Compare commits

...

3 Commits

Author SHA1 Message Date
osaajani 87a04742a3 fix version 2021-10-18 03:42:34 +02:00
osaajani d0fa0a299c Add a new webhook for sended sms status change. Add status and originating scheduled's id to webhook send_sms 2021-10-18 03:40:06 +02:00
osaajani ec108d8543 add status to webhook sms_send 2021-10-17 02:52:46 +02:00
13 changed files with 106 additions and 25 deletions

View File

@ -1 +1 @@
v3.1.13 v3.2.0

View File

@ -45,11 +45,12 @@ namespace controllers\internals;
* @param bool $flash : Is the sms a flash * @param bool $flash : Is the sms a flash
* @param bool $mms : Is the sms a MMS. By default false. * @param bool $mms : Is the sms a MMS. By default false.
* @param array $medias : Array of medias to link to the MMS * @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 * @param string $status : Status of a the sms. By default \models\Sended::STATUS_UNKNOWN
* *
* @return mixed : false on error, new sended id else * @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 = [ $sended = [
'id_user' => $id_user, 'id_user' => $id_user,
@ -62,6 +63,7 @@ namespace controllers\internals;
'flash' => $flash, 'flash' => $flash,
'mms' => $mms, 'mms' => $mms,
'status' => $status, 'status' => $status,
'originating_scheduled' => $originating_scheduled,
]; ];
//Ensure atomicity //Ensure atomicity
@ -105,24 +107,22 @@ namespace controllers\internals;
'status' => $status, '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);
}
/** if (!$success)
* Update a sended status for a sended. {
* return $success;
* @param int $id_sended : Sended id }
* @param string $status : Status of a the sms (unknown, delivered, failed)
* $webhook = [
* @return bool : false on error, true on success 'id' => $id_sended,
*/
public function update_status(int $id_sended, string $status): bool
{
$sended = [
'status' => $status, '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 * ?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 = [ $return = [
'error' => false, 'error' => false,
@ -278,23 +278,40 @@ namespace controllers\internals;
$return['error'] = true; $return['error'] = true;
$return['error_message'] = $response['error_message']; $return['error_message'] = $response['error_message'];
$status = \models\Sended::STATUS_FAILED; $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, $originating_scheduled, $status);
$sended = [
'id' => $sended_id,
'at' => $at,
'status' => $status,
'text' => $text,
'destination' => $destination,
'origin' => $id_phone,
'mms' => $mms,
'medias' => $medias,
'originating_scheduled' => $originating_scheduled,
];
$internal_webhook = new Webhook($this->bdd);
$internal_webhook->trigger($id_user, \models\Webhook::TYPE_SEND_SMS, $sended);
return $return; return $return;
} }
$internal_quota->consume_credit($id_user, $nb_credits); $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 = [ $sended = [
'id' => $sended_id, 'id' => $sended_id,
'at' => $at, 'at' => $at,
'status' => $status,
'text' => $text, 'text' => $text,
'destination' => $destination, 'destination' => $destination,
'origin' => $id_phone, 'origin' => $id_phone,
'mms' => $mms, 'mms' => $mms,
'medias' => $medias, 'medias' => $medias,
'originating_scheduled' => $originating_scheduled,
]; ];
$internal_webhook = new Webhook($this->bdd); $internal_webhook = new Webhook($this->bdd);

View File

@ -139,7 +139,7 @@ class Phone extends AbstractDaemon
//Do message sending //Do message sending
$this->logger->info('Try send message : ' . json_encode($message)); $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']) if ($response['error'])
{ {
$this->logger->error('Failed send message : ' . json_encode($message) . ' with error : ' . $response['error_message']); $this->logger->error('Failed send message : ' . json_encode($message) . ' with error : ' . $response['error_message']);

View File

@ -0,0 +1,42 @@
<?php
use Phinx\Migration\AbstractMigration;
class AddScheduledIdToSended extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* addCustomColumn
* renameColumn
* addIndex
* addForeignKey
*
* Any other destructive changes will result in an error when trying to
* rollback the migration.
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
$table = $this->table('sended');
$table->addColumn('originating_scheduled', 'integer', [
'null' => true,
'comment' => 'Id of the scheduled that was responsible for sending this message.',
'after' => 'mms'
])
->update();
}
}

View File

@ -0,0 +1,16 @@
<?php
use Phinx\Migration\AbstractMigration;
class AddWebhookTypeSendSmsStatusChange extends AbstractMigration
{
public function up()
{
$this->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\')');
}
}

View File

@ -14,6 +14,7 @@ namespace models;
class Webhook extends StandardModel class Webhook extends StandardModel
{ {
const TYPE_SEND_SMS = 'send_sms'; const TYPE_SEND_SMS = 'send_sms';
const TYPE_SEND_SMS_STATUS_CHANGE = 'send_sms_status_change';
const TYPE_RECEIVE_SMS = 'receive_sms'; const TYPE_RECEIVE_SMS = 'receive_sms';
const TYPE_INBOUND_CALL = 'inbound_call'; const TYPE_INBOUND_CALL = 'inbound_call';
const TYPE_QUOTA_LEVEL_ALERT = 'quota_level'; const TYPE_QUOTA_LEVEL_ALERT = 'quota_level';

View File

@ -182,7 +182,7 @@ jQuery(document).ready(function()
//Datatable //Datatable
jQuery('.datatable').DataTable({ jQuery('.datatable').DataTable({
"pageLength": 25, "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": { "language": {
"url": HTTP_PWD + "/assets/js/datatables/french.json", "url": HTTP_PWD + "/assets/js/datatables/french.json",
}, },

View File

@ -71,7 +71,7 @@ jQuery(document).ready(function ()
{ {
jQuery('.datatable').DataTable({ jQuery('.datatable').DataTable({
"pageLength": 25, "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": { "language": {
"url": HTTP_PWD + "/assets/js/datatables/french.json", "url": HTTP_PWD + "/assets/js/datatables/french.json",
}, },

View File

@ -79,7 +79,7 @@ jQuery(document).ready(function ()
{ {
jQuery('.datatable').DataTable({ jQuery('.datatable').DataTable({
"pageLength": 25, "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": { "language": {
"url": HTTP_PWD + "/assets/js/datatables/french.json", "url": HTTP_PWD + "/assets/js/datatables/french.json",
}, },

View File

@ -69,7 +69,7 @@ jQuery(document).ready(function ()
{ {
jQuery('.datatable').DataTable({ jQuery('.datatable').DataTable({
"pageLength": 25, "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": { "language": {
"url": HTTP_PWD + "/assets/js/datatables/french.json", "url": HTTP_PWD + "/assets/js/datatables/french.json",
}, },

View File

@ -47,6 +47,7 @@
<select name="type" class="form-control" required> <select name="type" class="form-control" required>
<option value="receive_sms" <?= ($_SESSION['previous_http_post']['type'] ?? '') == 'receive_sms' ? 'selected' : '' ?>>Réception d'un SMS</option> <option value="receive_sms" <?= ($_SESSION['previous_http_post']['type'] ?? '') == 'receive_sms' ? 'selected' : '' ?>>Réception d'un SMS</option>
<option value="send_sms" <?= ($_SESSION['previous_http_post']['type'] ?? '') == 'send_sms' ? 'selected' : '' ?>>Envoi d'un SMS</option> <option value="send_sms" <?= ($_SESSION['previous_http_post']['type'] ?? '') == 'send_sms' ? 'selected' : '' ?>>Envoi d'un SMS</option>
<option value="send_sms_status_change" <?= ($_SESSION['previous_http_post']['type'] ?? '') == 'send_sms_status_change' ? 'selected' : '' ?>>Mise à jour du statut d'un SMS envoyé</option>
<option value="inbound_call" <?= ($_SESSION['previous_http_post']['type'] ?? '') == 'inbound_call' ? 'selected' : '' ?>>Réception d'un appel téléphonique</option> <option value="inbound_call" <?= ($_SESSION['previous_http_post']['type'] ?? '') == 'inbound_call' ? 'selected' : '' ?>>Réception d'un appel téléphonique</option>
</select> </select>
</div> </div>

View File

@ -50,6 +50,8 @@
<select name="webhooks[<?php $this->s($webhook['id']); ?>][type]" class="form-control" required> <select name="webhooks[<?php $this->s($webhook['id']); ?>][type]" class="form-control" required>
<option <?php echo $webhook['type'] == 'receive_sms' ? 'selected="selected"' : '' ?> value="receive_sms">Réception d'un SMS</option> <option <?php echo $webhook['type'] == 'receive_sms' ? 'selected="selected"' : '' ?> value="receive_sms">Réception d'un SMS</option>
<option <?php echo $webhook['type'] == 'send_sms' ? 'selected="selected"' : '' ?> value="send_sms">Envoi d'un SMS</option> <option <?php echo $webhook['type'] == 'send_sms' ? 'selected="selected"' : '' ?> value="send_sms">Envoi d'un SMS</option>
<option <?php echo $webhook['type'] == 'send_sms_status_change' ? 'selected="selected"' : '' ?> value="send_sms_status_change">Mise à jour du statut d'un SMS envoyé</option>
<option <?php echo $webhook['type'] == 'inbound_call' ? 'selected="selected"' : '' ?> value="inbound_call">Réception d'un appel téléphonique</option>
</select> </select>
</div> </div>
<hr/> <hr/>

View File

@ -90,6 +90,8 @@ jQuery(document).ready(function ()
switch (data) { switch (data) {
case 'send_sms': case 'send_sms':
return 'Envoi de SMS'; return 'Envoi de SMS';
case 'send_sms_status_change':
return 'Mise à jour du statut d\'un SMS envoyé';
case 'receive_sms': case 'receive_sms':
return 'Réception de SMS'; return 'Réception de SMS';
case 'inbound_call': case 'inbound_call':