Add transfer of smss
This commit is contained in:
parent
b42c2490ac
commit
31d2739ccb
|
@ -140,6 +140,17 @@ namespace controllers\internals;
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find a user by his id
|
||||
* @param string $id : User id
|
||||
* @return mixed array
|
||||
*/
|
||||
public function get ($id)
|
||||
{
|
||||
return $this->model_user->get($id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a user by his api_key address
|
||||
* @param string $api_key : User api key
|
||||
|
|
|
@ -140,7 +140,6 @@ class Phone extends AbstractDaemon
|
|||
//Get users settings
|
||||
$user_settings = $internal_setting->gets_for_user($this->phone['id_user']);
|
||||
|
||||
|
||||
//Process smss
|
||||
foreach ($smss as $sms)
|
||||
{
|
||||
|
@ -152,6 +151,8 @@ class Phone extends AbstractDaemon
|
|||
|
||||
$this->process_for_webhook($sms, 'receive_sms', $user_settings);
|
||||
|
||||
$this->process_for_transfer($sms, $user_settings);
|
||||
|
||||
$internal_received->create($sms['at'], $sms['text'], $sms['origin'], $sms['destination'], 'unread', $is_command);
|
||||
}
|
||||
}
|
||||
|
@ -216,6 +217,32 @@ class Phone extends AbstractDaemon
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process a sms to transfer it by mail
|
||||
* @param array $sms : The sms
|
||||
* @param array $user_settings : Use settings
|
||||
*/
|
||||
private function process_for_transfer (array $sms, array $user_settings)
|
||||
{
|
||||
if (!$user_settings['transfer'])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$internal_user = new \controllers\internals\User($this->bdd);
|
||||
$user = $internal_user->get($this->phone['id_user']);
|
||||
|
||||
if (!$user)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->logger->info('Transfer sms to ' . $user['email'] . ' : ' . json_encode($sms));
|
||||
|
||||
\controllers\internals\Tool::send_email($user['email'], EMAIL_TRANSFER_SMS, ['sms' => $sms]);
|
||||
}
|
||||
|
||||
|
||||
public function on_start()
|
||||
|
|
|
@ -16,6 +16,17 @@ namespace models;
|
|||
*/
|
||||
class User extends \descartes\Model
|
||||
{
|
||||
/**
|
||||
* Find a user by his id
|
||||
* @param string $id : User id
|
||||
* @return mixed array
|
||||
*/
|
||||
public function get ($id)
|
||||
{
|
||||
return $this->_select_one('user', ['id' => $id]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find a user using his email
|
||||
* @param string $email : User email
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
Vous avez reçu un nouveau SMS :
|
||||
Date : <?= $sms['at'] ?>
|
||||
Origine : <?= $sms['origin'] ?>
|
||||
Destination : <?= $sms['destination'] ?>
|
||||
Message : <?= $sms['text'] ?>
|
Loading…
Reference in New Issue