Docs Menu

Docs HomeAtlas App Services

Twilio Service [Deprecated]

On this page

  • Overview
  • Configuration Parameters
  • Service Actions
  • Incoming Webhooks
  • Configuration
  • Request Payload
  • Example Webhook Function
  • Configure Twilio
  • Create a Messaging Service
  • Add a Webhook to a Twilio Project

Important

Third Party Services & Push Notifications Deprecation

Third party services and push notifications in App Services have been deprecated in favor of creating HTTP endpoints that use external dependencies in functions.

Webhooks have been renamed to HTTPS Endpoints with no change in behavior. You should migrate existing Webhooks.

Existing services will continue to work until November 1, 2024.

Because third party services and push notifications are now deprecated, they have been removed by default from the App Services UI. If you need to manage an existing third party service or push notification, you can add the configurations back to the UI by doing the following:

  • In the left navigation, under the Manage section, click App Settings.

  • Enable the toggle switch next to Temporarily Re-Enable 3rd Party Services, and then save your changes.

Twilio provides messaging, voice, and chat services for web and mobile apps. The Atlas App Services Twilio service supports integrating Twilio's Programmable SMS service into your application.

Note

To use Twilio with App Services, you must have a Twilio Phone Number registered to a messaging service associated with your Twilio account. You can create a new number from the Numbers page of the Twilio dashboard, or by following Twilio's Programmable SMS Quickstart guide.

You will need to provide values for the following parameters when you create a Twilio service interface:

Parameter
Description
Service Name
config.name
The name of this Twilio service interface. This must be unique from all other service interfaces in your application.
Twilio Account SID
config.sid
A unique identifier for your Twilio account. You can find this value on your Twilio account dashboard.
Twilio Authorization Token
secret_config.auth_token
The name of a Secret that stores a Twilio authorization token, which proves that you are the owner of a Twilio account. You can find this value on your Twilio account dashboard.

The Twilio service in App Services provides the following actions which are available in functions and in the SDKs:

For instructions on using a service action, see Call a Service Action.

Note

Convert Twilio Webhooks to Endpoints

Twilio Service webhoooks are deprecated in favor of custom HTTPS endpoints. To learn how to migrate your existing Twilio webhooks to endpoints, see Convert Webhooks to HTTPS Endpoints.

Incoming webhooks for the Twilio service enable your App to handle incoming text messages. Once you've created an incoming webhook, you can add it to a Twilio messaging service to handle incoming messages for that service.

Configuration Value
Description
Webhook Name
name

Required. The name of the webhook.

Note

Each incoming webhook in a Twilio service interface must have a unique name.

Respond With Result
respond_result

Required. If true, App Services sends the return value of the webhook function to Twilio in the response body.

Note

Twilio will automatically send a text message containing the webhook response's body to the phone number that sent the initial message.

Run Webhook As
run_as_user_id
run_as_user_id_script_source

Optional. The id of the App Services user that executes the webhook function when the webhook is called.

App Services automatically passes a payload document as the first argument to incoming webhook functions. In a Twilio Service incoming webhook the payload object represents an incoming SMS message and has the following form:

{
"From": "<Sender's Phone Number>",
"To": "<Receiver's Phone Number>",
"Body": "<SMS Body>"
}
Field
Description
From
A string that contains the E.164-formatted phone number that sent the incoming text message.
To
A string that contains the E.164-formatted phone number associated with your Twilio messaging service that the incoming text message was sent to.
Body
A string that contains the content of the incoming text message.

Example

A text message sent from the phone number (555)867-5309 to the Twilio phone number (805)716-6646 with the message "Hello! How are you?" would be represented by the following payload document:

{
"From": "+15558675309",
"To": "+18057166646",
"Body": "Hello! How are you?"
}

The following webhook function stores text messages sent to a Twilio phone number in a MongoDB collection and sends a text message response to the phone number that sent the text.

exports = async function(payload, response) {
// const { To, From, Body } = payload;
const mongodb = context.services.get("mongodb-atlas");
const texts = mongodb.db("demo").collection("texts");
try {
// Save the text message body, to number, and from number
const { insertedId } = await texts.insertOne(payload);
// Send the user a confirmation text message
response.setBody(`Saved your text message with _id: ${insertedId}`);
} catch (error) {
// Send the user an error notification text message
response.setBody(`Failed to save your text message: ${error}`);
}
}
  1. Log in to Twilio.

  2. Click Programmable SMS in the left navigation menu of your Twilio project.

  3. Click SMS > Messaging Services.

  4. Click Create new Messaging Service.

  5. Enter a Friendly Name and Use Case

  6. Click Create

  1. Click Programmable SMS in the left navigation menu of your Twilio project.

  2. Click SMS > Messaging Services.

  3. Click the messaging service that you want to use.

  4. On the messaging service configuration page, check the PROCESS INBOUND MESSAGES box.

  5. Enter the incoming webhook URL in the Request URL box.

  6. Click Save.

Your App is now integrated with Twilio's SMS messaging service. Send a message to your Twilio phone number to invoke the incoming webhook for your App.

←  http.head()twilio.send() →