Using Twilio node

Orbita can be integrated with Twilio to make phone calls or send SMS with the help of the Twilio node in Experience Designer. The URL of the TwiML used to create the phone call or msg.payload can contain the text of the SMS message.

 

Prerequisites

  • Registered Twilio account.

  • Twilio-powered Phone number.

Twilio node

The URL will be the local endpoint that was created in the first section.
http://127.0.0.1/oeapi/twilioml.xml

If you configure the node to make a phone call, provide a TwiML URL that is publicly accessible. You can add the receiving phone number in the To field, in the Twilio node, so that Twilio will send the text message(s) or make a phone call. If you set the msg.topic property in the function node connected to the Twilio node, the To field should be left blank.

Setting credentials

There are two options in the Credentials drop-down.

  • Use global credentials. Contact orbitasupport@orbita.ai to get details on the environmental variables used to configure global credentials.

  • Use local credentials. Use this option to give details of your Twilio account in the node. The recipient(s) will receive messages/phone calls from your Twilio phone number.

Adding a Twilio account to the Twilio node

To add a new Twilio account to the Twilio node:

  1. Open the Twilio node.

  2. Select “Use local credentials“ in the Credentials field and “Add new twilio-api…“ from the Twilio field as shown in the screenshot below. Click Edit against the Twilio field.

     

  3. A new dialog box appears. Enter the details from your Twilio account.

     

    1. Account SID and Token - you will get it from the Twilio console (Refer below section).

    2. From - the Twilio phone number.

    3. Name - Name of the Twilio configuration.

Twilio Account SID and token

  1. Go to and log in to your Twilio account.

     

  2. On the console page, you can get the Account SID and Auth Token.

Setting output

There are three types of Output.

 

  • SMS. Lets the Twilio node send a text message to the phone number.

     

     

  • Call. Lets the Twilio node make a phone call to the phone number.

     

     

  • WhatsApp. Lets the Twilio node send a message via WhatsApp.

     

     

    • To. The phone number to which a phone call or SMS or WhatsApp should be made or sent. If you use msg.topic property in the function node to add the phone number, you can leave this field blank.

    • URL. Phone calls that you make from a Twilio number to an outside number are controlled using TwiML. The initial URL for the call is provided as a parameter to the Twilio REST API request, which you make, to initiate the call.

      See, https://www.twilio.com/console/voice/twiml/overview to learn more about the URL.

    • Name. Name of the node.

Example flow

The following flow shows how to integrate Twilio with Experience Designer.

In the example, when a valid user triggers the help intent, Twilio reads TwiML instructions at that URL. In the function node, the TwiML is already instructed to respond in an automated voice “Please leave a message after the tone” and start the recording for 20 seconds.

Two different flows are given in the above example. The first flow creates an endpoint URL that can be used in the Twilio node. The second flow triggers a call when an authenticated user says “help”.

http in node

Creates an http end-point for creating web services.

  • Method is set to GET.

  • URL. Enter the XML file that is created.

Function node

The following code is used with parameters like msg.payload, statusCode, and msg.header. Push the XML code in msg.payload for this example. This XML code sends a short message and records the caller's voice post message.

msg.payload='<?xml version="1.0" encoding="UTF-8"?><Response><Say voice="woman">Please leave a message after the tone.</Say><Record maxLength="20" /></Response>'; msg.statusCode=200; msg.headers = {"content-type": "application/xml"}; return msg;

http response node

Sends responses back to requests that were received from the HTTP input node.

Intent Request node

Triggers the flow when help is called by the user.

Function node

Checks whether the user is an authenticated user.

Say node

Configure the bot to say something based on the output from the attached function node.

Status call back

We can identify the delivery status of the Twilio SMS or IVR calls we make from the system through the Twilio status call back property.

Voice/ IVR status callBack

Please use the below snippet to set the status call back function for IVR communication.

msg.twilio = { settings: { machineDetection: "DetectMessageEnd", machineDetectionTimeout: 30, asyncAmd: false, asyncAmdStatusCallbackMethod: "POST", asyncAmdStatusCallback: "https://domain/oeapi/amd", statusCallback:'https://domain/oeapi/twilio/voice/status', statusCallbackMethod: 'POST', statusCallbackEvent: ['initiated', 'answered', 'ringing', 'completed'] } }

The status of the connection will be available under the response property CallStatus

  1. When the call is initiated the status is CallStatus: "initiated"

  2. When the phone is ringing the status is CallStatus: "ringing"

  3. When the user attends the phone call the status is CallStatus: "In-Progress"

  4. When the call is disconnected the status is CallStatus: "completed"

  5. When the user does not attend the call or when the user disconnects the call without attending, then the status is CallStatus: "no-answer"

SMS status callBack

Please use the below snippet to set the status call back function for SMS communication.

msg.twilio = { settings: { statusCallbackMethod:'POST', statusCallback: 'https://domain/oeapi/twilio/sms/status', } }

The status of the connection will be available under the response property CallStatus

  1. When the SMS is sent, the status is SmsStatus: "sent"

  2. When the SMS is delivered, the status is SmsStatus: "delivered"

StatusCallBack Flow sample

The sample code to set up Twilio SMS and IVR services are given below. Import this code snippet in the Experience Designer.

Best Practices

  1. Do not use special characters in the messages.

  2. If the message is large (i.e. greater than 140 characters), split the message into segments and use multiple Twilio nodes to send the segments with a delay.

  3. The maximum number of characters allowed in one segment is 140. If you use multiple segments, then you should restrict the maximum number of characters used in each segment to 134 as 6 characters will be utilized to link the segments together.

Related Articles