mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-04-20 16:37:48 +02:00
Greatly improve adapters. Add twilio adapter for virtual numbers (no shortcode support before next version). Improve daemons exception + ERRORS handling. A lot of other little things
This commit is contained in:
parent
cbaa186c9e
commit
0c8fc7b3ac
17 changed files with 713 additions and 118 deletions
|
@ -26,18 +26,17 @@ namespace controllers\internals;
|
|||
* @param string $uid : Uid of the sms on the adapter service used
|
||||
* @param string $adapter : Name of the adapter service used to send the message
|
||||
* @param bool $flash : Is the sms a flash
|
||||
* @param string $status : Status of a the sms. By default 'unknown'
|
||||
* @param string $status : Status of a the sms. By default \models\Sended::STATUS_UNKNOWN
|
||||
*
|
||||
* @return bool : 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, ?string $status = 'unknown'): bool
|
||||
public function create(int $id_user, int $id_phone, $at, string $text, string $destination, string $uid, string $adapter, bool $flash = false, ?string $status = \models\Sended::STATUS_UNKNOWN): bool
|
||||
{
|
||||
$sended = [
|
||||
'id_user' => $id_user,
|
||||
'id_phone' => $id_phone,
|
||||
'at' => $at,
|
||||
'text' => $text,
|
||||
'origin' => $origin,
|
||||
'destination' => $destination,
|
||||
'uid' => $uid,
|
||||
'adapter' => $adapter,
|
||||
|
|
|
@ -60,20 +60,20 @@ use Monolog\Logger;
|
|||
* Function call on a sended sms status change notification reception.
|
||||
* We return nothing, and we let the adapter do his things.
|
||||
*
|
||||
* @param string $adapter_name : Name of the adapter to use
|
||||
* @param string $adapter_uid : Uid of the adapter to use
|
||||
*
|
||||
* @return bool : true on success, false on error
|
||||
*/
|
||||
public function update_sended_status(string $adapter_name)
|
||||
public function update_sended_status(string $adapter_uid)
|
||||
{
|
||||
$this->logger->info('Callback status call with adapter name : ' . $adapter_name);
|
||||
$this->logger->info('Callback status call with adapter uid : ' . $adapter_uid);
|
||||
|
||||
//Search for an adapter
|
||||
$find_adapter = false;
|
||||
$adapters = $this->internal_adapter->list_adapters();
|
||||
foreach ($adapters as $adapter)
|
||||
{
|
||||
if (mb_strtolower($adapter['meta_name']) === mb_strtolower($adapter_name))
|
||||
if (mb_strtolower($adapter['meta_uid']) === $adapter_uid)
|
||||
{
|
||||
$find_adapter = $adapter;
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ use Monolog\Logger;
|
|||
|
||||
if (false === $find_adapter)
|
||||
{
|
||||
$this->logger->error('Callback status use non existing adapter : ' . $adapter_name);
|
||||
$this->logger->error('Callback status use non existing adapter : ' . $adapter_uid);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ use Monolog\Logger;
|
|||
$adapter_classname = $find_adapter['meta_classname'];
|
||||
if (!$find_adapter['meta_support_status_change'])
|
||||
{
|
||||
$this->logger->error('Callback status use adapter ' . $adapter_name . ' which does not support status change.');
|
||||
$this->logger->error('Callback status use adapter ' . $adapter_uid . ' which does not support status change.');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ use Monolog\Logger;
|
|||
$callback_return = $adapter_classname::status_change_callback();
|
||||
if (!$callback_return)
|
||||
{
|
||||
$this->logger->error('Callback status with adapter ' . $adapter_name . ' failed on adapter compute.');
|
||||
$this->logger->error('Callback status with adapter ' . $adapter_uid . ' failed because adapter cannot process datas with success.');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -111,7 +111,14 @@ use Monolog\Logger;
|
|||
return false;
|
||||
}
|
||||
|
||||
$this->logger->info('Callback status update message with uid ' . $callback_return['uid'] . '.');
|
||||
//Do not update if current status is delivered or failed
|
||||
if ($sended['status'] === \models\Sended::STATUS_DELIVERED || $sended['status'] === \models\Sended::STATUS_FAILED)
|
||||
{
|
||||
$this->logger->info('Callback status update message ignore because status is already ' . $sended['status'] . '.');
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->logger->info('Callback status update message with uid ' . $callback_return['uid'] . ' to ' . $callback_return['status'] . '.');
|
||||
$this->internal_sended->update_status_for_user($this->user['id'], $sended['id'], $callback_return['status']);
|
||||
|
||||
return true;
|
||||
|
|
|
@ -171,11 +171,38 @@ class Phone extends \descartes\Controller
|
|||
return $this->redirect(\descartes\Router::url('Phone', 'add'));
|
||||
}
|
||||
|
||||
//If field phone number is invalid
|
||||
foreach ($find_adapter['meta_datas_fields'] as $field)
|
||||
{
|
||||
if (false === ($field['number'] ?? false))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!empty($adapter_datas[$field['name']]))
|
||||
{
|
||||
$adapter_datas[$field['name']] = \controllers\internals\Tool::parse_phone($adapter_datas[$field['name']]);
|
||||
|
||||
if ($adapter_datas[$field['name']])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
var_dump($field);
|
||||
var_dump($adapter_datas[$field['name']]);
|
||||
die();
|
||||
|
||||
\FlashMessage\FlashMessage::push('danger', 'Vous avez fourni un numéro de téléphone avec un format invalide.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Phone', 'add'));
|
||||
}
|
||||
|
||||
$adapter_datas = json_encode($adapter_datas);
|
||||
|
||||
//Check adapter is working correctly with thoses names and datas
|
||||
$adapter_classname = $find_adapter['meta_classname'];
|
||||
$adapter_instance = new $adapter_classname($name, $adapter_datas);
|
||||
$adapter_instance = new $adapter_classname($adapter_datas);
|
||||
$adapter_working = $adapter_instance->test();
|
||||
|
||||
if (!$adapter_working)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue