Navigation

twilio.send()

twilio.send()

Sends an SMS text message with Twilio.

Info With Circle IconCreated with Sketch.Note

To send or receive messages via the Twilio API for WhatsApp, prepend the to or from numbers with whatsapp:.

to: "whatsapp:+15558675309",
from: "whatsapp:+15551234567",
exports = function() {
const twilio = context.services.get("myTwilio");
twilio.send({
to: "+15558675309",
from: "+15551234567",
body: "Hello from Realm!"
});
};
ParameterTypeDescription
argsdocument

A document of the following form:

{
"to": <string>, // recipient phone #
"from": <string>, // sender phone #
"body": <string> // message
}
args.tostringThe recipient's phone number in E.164 Format.
args.fromstringA phone number associated with your Twilio account in E.164 Format.
args.bodystringThe message to send.

The twilio.send() action does not return a value.

{
"%%args.from": "+15551234"
}
{
"%%args.to": {
"$in": [
"+15551234",
"+18675309"
]
}
}
{
"%%true": {
"%function": {
"name": "isCurrentUsersPhoneNumber",
"arguments": [
"%%args.to"
]
}
}
}
Info With Circle IconCreated with Sketch.Note

This template calls an example function named isCurrentUsersPhoneNumber that does the following:

  1. Accepts the phone number provided in the to argument
  2. Queries MongoDB for a user document that matches the current user's id
  3. Compares the provided phone number to the number listed in the user document
  4. Returns the boolean result of the comparison
exports = function(toPhone) {
const mdb = context.services.get('mongodb-atlas');
const users = mdb.db('demo').collection('users');
const user = users.findOne({ _id: context.user.id });
return user.phoneNumber === toPhone;
}
Give Feedback