Navigation
  • Rules >
  • Twilio Service Rules

Twilio Service Rules

Twilio provides messaging, voice, and chat services for web and mobile apps. MongoDB Stitch supports integrating apps with Twilio’s Programmable SMS service.

To use the Twilio Service, you must specify rules to enable its actions. The rule must evaluate to true for the action to be enabled. Actions can be configured to be always enabled by specifying an empty document for your rule, {} , which evaluates to true.

Service Configuration

Before applying service rules, you must set up the Twilio service and add it to your MongoDB Stitch application. For instructions on setting up your Twilio service, see Twilio Service.

Specify a Rule

  1. Select the send checkbox under Actions.

  2. Specify a rule in valid JSON that evaluates to a boolean. The following are permitted in the rule document:

    {
      <field1>: <value1|expression1>,
      <field2>: <value2|expression2>,
      ...
    }
    

Twilio Service Arguments

To specify a rule based on arguments:

{
  "%%args.<argument1>": <value1|expression1>,
  "%%args.<argument2>": <value1|expression2>,
  ...
}

Or, you can omit the %%args prefix if you do not specify any expansion prefixes for the fields.

{
  "<argument1>": <value1|expression1>,
  "<argument2>": <value1|expression2>,
  ...
}

However, you cannot mix arguments with prefixes and arguments without prefixes in the same rule. For example, the following rule is invalid:

{
  "%%args.to": "text@example.com",
  "from": "someone@example.com",
  ...
}

The following arguments are permitted in Twilio service rules:

Field Type Description
to String The destination phone number in E.164 format, such as "+15551112222".
from String The originating phone number in E.164 format, such as "+15551112222".
body String The body of the message.

Example

Actions When
send
{
  "to" : { "%in": "%%values.confirmedNumbers" },
}

This rule ensures that applications can only perform a send action when the to argument is a string listed in confirmedNumbers, where confirmedNumbers is a user-defined constant. For more information on defining constants, see Values.

←   HTTP Service Rules Values  →