Merge pull request #8222 from appwrite/feat-support-twilio-messaging-service-sid

feat: support twilio messaging service sid
This commit is contained in:
Luke B. Silver 2024-05-30 17:24:38 +01:00 committed by GitHub
commit 065dfa6663
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 22 additions and 14 deletions

View file

@ -450,7 +450,7 @@ return [
], ],
[ [
'name' => '_APP_SMS_FROM', 'name' => '_APP_SMS_FROM',
'description' => 'Phone number used for sending out messages. Must start with a leading \'+\' and maximum of 15 digits without spaces (+123456789).', 'description' => 'Phone number used for sending out messages. If using Twilio, this may be a Messaging Service SID, starting with MG. Otherwise, the number must start with a leading \'+\' and maximum of 15 digits without spaces (+123456789). ',
'introduction' => '0.15.0', 'introduction' => '0.15.0',
'default' => '', 'default' => '',
'required' => false, 'required' => false,

View file

@ -58,7 +58,7 @@
"utopia-php/image": "0.6.*", "utopia-php/image": "0.6.*",
"utopia-php/locale": "0.4.*", "utopia-php/locale": "0.4.*",
"utopia-php/logger": "0.5.*", "utopia-php/logger": "0.5.*",
"utopia-php/messaging": "0.11.*", "utopia-php/messaging": "0.12.*",
"utopia-php/migration": "0.4.*", "utopia-php/migration": "0.4.*",
"utopia-php/orchestration": "0.9.*", "utopia-php/orchestration": "0.9.*",
"utopia-php/platform": "0.5.*", "utopia-php/platform": "0.5.*",

14
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "53996479cd4ba0c73dbc72d46b240be0", "content-hash": "bee024ec80d546d910563dc166baed9e",
"packages": [ "packages": [
{ {
"name": "adhocore/jwt", "name": "adhocore/jwt",
@ -2119,16 +2119,16 @@
}, },
{ {
"name": "utopia-php/messaging", "name": "utopia-php/messaging",
"version": "0.11.0", "version": "0.12.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/utopia-php/messaging.git", "url": "https://github.com/utopia-php/messaging.git",
"reference": "b499c3ad11af711c28252c62d83f24e6106a2154" "reference": "6e466d3511981291843c6ebf9ce3f44fc75e37b0"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/utopia-php/messaging/zipball/b499c3ad11af711c28252c62d83f24e6106a2154", "url": "https://api.github.com/repos/utopia-php/messaging/zipball/6e466d3511981291843c6ebf9ce3f44fc75e37b0",
"reference": "b499c3ad11af711c28252c62d83f24e6106a2154", "reference": "6e466d3511981291843c6ebf9ce3f44fc75e37b0",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2164,9 +2164,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/utopia-php/messaging/issues", "issues": "https://github.com/utopia-php/messaging/issues",
"source": "https://github.com/utopia-php/messaging/tree/0.11.0" "source": "https://github.com/utopia-php/messaging/tree/0.12.0"
}, },
"time": "2024-05-08T17:10:02+00:00" "time": "2024-05-30T14:58:25+00:00"
}, },
{ {
"name": "utopia-php/migration", "name": "utopia-php/migration",

View file

@ -399,7 +399,10 @@ class Messaging extends Action
'credentials' => match ($host) { 'credentials' => match ($host) {
'twilio' => [ 'twilio' => [
'accountSid' => $user, 'accountSid' => $user,
'authToken' => $password 'authToken' => $password,
// Twilio Messaging Service SIDs always start with MG
// https://www.twilio.com/docs/messaging/services
'messagingServiceSid' => \str_starts_with($from, 'MG') ? $from : null
], ],
'textmagic' => [ 'textmagic' => [
'username' => $user, 'username' => $user,
@ -420,9 +423,14 @@ class Messaging extends Action
], ],
default => null default => null
}, },
'options' => [ 'options' => match ($host) {
'from' => $from 'twilio' => [
] 'from' => \str_starts_with($from, 'MG') ? null : $from
],
default => [
'from' => $from
]
}
]); ]);
$adapter = $this->getSmsAdapter($provider); $adapter = $this->getSmsAdapter($provider);
@ -465,7 +473,7 @@ class Messaging extends Action
return match ($provider->getAttribute('provider')) { return match ($provider->getAttribute('provider')) {
'mock' => new Mock('username', 'password'), 'mock' => new Mock('username', 'password'),
'twilio' => new Twilio($credentials['accountSid'], $credentials['authToken']), 'twilio' => new Twilio($credentials['accountSid'], $credentials['authToken'], null, isset($credentials['messagingServiceSid']) ? $credentials['messagingServiceSid'] : null),
'textmagic' => new TextMagic($credentials['username'], $credentials['apiKey']), 'textmagic' => new TextMagic($credentials['username'], $credentials['apiKey']),
'telesign' => new Telesign($credentials['customerId'], $credentials['apiKey']), 'telesign' => new Telesign($credentials['customerId'], $credentials['apiKey']),
'msg91' => new Msg91($credentials['senderId'], $credentials['authKey'], $credentials['templateId']), 'msg91' => new Msg91($credentials['senderId'], $credentials['authKey'], $credentials['templateId']),