From ec108d854379466075abb216010cfb6338c71995 Mon Sep 17 00:00:00 2001 From: osaajani <> Date: Sun, 17 Oct 2021 02:52:46 +0200 Subject: [PATCH 1/3] add status to webhook sms_send --- controllers/internals/Sended.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/controllers/internals/Sended.php b/controllers/internals/Sended.php index 504cece..9091998 100644 --- a/controllers/internals/Sended.php +++ b/controllers/internals/Sended.php @@ -278,7 +278,21 @@ namespace controllers\internals; $return['error'] = true; $return['error_message'] = $response['error_message']; $status = \models\Sended::STATUS_FAILED; - $this->create($id_user, $id_phone, $at, $text, $destination, $response['uid'] ?? uniqid(), $adapter->meta_classname(), $flash, $mms, $medias, $status); + $sended_id = $this->create($id_user, $id_phone, $at, $text, $destination, $response['uid'] ?? uniqid(), $adapter->meta_classname(), $flash, $mms, $medias, $status); + + $sended = [ + 'id' => $sended_id, + 'at' => $at, + 'status' => $status, + 'text' => $text, + 'destination' => $destination, + 'origin' => $id_phone, + 'mms' => $mms, + 'medias' => $medias, + ]; + + $internal_webhook = new Webhook($this->bdd); + $internal_webhook->trigger($id_user, \models\Webhook::TYPE_SEND_SMS, $sended); return $return; } @@ -290,6 +304,7 @@ namespace controllers\internals; $sended = [ 'id' => $sended_id, 'at' => $at, + 'status' => $status, 'text' => $text, 'destination' => $destination, 'origin' => $id_phone, From d0fa0a299c242e96e7bdc21a2c6816291c21b76b Mon Sep 17 00:00:00 2001 From: osaajani <> Date: Mon, 18 Oct 2021 03:40:06 +0200 Subject: [PATCH 2/3] Add a new webhook for sended sms status change. Add status and originating scheduled's id to webhook send_sms --- VERSION | 2 +- controllers/internals/Sended.php | 38 +++++++++-------- daemons/Phone.php | 4 +- ...11017231147_add_scheduled_id_to_sended.php | 42 +++++++++++++++++++ ...dd_webhook_type_send_sms_status_change.php | 16 +++++++ models/Webhook.php | 1 + templates/contact/list.php | 2 +- templates/event/list.php | 2 +- templates/received/list.php | 2 +- templates/sended/list.php | 2 +- templates/webhook/add.php | 1 + templates/webhook/edit.php | 2 + templates/webhook/list.php | 2 + 13 files changed, 91 insertions(+), 25 deletions(-) create mode 100644 db/migrations/20211017231147_add_scheduled_id_to_sended.php create mode 100644 db/migrations/20211018002819_add_webhook_type_send_sms_status_change.php diff --git a/VERSION b/VERSION index ecbc73c..b68118d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v3.1.13 +v3.2.13 diff --git a/controllers/internals/Sended.php b/controllers/internals/Sended.php index 9091998..a492aac 100644 --- a/controllers/internals/Sended.php +++ b/controllers/internals/Sended.php @@ -45,11 +45,12 @@ namespace controllers\internals; * @param bool $flash : Is the sms a flash * @param bool $mms : Is the sms a MMS. By default false. * @param array $medias : Array of medias to link to the MMS + * @param ?int $originating_scheduled : Id of the scheduled message that was responsible for sending this message. By default null. * @param string $status : Status of a the sms. By default \models\Sended::STATUS_UNKNOWN * * @return mixed : false on error, new sended id else */ - public function create(int $id_user, int $id_phone, $at, string $text, string $destination, string $uid, string $adapter, bool $flash = false, bool $mms = false, array $medias = [], ?string $status = \models\Sended::STATUS_UNKNOWN) + public function create(int $id_user, int $id_phone, $at, string $text, string $destination, string $uid, string $adapter, bool $flash = false, bool $mms = false, array $medias = [], ?int $originating_scheduled = null, ?string $status = \models\Sended::STATUS_UNKNOWN) { $sended = [ 'id_user' => $id_user, @@ -62,6 +63,7 @@ namespace controllers\internals; 'flash' => $flash, 'mms' => $mms, 'status' => $status, + 'originating_scheduled' => $originating_scheduled, ]; //Ensure atomicity @@ -105,24 +107,22 @@ namespace controllers\internals; 'status' => $status, ]; - return (bool) $this->get_model()->update_for_user($id_user, $id_sended, $sended); - } + $success = (bool) $this->get_model()->update_for_user($id_user, $id_sended, $sended); - /** - * Update a sended status for a sended. - * - * @param int $id_sended : Sended id - * @param string $status : Status of a the sms (unknown, delivered, failed) - * - * @return bool : false on error, true on success - */ - public function update_status(int $id_sended, string $status): bool - { - $sended = [ + if (!$success) + { + return $success; + } + + $webhook = [ + 'id' => $id_sended, 'status' => $status, ]; - return (bool) $this->get_model()->update($id_sended, $sended); + $internal_webhook = new Webhook($this->bdd); + $internal_webhook->trigger($id_user, \models\Webhook::TYPE_SEND_SMS_STATUS_CHANGE, $webhook); + + return $success; } /** @@ -231,7 +231,7 @@ namespace controllers\internals; * ?string 'error_message' => null if success, error message else * ] */ - public function send(\adapters\AdapterInterface $adapter, int $id_user, int $id_phone, string $text, string $destination, bool $flash = false, bool $mms = false, array $medias = [], string $status = \models\Sended::STATUS_UNKNOWN): array + public function send(\adapters\AdapterInterface $adapter, int $id_user, int $id_phone, string $text, string $destination, bool $flash = false, bool $mms = false, array $medias = [], $originating_scheduled = null, string $status = \models\Sended::STATUS_UNKNOWN): array { $return = [ 'error' => false, @@ -278,7 +278,7 @@ namespace controllers\internals; $return['error'] = true; $return['error_message'] = $response['error_message']; $status = \models\Sended::STATUS_FAILED; - $sended_id = $this->create($id_user, $id_phone, $at, $text, $destination, $response['uid'] ?? uniqid(), $adapter->meta_classname(), $flash, $mms, $medias, $status); + $sended_id = $this->create($id_user, $id_phone, $at, $text, $destination, $response['uid'] ?? uniqid(), $adapter->meta_classname(), $flash, $mms, $medias, $originating_scheduled, $status); $sended = [ 'id' => $sended_id, @@ -289,6 +289,7 @@ namespace controllers\internals; 'origin' => $id_phone, 'mms' => $mms, 'medias' => $medias, + 'originating_scheduled' => $originating_scheduled, ]; $internal_webhook = new Webhook($this->bdd); @@ -299,7 +300,7 @@ namespace controllers\internals; $internal_quota->consume_credit($id_user, $nb_credits); - $sended_id = $this->create($id_user, $id_phone, $at, $text, $destination, $response['uid'] ?? uniqid(), $adapter->meta_classname(), $flash, $mms, $medias, $status); + $sended_id = $this->create($id_user, $id_phone, $at, $text, $destination, $response['uid'] ?? uniqid(), $adapter->meta_classname(), $flash, $mms, $medias, $originating_scheduled, $status); $sended = [ 'id' => $sended_id, @@ -310,6 +311,7 @@ namespace controllers\internals; 'origin' => $id_phone, 'mms' => $mms, 'medias' => $medias, + 'originating_scheduled' => $originating_scheduled, ]; $internal_webhook = new Webhook($this->bdd); diff --git a/daemons/Phone.php b/daemons/Phone.php index 48b99e9..1be7856 100644 --- a/daemons/Phone.php +++ b/daemons/Phone.php @@ -139,14 +139,14 @@ class Phone extends AbstractDaemon //Do message sending $this->logger->info('Try send message : ' . json_encode($message)); - $response = $internal_sended->send($this->adapter, $this->phone['id_user'], $this->phone['id'], $message['text'], $message['destination'], $message['flash'], $message['mms'], $message['medias']); + $response = $internal_sended->send($this->adapter, $this->phone['id_user'], $this->phone['id'], $message['text'], $message['destination'], $message['flash'], $message['mms'], $message['medias'], $message['id_scheduled']); if ($response['error']) { $this->logger->error('Failed send message : ' . json_encode($message) . ' with error : ' . $response['error_message']); continue; } - + $this->logger->info('Successfully send message : ' . json_encode($message)); } } diff --git a/db/migrations/20211017231147_add_scheduled_id_to_sended.php b/db/migrations/20211017231147_add_scheduled_id_to_sended.php new file mode 100644 index 0000000..bc7f95a --- /dev/null +++ b/db/migrations/20211017231147_add_scheduled_id_to_sended.php @@ -0,0 +1,42 @@ +table('sended'); + $table->addColumn('originating_scheduled', 'integer', [ + 'null' => true, + 'comment' => 'Id of the scheduled that was responsible for sending this message.', + 'after' => 'mms' + ]) + ->update(); + } +} diff --git a/db/migrations/20211018002819_add_webhook_type_send_sms_status_change.php b/db/migrations/20211018002819_add_webhook_type_send_sms_status_change.php new file mode 100644 index 0000000..9289ec8 --- /dev/null +++ b/db/migrations/20211018002819_add_webhook_type_send_sms_status_change.php @@ -0,0 +1,16 @@ +execute('ALTER TABLE `webhook` MODIFY `type` ENUM(\'send_sms\', \'send_sms_status_change\', \'receive_sms\', \'inbound_call\')'); + } + + public function down() + { + $this->execute('ALTER TABLE `webhook` MODIFY `type` ENUM(\'send_sms\', \'receive_sms\', \'inbound_call\')'); + } +} diff --git a/models/Webhook.php b/models/Webhook.php index f55bf85..f963df9 100644 --- a/models/Webhook.php +++ b/models/Webhook.php @@ -14,6 +14,7 @@ namespace models; class Webhook extends StandardModel { const TYPE_SEND_SMS = 'send_sms'; + const TYPE_SEND_SMS_STATUS_CHANGE = 'send_sms_status_change'; const TYPE_RECEIVE_SMS = 'receive_sms'; const TYPE_INBOUND_CALL = 'inbound_call'; const TYPE_QUOTA_LEVEL_ALERT = 'quota_level'; diff --git a/templates/contact/list.php b/templates/contact/list.php index 2284706..741df56 100644 --- a/templates/contact/list.php +++ b/templates/contact/list.php @@ -182,7 +182,7 @@ jQuery(document).ready(function() //Datatable jQuery('.datatable').DataTable({ "pageLength": 25, - "lengthMenu": [[25, 50, 100, 1000, 10000, -1], [25, 50, 100, 1000, 10000, "All"]], + "lengthMenu": [[25, 50, 100, 1000, 10000, Math.pow(10, 10)], [25, 50, 100, 1000, 10000, "All"]], "language": { "url": HTTP_PWD + "/assets/js/datatables/french.json", }, diff --git a/templates/event/list.php b/templates/event/list.php index 93d24c3..72de9f4 100644 --- a/templates/event/list.php +++ b/templates/event/list.php @@ -71,7 +71,7 @@ jQuery(document).ready(function () { jQuery('.datatable').DataTable({ "pageLength": 25, - "lengthMenu": [[25, 50, 100, 1000, 10000, -1], [25, 50, 100, 1000, 10000, "All"]], + "lengthMenu": [[25, 50, 100, 1000, 10000, Math.pow(10, 10)], [25, 50, 100, 1000, 10000, "All"]], "language": { "url": HTTP_PWD + "/assets/js/datatables/french.json", }, diff --git a/templates/received/list.php b/templates/received/list.php index a4c44e1..1024d12 100644 --- a/templates/received/list.php +++ b/templates/received/list.php @@ -79,7 +79,7 @@ jQuery(document).ready(function () { jQuery('.datatable').DataTable({ "pageLength": 25, - "lengthMenu": [[25, 50, 100, 1000, 10000, -1], [25, 50, 100, 1000, 10000, "All"]], + "lengthMenu": [[25, 50, 100, 1000, 10000, Math.pow(10, 10)], [25, 50, 100, 1000, 10000, "All"]], "language": { "url": HTTP_PWD + "/assets/js/datatables/french.json", }, diff --git a/templates/sended/list.php b/templates/sended/list.php index d439af7..7f1ada0 100644 --- a/templates/sended/list.php +++ b/templates/sended/list.php @@ -69,7 +69,7 @@ jQuery(document).ready(function () { jQuery('.datatable').DataTable({ "pageLength": 25, - "lengthMenu": [[25, 50, 100, 1000, 10000, -1], [25, 50, 100, 1000, 10000]], + "lengthMenu": [[25, 50, 100, 1000, 10000, Math.pow(10, 10)], [25, 50, 100, 1000, 10000, "All"]], "language": { "url": HTTP_PWD + "/assets/js/datatables/french.json", }, diff --git a/templates/webhook/add.php b/templates/webhook/add.php index 6e53c43..e0ab6d5 100644 --- a/templates/webhook/add.php +++ b/templates/webhook/add.php @@ -47,6 +47,7 @@ diff --git a/templates/webhook/edit.php b/templates/webhook/edit.php index 7808faf..e297923 100644 --- a/templates/webhook/edit.php +++ b/templates/webhook/edit.php @@ -50,6 +50,8 @@
diff --git a/templates/webhook/list.php b/templates/webhook/list.php index c1e2e0f..05a66d9 100644 --- a/templates/webhook/list.php +++ b/templates/webhook/list.php @@ -90,6 +90,8 @@ jQuery(document).ready(function () switch (data) { case 'send_sms': return 'Envoi de SMS'; + case 'send_sms_status_change': + return 'Mise à jour du statut d\'un SMS envoyé'; case 'receive_sms': return 'Réception de SMS'; case 'inbound_call': From 87a04742a3224a2c8bbd5ad21fa133649ce3ac46 Mon Sep 17 00:00:00 2001 From: osaajani <> Date: Mon, 18 Oct 2021 03:42:34 +0200 Subject: [PATCH 3/3] fix version --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index b68118d..6d260c3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v3.2.13 +v3.2.0