Incoming.php in SMS Framework 8
File
tests/modules/sms_test_gateway/src/Plugin/SmsGateway/Incoming.php
View source
<?php
namespace Drupal\sms_test_gateway\Plugin\SmsGateway;
use Drupal\sms\Message\SmsDeliveryReport;
use Drupal\sms\Message\SmsMessageResult;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Drupal\Component\Serialization\Json;
use Drupal\sms\Direction;
use Drupal\sms\Entity\SmsGatewayInterface;
use Drupal\sms\Message\SmsMessage;
use Drupal\sms\Message\SmsMessageInterface;
use Drupal\sms\Plugin\SmsGatewayPluginBase;
use Drupal\sms\SmsProcessingResponse;
class Incoming extends SmsGatewayPluginBase {
public function send(SmsMessageInterface $sms) {
}
public function processIncoming(Request $request, SmsGatewayInterface $sms_gateway) {
$json = Json::decode($request
->getContent());
$raw_messages = $json['messages'];
$sms_properties = [
'sender_number' => 'setSenderNumber',
'message' => 'setMessage',
'recipients' => 'addRecipients',
];
$messages = [];
foreach ($raw_messages as $raw_message) {
$result = new SmsMessageResult();
foreach ($raw_message['recipients'] as $recipient) {
$report = (new SmsDeliveryReport())
->setRecipient($recipient);
$result
->addReport($report);
}
$message = (new SmsMessage())
->setDirection(Direction::INCOMING)
->setGateway($sms_gateway)
->setResult($result);
foreach ($sms_properties as $property => $method) {
if (array_key_exists($property, $raw_message)) {
$value = $raw_message[$property];
call_user_func_array([
$message,
$method,
], [
$value,
]);
}
}
$messages[] = $message;
}
$response = new Response('', 204);
$task = (new SmsProcessingResponse())
->setResponse($response)
->setMessages($messages);
return $task;
}
}
Classes
Name |
Description |
Incoming |
Defines a gateway supporting incoming route. |