Add new webhook when SMS fail to send
This commit is contained in:
parent
b8e587a59e
commit
c3fb8be0ad
|
@ -187,7 +187,18 @@ 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, $status);
|
$errored_id = $this->create($id_user, $id_phone, $at, $text, $destination, $response['uid'] ?? uniqid()$
|
||||||
|
|
||||||
|
$errored = [
|
||||||
|
'id' => $errored_id,
|
||||||
|
'at' => $at,
|
||||||
|
'text' => $text,
|
||||||
|
'destination' => $destination,
|
||||||
|
'origin' => $id_phone,
|
||||||
|
];
|
||||||
|
|
||||||
|
$internal_webhook = new Webhook($this->bdd);
|
||||||
|
$internal_webhook->trigger($id_user, \models\Webhook::TYPE_SEND_ERROR, $errored);
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
use Phinx\Migration\AbstractMigration;
|
||||||
|
|
||||||
|
class AddSendErrorWebhook extends AbstractMigration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Migrate Up.
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
$users = $this->table('webhook');
|
||||||
|
$users->changeColumn('type', 'enum', ['values' => ['send_sms', 'receive_sms', 'send_sms_error']])
|
||||||
|
->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Migrate Down.
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
$users = $this->table('webhook');
|
||||||
|
$users->changeColumn('type', 'enum', ['values' => ['send_sms', 'receive_sms']])
|
||||||
|
->save();
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,6 +14,7 @@ namespace models;
|
||||||
class Webhook extends StandardModel
|
class Webhook extends StandardModel
|
||||||
{
|
{
|
||||||
const TYPE_SEND = 'send_sms';
|
const TYPE_SEND = 'send_sms';
|
||||||
|
const TYPE_SEND_ERROR = 'send_sms_error';
|
||||||
const TYPE_RECEIVE = 'receive_sms';
|
const TYPE_RECEIVE = 'receive_sms';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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_error" <?= ($_SESSION['previous_http_post']['type'] ?? '') == 'send_sms_error' ? 'selected' : '' ?>>Erreur à l'envoi d'un SMS</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<a class="btn btn-danger" href="<?php echo \descartes\Router::url('Webhook', 'list'); ?>">Annuler</a>
|
<a class="btn btn-danger" href="<?php echo \descartes\Router::url('Webhook', 'list'); ?>">Annuler</a>
|
||||||
|
|
|
@ -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_error':
|
||||||
|
return 'Erreur à l\'envoi de SMS';
|
||||||
case 'receive_sms':
|
case 'receive_sms':
|
||||||
return 'Réception de SMS';
|
return 'Réception de SMS';
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue