Merge branch '394-warranty-expiration-sms-reminder' into 'master'
Resolve "Warranty expiration sms reminder" Closes #394 See merge request jankstudio/resq!442
This commit is contained in:
commit
89c18eda1c
7 changed files with 292 additions and 2 deletions
|
|
@ -30,6 +30,10 @@ security:
|
|||
pattern: ^\/api\/
|
||||
security: false
|
||||
|
||||
sms:
|
||||
pattern: ^/sms\/
|
||||
security: false
|
||||
|
||||
rider_api:
|
||||
pattern: ^\/rapi\/
|
||||
security: false
|
||||
|
|
|
|||
6
config/routes/sms.yaml
Normal file
6
config/routes/sms.yaml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
# sms handling - rising tide
|
||||
|
||||
sms_delivery_receipt:
|
||||
path: /sms/delivery_receipt
|
||||
controller: App\Controller\SMSController::deliveryReceipt
|
||||
methods: [POST]
|
||||
|
|
@ -74,6 +74,7 @@ services:
|
|||
$pass: "%env(RT_PASS)%"
|
||||
$usage_type: "%env(RT_USAGE_TYPE)%"
|
||||
$shortcode: "%env(RT_SHORTCODE)%"
|
||||
$dr_url: "https://resqapi.jankstudio.com/sms/delivery_receipt"
|
||||
|
||||
App\Service\MQTTClient:
|
||||
arguments:
|
||||
|
|
|
|||
41
src/Command/TestSMSCommand.php
Normal file
41
src/Command/TestSMSCommand.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use App\Service\RisingTideGateway;
|
||||
|
||||
class TestSMSCommand extends Command
|
||||
{
|
||||
protected $gateway;
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('sms:test')
|
||||
->setDescription('Sends a test SMS message.')
|
||||
->setHelp('Sends a test SMS message.')
|
||||
->addArgument('destination', InputArgument::REQUIRED, 'Destination number to send to');
|
||||
}
|
||||
|
||||
public function __construct(RisingTideGateway $gateway)
|
||||
{
|
||||
$this->gateway = $gateway;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$number = $input->getArgument('destination');
|
||||
|
||||
error_log('sending sms to ' . $number);
|
||||
$msg = 'This is a test.';
|
||||
$this->gateway->sendSMS($number, 'MOTOLITE', $msg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
71
src/Controller/SMSController.php
Normal file
71
src/Controller/SMSController.php
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
|
||||
use App\Entity\SMSMessage;
|
||||
|
||||
use DateTime;
|
||||
|
||||
|
||||
class SMSController extends Controller
|
||||
{
|
||||
public function deliveryReceipt(Request $req, EntityManagerInterface $em)
|
||||
{
|
||||
$content = $req->getContent();
|
||||
|
||||
error_log($content);
|
||||
|
||||
$data = json_decode($content, true);
|
||||
error_log(print_r($data, true));
|
||||
|
||||
// data has id?
|
||||
if (!isset($data['id']))
|
||||
{
|
||||
error_log('SMSDR: no id sent');
|
||||
$resp = new Response();
|
||||
$resp->setStatusCode(400);
|
||||
return $resp;
|
||||
}
|
||||
|
||||
// check structure
|
||||
if (!isset($data['delivered']) ||
|
||||
!isset($data['reason_code']) ||
|
||||
!isset($data['reason_description'])
|
||||
)
|
||||
{
|
||||
error_log('SMSDR: bad data structure');
|
||||
$resp = new Response();
|
||||
$resp->setStatusCode(400);
|
||||
return $resp;
|
||||
}
|
||||
|
||||
// find sms
|
||||
$sms = $em->getRepository(SMSMessage::class)->find($data['id']);
|
||||
if ($sms == null)
|
||||
{
|
||||
error_log('SMSDR: no sms found');
|
||||
$resp = new Response();
|
||||
$resp->setStatusCode(202);
|
||||
return $resp;
|
||||
}
|
||||
|
||||
$sms->setReasonCode($data['reason_code']);
|
||||
if ($data['delivered'])
|
||||
$sms->setStatus('delivered');
|
||||
else
|
||||
$sms->setStatus('not_delivered');
|
||||
$em->flush();
|
||||
|
||||
$resp = new Response();
|
||||
$resp->setStatusCode(202);
|
||||
return $resp;
|
||||
}
|
||||
}
|
||||
149
src/Entity/SMSMessage.php
Normal file
149
src/Entity/SMSMessage.php
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use DateTime;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="sms_message")
|
||||
*/
|
||||
class SMSMessage
|
||||
{
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetime")
|
||||
*/
|
||||
protected $date_create;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=100)
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=100)
|
||||
*/
|
||||
protected $source_alias;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=100)
|
||||
*/
|
||||
protected $destination;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text")
|
||||
*/
|
||||
protected $message;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=30)
|
||||
*/
|
||||
protected $status;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="integer", length=5)
|
||||
*/
|
||||
protected $reason_code;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->date_create = new DateTime();
|
||||
$this->from = '';
|
||||
$this->from_alias = '';
|
||||
$this->to = '';
|
||||
$this->message = '';
|
||||
$this->status = 'created';
|
||||
$this->reason_code = 0;
|
||||
|
||||
// status are:
|
||||
// created
|
||||
// sent
|
||||
// delivered
|
||||
// not_delivered
|
||||
}
|
||||
|
||||
public function getID()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getDateCreate()
|
||||
{
|
||||
return $this->date_create;
|
||||
}
|
||||
|
||||
public function setFrom($from)
|
||||
{
|
||||
$this->source = $from;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFrom()
|
||||
{
|
||||
return $this->source;
|
||||
}
|
||||
|
||||
public function setFromAlias($alias)
|
||||
{
|
||||
$this->source_alias = $alias;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFromAlias()
|
||||
{
|
||||
return $this->source_alias;
|
||||
}
|
||||
|
||||
public function setTo($to)
|
||||
{
|
||||
$this->destination = $to;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTo()
|
||||
{
|
||||
return $this->destination;
|
||||
}
|
||||
|
||||
public function setMessage($message)
|
||||
{
|
||||
$this->message = $message;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMessage()
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
public function setStatus($status)
|
||||
{
|
||||
$this->status = $status;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStatus()
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
public function setReasonCode($code)
|
||||
{
|
||||
$this->reason_code = $code;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getReasonCode()
|
||||
{
|
||||
return $this->reason_code;
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ namespace App\Service;
|
|||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use DateTime;
|
||||
use App\Entity\SMSMessage;
|
||||
|
||||
class RisingTideGateway
|
||||
{
|
||||
|
|
@ -17,14 +18,16 @@ class RisingTideGateway
|
|||
protected $pass;
|
||||
protected $usage_type;
|
||||
protected $shortcode;
|
||||
protected $dr_url;
|
||||
|
||||
public function __construct(EntityManagerInterface $em, $user, $pass, $usage_type, $shortcode)
|
||||
public function __construct(EntityManagerInterface $em, $user, $pass, $usage_type, $shortcode, $dr_url)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->user = $user;
|
||||
$this->pass = $pass;
|
||||
$this->usage_type = $usage_type;
|
||||
$this->shortcode = $shortcode;
|
||||
$this->dr_url = $dr_url;
|
||||
}
|
||||
|
||||
public function sendSMS($mobile_num, $mask, $message)
|
||||
|
|
@ -33,10 +36,22 @@ class RisingTideGateway
|
|||
'Content-Type: application/vnd.net.wyrls.Document-v3+json'
|
||||
];
|
||||
|
||||
$date = new DateTime();
|
||||
$sms = new SMSMessage();
|
||||
$sms->setFrom($this->shortcode)
|
||||
->setFromAlias($mask)
|
||||
->setTo($mobile_num)
|
||||
->setMessage($message)
|
||||
->setStatus('sent');
|
||||
|
||||
$this->em->persist($sms);
|
||||
$this->em->flush();
|
||||
|
||||
$date = $sms->getDateCreate();
|
||||
// $date = new DateTime();
|
||||
$date_string = $date->format('Y-m-d') . 'T' . $date->format('H:m:s');
|
||||
|
||||
$data = [
|
||||
'id' => $sms->getID(),
|
||||
'from' => $this->shortcode,
|
||||
'from_alias' => $mask,
|
||||
'to' => $mobile_num,
|
||||
|
|
@ -44,7 +59,10 @@ class RisingTideGateway
|
|||
'body' => $message,
|
||||
'date' => $date_string,
|
||||
'usagetype' => $this->usage_type,
|
||||
'delivery_receipt_url' => $dr_url,
|
||||
];
|
||||
error_log(print_r($data, true));
|
||||
|
||||
$data_json = json_encode($data);
|
||||
|
||||
$userpwd = $this->user . ':' . $this->pass;
|
||||
|
|
|
|||
Loading…
Reference in a new issue