Twilio Node

The Twilio Node allows a workflow to send SMS messages using the configured Twilio account.

Node Properties

The configuration of the Twilio Node includes four major sections:

  • Twilio authentication
  • Defining the message contents
  • Setting up recipients
  • (Optional) Choosing a payload path for the result

Twilio Account Configuration

Twilio Node Account Config

The first step of the node configuration is Twilio authentication. There are several components:

  • The Twilio Account SID (required)
  • Authentication Method (required):

    • Auth Token: Authenticate with Twilio account Auth Token
    • API Key: Authenticate with Twilio API Key

Based on the selected Authentication Method, the required inputs for either Auth Token or API Key appear.

In the example above, the node is configured to use the Account SID YOUR_TWILIO_ACCOUNT_SID_HERE, an Authentication Method of API Key, and the API Key SID YOUR_TWILIO_API_KEY_SID_HERE with Secret YOUR_TWILIO_API_SECRET_HERE.

Optionally, the maximum allowed price of an SMS message can be configured (see Twilio’s API Docs for more information on this field).

All of the account configuration inputs, except for the maximum price, support string templates.

Message Configuration

Next, configure the content of the SMS message …

  • Send From: Choose whether to send the message from one of your Twilio phone numbers or from an SID.
  • From Template: Depending on the “Send From” choice, provide a string template that resolves to either a phone number or an SID in this field. This value must be associated with your Twilio account provided in the Twilio configuration.
  • SMS Message Template: Provide the body of the message. This should resolve to a short, plain-text message.
  • Media URL Template: Optionally, you may also provide a publicly available URL to a multimedia object to include as an attachment.

Either the SMS Message Template or the Media URL Template must be provided; you may also provide both.

Recipient Numbers

Provide at least one phone number to send your message to. Multiple recipients can receive the same message, and those recipients can be provided through a combination of the following methods …

  • One number per line.
  • Multiple numbers per line, separated by commas (,) or semicolons (;).
  • A string template referencing a phone number, a string of comma- or semicolon-separated numbers, or an array of phone numbers on the payload.

For example, given the following payload …

{
  "working": {
    "numbers": [
        "7894443333, 13214567890, +13026546544",
        "+19795753838"
    ],
    "extraNumber": "+18038274238"
  }
}

… and a Twilio Node with “To Numbers” defined as follows …

  1. +15135551212; +13753471111
  2. {{working.extraNumber}}
  3. {{working.numbers}}

… this would result in messages being sent to seven different recipients. (Each number is a separate send; the node does not create a group message for all recipients.)

Result

Optionally, provide a payload path where the result of the request can be placed on the current payload. If provided, the Twilio Node will place an array at this path, with one entry per recipient number.

Node Example

The following is an example of a payload after successfully sending a text to one recipient:

{
  "working": {
    "data": [
      {
        "success": true,
        "number": "+2128675309"
      }
    ]
  },
  "applicationName": "1234",
  "flowName": "twilio",
  "flowId": "5f11baf767b66e00079eaf01",
  "relayType": "user",
  "relayId": "5eda4db1f5f37d00072001c8",
  "flowVersion": "develop",
  "triggerType": "virtualButton",
  "triggerId": "5f11baf767b66e00079eaf01-CmMhatHPvLAi2eiv0elSq",
  "applicationId": "5ede6a9b4e9e6d0006466b49",
  },
  "time": "2020-07-17T18:42:09.942Z"
}

Node Errors

The Twilio Node can fail to send for several reasons. For example, In the case of an error, the resulting array contains objects with an error key and a message key instead of the success key.

For example, the following would be placed on the payload at a result path of working.twilioResult when trying to send the message with a “From” number that is not associated with your account:

{
  "working": {
    "twilioResult": [
      {
        "error": true,
        "message": "The From phone number +344423439583 is not a valid, SMS-capable inbound phone number or short code for your account.",
        "number": "+2128675309"
      }
    ]
  }
}

And, the following would be placed at the path when trying to send to an invalid phone number:

{
  "working": {
    "twilioResult": [
      {
        "error": true,
        "message": "Phone number invalid",
        "number": "+344454238712"
      }
    ]
  }
}

Was this page helpful?


Still looking for help? You can also search the WEGnology Forums or submit your question there.