mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-04-22 17:36:29 +02:00
Add octopsuh shortcode adapter, still testing. Add callback reception support. Add callback show in adapter.
This commit is contained in:
parent
89cb3db678
commit
6ad299f21e
14 changed files with 591 additions and 42 deletions
|
@ -123,4 +123,63 @@ use Monolog\Logger;
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function call on sms reception notification
|
||||
* We return nothing, and we let the adapter do his things.
|
||||
*
|
||||
* @param string $adapter_uid : Uid of the adapter to use
|
||||
* @param int $id_phone : Phone id
|
||||
*
|
||||
* @return bool : true on success, false on error
|
||||
*/
|
||||
public function reception (string $adapter_uid, int $id_phone)
|
||||
{
|
||||
$this->logger->info('Callback reception 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_uid']) === $adapter_uid)
|
||||
{
|
||||
$find_adapter = $adapter;
|
||||
}
|
||||
}
|
||||
|
||||
if (false === $find_adapter)
|
||||
{
|
||||
$this->logger->error('Callback reception use non existing adapter : ' . $adapter_uid);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//Instanciate adapter, check if status change is supported and if so call status change callback
|
||||
$adapter_classname = $find_adapter['meta_classname'];
|
||||
if (!$find_adapter['meta_support_reception'])
|
||||
{
|
||||
$this->logger->error('Callback recepetion use adapter ' . $adapter_uid . ' which does not support reception.');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$response = $adapter_classname::reception_callback();
|
||||
if ($response['error'])
|
||||
{
|
||||
$this->logger->error('Callback reception with adapter ' . $adapter_uid . ' failed : ' . $response['error_message']);
|
||||
return false;
|
||||
}
|
||||
|
||||
$response = $internal_received->receive($this->user['id'], $id_phone, $response['sms']['text'], $response['sms']['origin'], $response['sms']['at']);
|
||||
if ($response['error'])
|
||||
{
|
||||
$this->logger->error('Failed receive message : ' . json_encode($sms) . ' with error : ' . $response['error_message']);
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->logger->info('Callback reception successfully received message ' . json_encode($response['sms']));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,19 +36,39 @@ class Phone extends \descartes\Controller
|
|||
public function list($page = 0)
|
||||
{
|
||||
$id_user = $_SESSION['user']['id'];
|
||||
$api_key = $_SESSION['user']['api_key'];
|
||||
$page = (int) $page;
|
||||
$phones = $this->internal_phone->list_for_user($id_user, 25, $page);
|
||||
|
||||
$adapters = [];
|
||||
$adapters_metas = $this->internal_adapter->list_adapters();
|
||||
foreach ($adapters_metas as $adapter_metas)
|
||||
$adapters = $this->internal_adapter->list_adapters();
|
||||
foreach ($adapters as $key => $adapter)
|
||||
{
|
||||
$adapters[$adapter_metas['meta_classname']] = $adapter_metas['meta_name'];
|
||||
unset($adapters[$key]);
|
||||
$adapters[$adapter['meta_classname']] = $adapter;
|
||||
}
|
||||
|
||||
foreach ($phones as &$phone)
|
||||
{
|
||||
$phone['adapter'] = $adapters[$phone['adapter']] ?? 'Inconnu';
|
||||
$adapter = $adapters[$phone['adapter']] ?? false;
|
||||
|
||||
if (!$adapter)
|
||||
{
|
||||
$phone['adapter'] = 'Inconnu';
|
||||
continue;
|
||||
}
|
||||
|
||||
$phone['adapter'] = $adapter['meta_name'];
|
||||
|
||||
if ($adapter['meta_support_reception'])
|
||||
{
|
||||
$phone['callback_reception'] = \descartes\Router::url('Callback', 'reception', ['adapter_uid' => $adapter['meta_uid'], 'id_phone' => $phone['id']], ['api_key' => $api_key]);
|
||||
}
|
||||
|
||||
if ($adapter['meta_support_status_change'])
|
||||
{
|
||||
$phone['callback_status'] = \descartes\Router::url('Callback', 'update_sended_status', ['adapter_uid' => $adapter['meta_uid']], ['api_key' => $api_key]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->render('phone/list', ['phones' => $phones]);
|
||||
|
@ -207,7 +227,7 @@ class Phone extends \descartes\Controller
|
|||
|
||||
if (!$adapter_working)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Impossible d\'utiliser l\'adaptateur choisis avec les données fournies. Vérifiez le numéro de téléphone et les réglages.');
|
||||
\FlashMessage\FlashMessage::push('danger', 'Impossible d\'utiliser l\'adaptateur choisis avec les données fournies. Vérifiez les réglages.');
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Phone', 'add'));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue