Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,8 @@ jobs:
TESTS_GITHUB_INSTALLATION_ID: ${{ secrets.TESTS_GITHUB_INSTALLATION_ID }}
TESTS_BITBUCKET_ACCESS_TOKEN: ${{ secrets.TESTS_BITBUCKET_ACCESS_TOKEN }}
TESTS_BITBUCKET_WORKSPACE: ${{ secrets.TESTS_BITBUCKET_WORKSPACE }}
TESTS_WHATSAPP_ACCESS_TOKEN: ${{ secrets.TESTS_WHATSAPP_ACCESS_TOKEN }}
TESTS_WHATSAPP_PHONE_NUMBER_ID: ${{ secrets.TESTS_WHATSAPP_PHONE_NUMBER_ID }}
TESTS_WHATSAPP_BUSINESS_ACCOUNT_ID: ${{ secrets.TESTS_WHATSAPP_BUSINESS_ACCOUNT_ID }}
TESTS_WHATSAPP_RECIPIENT: ${{ secrets.TESTS_WHATSAPP_RECIPIENT }}
run: bin/monorepo test ${{ matrix.package }} ${{ matrix.linked && '--linked' || '' }}
1 change: 1 addition & 0 deletions .vale/styles/config/vocabularies/Utopia/accept.txt
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ worktree(?:s)?
webOS
WebView
Wget
WhatsApp
YAML
Yandex
zstd
4 changes: 4 additions & 0 deletions packages/messaging/.env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ FAST2SMS_MESSAGE_ID=
FAST2SMS_TO=
INFORU_API_TOKEN=
INFORU_SENDER_ID=
TESTS_WHATSAPP_ACCESS_TOKEN=
TESTS_WHATSAPP_PHONE_NUMBER_ID=
TESTS_WHATSAPP_BUSINESS_ACCOUNT_ID=
TESTS_WHATSAPP_RECIPIENT=
41 changes: 41 additions & 0 deletions packages/messaging/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,46 @@ $messaging = new Telesign('YOUR_USERNAME', 'YOUR_PASSWORD');
$messaging->send($message);
```

### One-time codes over WhatsApp

The WhatsApp adapter sends codes through a Meta Cloud API authentication template. Meta fixes the template text, so the message content is the code itself: up to 15 letters and digits, no free text. Create the template once per language, then send with the same `SMS` message type.

```php
<?php

use \Utopia\Messaging\Messages\SMS;
use \Utopia\Messaging\Adapter\SMS\WhatsApp;
use \Utopia\Messaging\Adapter\SMS\WhatsApp\App;
use \Utopia\Messaging\Adapter\SMS\WhatsApp\MetadataParameter;
use \Utopia\Messaging\Adapter\SMS\WhatsApp\OtpType;

$messaging = new WhatsApp('YOUR_ACCESS_TOKEN', 'YOUR_PHONE_NUMBER_ID', 'login_code');

// Copy-code works everywhere. One-tap and zero-tap hand the code straight to a
// named Android app and fall back to copy-code on other platforms.
$messaging->upsertTemplate(
'YOUR_BUSINESS_ACCOUNT_ID',
['en_US', 'fr'],
expirationMinutes: 10,
otpType: OtpType::ONE_TAP,
apps: [new App('com.example.app', 'K8a/AINcGX7')],
);

$messaging->getTemplate('YOUR_BUSINESS_ACCOUNT_ID'); // [['language' => 'en_US', 'status' => 'APPROVED', ...], ...]

$message = new SMS(
to: ['+12025550139'],
content: '482913'
);
$message->setMetadata([
MetadataParameter::LANGUAGE->value => 'fr',
MetadataParameter::TEMPLATE->value => 'recovery_code',
MetadataParameter::CALLBACK_DATA->value => 'token-64f1c2', // echoed back in status webhooks
]);

$messaging->send($message);
```

## Push

```php
Expand Down Expand Up @@ -118,6 +158,7 @@ $messaging->send($message);
- [x] [Seven](https://www.seven.io/)
- [ ] [SmsGlobal](https://www.smsglobal.com/)
- [x] [Inforu](https://www.inforu.co.il/)
- [x] [WhatsApp](https://developers.facebook.com/docs/whatsapp/cloud-api) (one-time codes through authentication templates)

### Push
- [x] [FCM](https://firebase.google.com/docs/cloud-messaging)
Expand Down
2 changes: 2 additions & 0 deletions packages/messaging/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
<exclude>tests/Messaging/Adapter/Email/EmailTest.php</exclude>
<exclude>tests/Messaging/Adapter/Email/SMTPTest.php</exclude>
<exclude>tests/Messaging/Adapter/SMS/SMSTest.php</exclude>
<exclude>tests/Messaging/Adapter/SMS/WhatsAppTest.php</exclude>
Comment thread
ChiragAgg5k marked this conversation as resolved.
</testsuite>
<testsuite name="e2e">
<file>tests/Messaging/Adapter/Email/EmailTest.php</file>
<file>tests/Messaging/Adapter/Email/SMTPTest.php</file>
<file>tests/Messaging/Adapter/SMS/SMSTest.php</file>
<file>tests/Messaging/Adapter/SMS/WhatsAppTest.php</file>
</testsuite>
</testsuites>
<source>
Expand Down
Loading
Loading