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 rules must evaluate to true for the action to be enabled. An empty document ({}) always evaluates to true.

Specify a Rule

  1. Select the send checkbox under Actions.

  2. Specify the rule in valid JSON that evaluates to a boolean. You can specify MongoDB query expression operators with the exception of the $text and geospatial operators:

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

    You can specify rules based on an argument to the action. For details and examples, see Twilio Service Arguments.

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",
  ...
}

You can use the following action arguments in Twilio service rules.

to

The to argument is a string that corresponds to the destination phone number in E.164 format, such as "+15551112222".

from

The from argument is a string that corresponds to the originating phone number in E.164 format, such as "+15551112222".

body

The body argument is a string that corresponds to 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 in defining constants, see Values.