Docs Home → Atlas App Services
twilio.send()
On this page
Definition
Sends an SMS text message with Twilio.
Usage
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",
Example
Parameters
Return Value
The twilio.send()
action does not return a value.
Rule Templates
Users Can Send Only Messages from a Specific Phone Number
{ "%%args.from": "+15551234" }
Users Can Only Send Messages to a Limited Set of Phone Numbers
{ "%%args.to": { "$in": [ "+15551234", "+18675309" ] } }
Users Can Only Send Messages to Themselves
{ "%%true": { "%function": { "name": "isCurrentUsersPhoneNumber", "arguments": [ "%%args.to" ] } } }
Note
This template calls an example function named
isCurrentUsersPhoneNumber
that does the following:
Accepts the phone number provided in the
to
argumentQueries MongoDB for a user document that matches the current user's id
Compares the provided phone number to the number listed in the user document
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; }