Send SMS messages

You can send custom sms messages to your app's users using Appwrite Messaging and a connected SMTP service. This guide takes you through the implementation path of adding sms messaging to your app.

Add a provider

Appwrite supports Twilio, MSG91, Telesign, TextMagic, and Vonage as SMS providers. You must configure one of them as a provider.

Add a SMTP provider

Add a SMTP provider

To add a new provider navigate to Messaging > Providers > Add provider > SMS and follow the wizard. You can find more details about configuring in the provider guides for Twilio, MSG91, Telesign, TextMagic, and Vonage.

Add targets

In Appwrite Messaging, each user has targets like their email, phone number, and devices with your app installed. You can deliver messages to users through their targets.

Target overview

Target overview

If the user signed up with phone (SMS) authentication, their account would already have a phone number as a target. During development, you can add targets to existing accounts by navigating to Authentication > Users > Select a user > Targets > Add a subscriber.

Add a target

Add a target

You can also implement forms in your app to collect contact information and add it as a target with the createSubscriber endpoint.

const sdk = require('node-appwrite');

const client = new sdk.Client()
    .setEndpoint('https://cloud.appwrite.io/v1')  // Your API Endpoint
    .setProject('5df5acd0d48c2')                  // Your project ID
    .setKey('919c2d18fb5d4...a2ae413da83346ad2');                  // Your secret API key

const users = new sdk.Users(client);

const target = await users.createTarget(
    '<USER_ID>',                     // userId
    '<TARGET_ID>',                   // targetId
    sdk.MessagingProviderType.Phone, // providerType
    '<IDENTIFIER>',                  // identifier
    '<PROVIDER_ID>',                 // providerId (optional)
    '<NAME>'                         // name (optional)
);

Create topics (optional)

You can use topics to organize targets that should receive the same messages, so you can send SMS messages to groups of targets instead of one at time. This step is optional if you plan to only send SMS messages to individual targets.

To create a topic in the Appwrite Console, navigate to Messaging > Topics > Create topic.

Add a target

Add a target

You can also create topics programmatically using an Appwrite Server SDK.

const sdk = require('node-appwrite');

const client = new sdk.Client()
    .setEndpoint('https://cloud.appwrite.io/v1')  // Your API Endpoint
    .setProject('5df5acd0d48c2')                  // Your project ID
    .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key

const messaging = new sdk.Messaging(client);

const topic = await messaging.createTopic(
    '[TOPIC_ID]',     // topicId
    '[NAME]'          // name
);

Send SMS messages

You can send SMS messages using a Server SDK. To send an SMS messages immediately, you can call the createSMS endpoint without passing either the draft or scheduledAt parameters.

const sdk = require('node-appwrite');

// Init SDK
const client = new sdk.Client()
    .setEndpoint('https://cloud.appwrite.io/v1')  // Your API Endpoint
    .setProject('5df5acd0d48c2')                  // Your project ID
    .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key

const messaging = new sdk.Messaging(client);

const message = await messaging.createSMS(
    '[MESSAGE_ID]',    // messageId
    '[CONTENT]',       // content
    [],                // topics (optional)
    [],                // users (optional)
    [],                // targets (optional)
    false,             // draft (optional)
    ''                 // scheduledAt (optional)
);

Schedule SMS message

To send an scheduled SMS message, you can call the createSMS endpoint with scheduledAt as a ISO 8601 date time string for the scheduled time.

const sdk = require('node-appwrite');

// Init SDK
const client = new sdk.Client()
    .setEndpoint('https://cloud.appwrite.io/v1')  // Your API Endpoint
    .setProject('5df5acd0d48c2')                  // Your project ID
    .setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key

const messaging = new sdk.Messaging(client);

const message = await messaging.createSMS(
    '[MESSAGE_ID]',             // messageId
    '[CONTENT]',                // content
    [],                         // topics (optional)
    [],                         // users (optional)
    [],                         // targets (optional)
    false,                      // draft (optional)
    '2025-02-13T22:01:00+0000'  // scheduledAt (optional)
);