You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SMS gateway plugins allow you to create SMS gateway providers.
12
+
Providers are an interface between [SMS API](/apis/subsystems/sms/index.md) and the external SMS provider (e.g. Amazon Web Services).
13
+
This allows for the sending of SMS notifications to users from your Moodle instance.
14
+
15
+
For example, you set up MFA (Multi-Factor Authentication) in Moodle and choose 'AWS' as your SMS gateway provider.
16
+
This enables users to receive SMS notifications as part of the authentication process.
17
+
18
+
## File structure
19
+
20
+
SMS gateway plugins are located in the `/sms/gateway` directory. A plugin should not include any custom files outside its own
21
+
plugin folder.
22
+
23
+
Each plugin is in a separate subdirectory and consists of a number of mandatory files and any other files the developer is going to use. See the [common plugin files](/apis/commonfiles/index.mdx) documentation for other files which may be useful in your plugin.
24
+
25
+
<details>
26
+
<summary>The directory layout for the `smsgateway` plugin.</summary>
27
+
28
+
```console
29
+
sms/gateway/example
30
+
├── classes
31
+
│ ├── gateway.php
32
+
│ ├── hook_listener.php
33
+
│ └── privacy
34
+
│ └── provider.php
35
+
├── lang
36
+
│ └── en
37
+
│ └── smsgateway_example.php
38
+
├── settings.php
39
+
└── version.php
40
+
```
41
+
42
+
</details>
43
+
44
+
## Key files
45
+
46
+
There are a number of key files within the SMS gateway plugin which will need to be configured for correct functionality.
47
+
48
+
- gateway.php
49
+
- hook_listener.php
50
+
51
+
### gateway.php
52
+
53
+
Each plugin must create a class called `gateway` which extends the `\core_sms\gateway` class.
54
+
The SMS API will use the extended methods from this class.
A single SMS sent by the API may consist of up to 480 UTF-8 characters. It is up to the message _gateway_ plugin to determine how this message is sent to the recipient.
43
+
A single SMS sent by the API may consist of up to 480 UTF-8 characters. It is up to the message _gateway plugin_ to determine how this message is sent to the recipient.
29
44
30
45
Any message longer than the maximum length will be immediately rejected.
31
46
32
47
:::
33
48
49
+
### Parameter consideration while sending messages
50
+
51
+
When sending a message it's important add the correct `component` (e.g. `tool_mfa`) and `messagetype` (e.g. `mfa code`) for record keeping purpose.
52
+
One component can have many different types of messages and those types should be clearly mentioned while sending the messages so that they are clear
53
+
in reporting and other locations. [MDL-80963](https://tracker.moodle.org/browse/MDL-81015) will be used to build a report for messages status.
54
+
55
+
The `gatewayid` is an optional parameter, and it's not required to mention it. If the plugin has a specific gateway selected as a part of
56
+
the config and or a specific gateway config needs to be used, then it can mention the `gatewayid` of that specific gateway config. Otherwise,
57
+
the SMS API will pick one according to the priority and use that to send the message.
58
+
34
59
### Sending messages containing sensitive information
35
60
36
61
When sending a message containing something like a 2FA login token, you should make use of the `issensitive` flag.
@@ -39,6 +64,11 @@ Passing this flag prevents the SMS subsystem from storing the content of the mes
39
64
40
65
The `send()` method return an instance of `\core_sms\message` which can be used to check on the message status.
41
66
67
+
### Sending messages asynchronously
68
+
69
+
Messages can not be sent asynchronously yet. The parameter has been implemented, but the feature is yet to be built
70
+
(see [MDL-81015](https://tracker.moodle.org/browse/MDL-81015) for more information).
71
+
42
72
## Fetching messages
43
73
44
74
Every sent message is stored in the database for subsequent reporting, and to check statuses.
@@ -122,3 +152,47 @@ graph TD
122
152
GQ --> |Gateway failed to send the message| GF
123
153
end
124
154
```
155
+
156
+
## Getting SMS gateways
157
+
158
+
[SMS gateways](/apis/plugintypes/sms/index.md) are plugins that provide a way to interface with external SMS providers.
159
+
Once a gateway is configured, any component implementing the SMS API can get a list of gateways.
160
+
161
+
```php title="Getting the list of enabled gateways"
0 commit comments