diff --git a/config/services.yaml b/config/services.yaml index 284b7b73..b0a5b022 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -73,6 +73,7 @@ services: $pass: "%env(RT_PASS)%" $usage_type: "%env(RT_USAGE_TYPE)%" $shortcode: "%env(RT_SHORTCODE)%" + $dr_url: "" App\Service\MQTTClient: arguments: diff --git a/src/Command/TestSMSCommand.php b/src/Command/TestSMSCommand.php new file mode 100644 index 00000000..f431398f --- /dev/null +++ b/src/Command/TestSMSCommand.php @@ -0,0 +1,41 @@ +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; + } +} diff --git a/src/Entity/SMSMessage.php b/src/Entity/SMSMessage.php new file mode 100644 index 00000000..cb6b2e0a --- /dev/null +++ b/src/Entity/SMSMessage.php @@ -0,0 +1,126 @@ +date_create = new DateTime(); + $this->from = ''; + $this->from_alias = ''; + $this->to = ''; + $this->message = ''; + $this->status = 'created'; + } + + 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; + } +} diff --git a/src/Service/RisingTideGateway.php b/src/Service/RisingTideGateway.php index ddfb2f79..c33c0ae9 100644 --- a/src/Service/RisingTideGateway.php +++ b/src/Service/RisingTideGateway.php @@ -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,7 +36,18 @@ 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 = [