1441 |
ariadna |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
namespace smsgateway_aws;
|
|
|
18 |
|
|
|
19 |
use core_sms\manager;
|
|
|
20 |
use core_sms\message;
|
|
|
21 |
use MoodleQuickForm;
|
|
|
22 |
|
|
|
23 |
/**
|
|
|
24 |
* AWS SMS gateway.
|
|
|
25 |
*
|
|
|
26 |
* @package smsgateway_aws
|
|
|
27 |
* @copyright 2024 Safat Shahin <safat.shahin@moodle.com>
|
|
|
28 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
29 |
*/
|
|
|
30 |
class gateway extends \core_sms\gateway {
|
|
|
31 |
|
|
|
32 |
#[\Override]
|
|
|
33 |
public function send(
|
|
|
34 |
message $message,
|
|
|
35 |
): message {
|
|
|
36 |
global $DB;
|
|
|
37 |
// Get the config from the message record.
|
|
|
38 |
$awsconfig = $DB->get_field(
|
|
|
39 |
table: 'sms_gateways',
|
|
|
40 |
return: 'config',
|
|
|
41 |
conditions: ['id' => $message->gatewayid, 'enabled' => 1, 'gateway' => 'smsgateway_aws\gateway',],
|
|
|
42 |
);
|
|
|
43 |
$status = \core_sms\message_status::GATEWAY_NOT_AVAILABLE;
|
|
|
44 |
if ($awsconfig) {
|
|
|
45 |
$config = (object)json_decode($awsconfig, true, 512, JSON_THROW_ON_ERROR);
|
|
|
46 |
$class = '\smsgateway_aws\local\service\\' . $config->gateway;
|
|
|
47 |
$recipientnumber = manager::format_number(
|
|
|
48 |
phonenumber: $message->recipientnumber,
|
|
|
49 |
countrycode: isset($config->countrycode) ?? null,
|
|
|
50 |
);
|
|
|
51 |
|
|
|
52 |
if (class_exists($class)) {
|
|
|
53 |
$status = call_user_func(
|
|
|
54 |
$class . '::send_sms_message',
|
|
|
55 |
$message->content,
|
|
|
56 |
$recipientnumber,
|
|
|
57 |
$config,
|
|
|
58 |
);
|
|
|
59 |
}
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
return $message->with(
|
|
|
63 |
status: $status,
|
|
|
64 |
);
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
#[\Override]
|
|
|
68 |
public function get_send_priority(message $message): int {
|
|
|
69 |
return 50;
|
|
|
70 |
}
|
|
|
71 |
}
|