twilio.send()
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
exports = function() { const twilio = context.services.get("myTwilio"); twilio.send({ to: "+15558675309", from: "+15551234567", body: "Hello from App Services!" }); };
Parameters
Parameter | Type | Description | |||||
---|---|---|---|---|---|---|---|
| document | A document of the following form:
| |||||
| string | The recipient's phone number in E.164 Format. | |||||
| string | A phone number associated with your Twilio account in E.164 Format. | |||||
| string | The message to send. |
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; }