# Twilio

<div align="left"><figure><img src="https://3401585094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmnBepgycwgisXr9ya1N4%2Fuploads%2FypHh4cyFrkLSMANErFwU%2Fimage.png?alt=media&#x26;token=abb66af5-d5cd-4a3f-9781-48f1c88e4ce7" alt="" width="188"><figcaption></figcaption></figure></div>

The Twilio service allows you to send automated text/sms/mms messages from your app using the [Twilio API](https://www.twilio.com/docs/usage/api).

***

## Profile Settings

{% hint style="success" %}
NOTE: All profile settings are encrypted and stored in Zingy's cloud infrastructure.
{% endhint %}

### Account SID

<div align="left"><figure><img src="https://3401585094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmnBepgycwgisXr9ya1N4%2Fuploads%2FvdZ5Bl4yfbr3vYY2IiSd%2Fimage.png?alt=media&#x26;token=dee800cd-7768-4a0c-9b42-00d4d796e68e" alt="" width="375"><figcaption></figcaption></figure></div>

Enter your [Twilio Account SID](https://help.twilio.com/articles/14726256820123-What-is-a-Twilio-Account-SID-and-where-can-I-find-it-) here.

### API Key (optional)

<div align="left"><figure><img src="https://3401585094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmnBepgycwgisXr9ya1N4%2Fuploads%2FUg6fpYu1Vz7rPKAXfwhp%2Fimage.png?alt=media&#x26;token=1e3b6b99-2cd2-4c7b-9ec7-b9cf52195dc1" alt="" width="375"><figcaption></figcaption></figure></div>

Twilio allows you to use its API services using either Auth Tokens or API Keys with Key secrets.

If you plan on using API Key, enter the value here.

Click [here](https://www.twilio.com/blog/better-twilio-authentication-csharp-twilio-api-keys) for more information.

### Auth Token/API Key Secret

<div align="left"><figure><img src="https://3401585094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmnBepgycwgisXr9ya1N4%2Fuploads%2FpTK7WR12YPyZ3miF2gct%2Fimage.png?alt=media&#x26;token=4646ba14-fc81-4b3c-9203-43c01405459c" alt="" width="375"><figcaption></figcaption></figure></div>

If you entered a API Key above, enter the API Key Secret value here. If not, enter your Twilio account's [Auth Token value](https://help.twilio.com/articles/14726256820123-What-is-a-Twilio-Account-SID-and-where-can-I-find-it-) here.

Click [here](https://www.twilio.com/blog/better-twilio-authentication-csharp-twilio-api-keys) for more information on Auth Token vs API Keys.

***

## Connection Settings

The Twilio service does not have any connection specific settings.

***

## Operations/Commands

The [Execute Connection Command](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/execute-connection-command) block is available in both [Page Flow](https://docs.zingy.ai/app-editor/page-flow) and [Cloud Flow](https://docs.zingy.ai/app-editor/cloud-flow). Using this block you can add logic to trigger the operations/commands supported by the Sendgrid service.

{% hint style="success" %}
For security purposes, all operations/commands offered by the Twilio service are only available in [Cloud Flow](https://docs.zingy.ai/app-editor/cloud-flow) and cannot be used in [Page Flow](https://docs.zingy.ai/app-editor/page-flow).
{% endhint %}

### Send Message

Use this command to send a text/sms/mms using the Twilio service.

#### Input Data

When invoking this operation, an object with the following properties is required:

<table><thead><tr><th width="149">Property</th><th width="95">Type</th><th>Description</th></tr></thead><tbody><tr><td>fromPhone</td><td><a href="../../page-flow/references/value-types">text</a></td><td>A <a href="https://www.twilio.com/blog/register-phone-number-send-sms-twilio-cli">registered and approved</a> origination phone number in <a href="https://www.twilio.com/docs/glossary/what-e164">E.164 format</a>.</td></tr><tr><td>fromService</td><td><a href="../../page-flow/references/value-types">text</a></td><td>Optional. If sending the message as part of a campaign, specify the <a href="https://www.twilio.com/docs/messaging/tutorials/send-messages-with-messaging-services#send-a-message-with-a-messaging-service">Message Service SID</a> here.</td></tr><tr><td>toPhone</td><td><a href="../../page-flow/references/value-types">text</a></td><td>The recipient phone number in in <a href="https://www.twilio.com/docs/glossary/what-e164">E.164 format</a>.</td></tr><tr><td>msg</td><td><a href="../../page-flow/references/value-types">text</a></td><td>The message body.</td></tr><tr><td>customProps</td><td><a href="../../page-flow/references/value-types">object</a></td><td>Optional. For advanced users, this specifies an object with properties based on parameters used by the <a href="https://www.twilio.com/docs/messaging/tutorials/how-to-send-sms-messages/node">Twilio API</a>.</td></tr></tbody></table>

#### Output

[Object](https://docs.zingy.ai/app-editor/page-flow/references/value-types) containing information about the message. Please refer to the [Twilio API documentation](https://www.twilio.com/docs/messaging/api/message-resource) for details.

### List Messages

Use this command to list messages in your Twilio account.

#### Input Data

When invoking this operation, an object with the following properties is required:

<table><thead><tr><th width="149">Property</th><th width="95">Type</th><th>Description</th></tr></thead><tbody><tr><td>criteria</td><td><a href="../../page-flow/references/value-types">object</a></td><td>Optional. Object containing criteria for listing as specified by the <a href="https://www.twilio.com/docs/messaging/tutorials/how-to-retrieve-and-modify-message-history#search-previous-messages">Twilio API</a>.</td></tr><tr><td>limit</td><td><a href="../../page-flow/references/value-types">numeric</a></td><td>Optional. Limit the number of messages listed per page.</td></tr></tbody></table>

#### Output

[List](https://docs.zingy.ai/app-editor/page-flow/references/value-types) of messages retrieved based on the criteria specified.

### Read Message

Use this command to retrieve/fetch a specific text/sms/mms message in your Twilio account.

#### Input Data

When invoking this operation, an object with the following properties is required:

<table><thead><tr><th width="149">Property</th><th width="95">Type</th><th>Description</th></tr></thead><tbody><tr><td>sid</td><td><a href="../../page-flow/references/value-types">text</a></td><td>The unique Message SID identifying the message to be read.</td></tr></tbody></table>

#### Output

[Object](https://docs.zingy.ai/app-editor/page-flow/references/value-types) representing the message.

### Update Message

Use this command update properties of a text/sms/mms message in your Twilio account. This command is usually used to [redact a message](https://www.twilio.com/docs/messaging/tutorials/how-to-retrieve-and-modify-message-history#delete-or-redact-previously-sent-messages).

#### Input Data

When invoking this operation, an object with the following properties is required:

<table><thead><tr><th width="211">Property</th><th width="90">Type</th><th>Description</th></tr></thead><tbody><tr><td>sid</td><td><a href="../../page-flow/references/value-types">text</a></td><td>The unique Message SID identifying the message to be updated.</td></tr><tr><td>customProps</td><td><a href="../../page-flow/references/value-types">object</a></td><td>Object containing properties to be updated. Please note that Twilio restricts specific properties from being updated based on the status of the message.</td></tr></tbody></table>

#### Output

[Object](https://docs.zingy.ai/app-editor/page-flow/references/value-types) containing information about the message. Please refer to the [Twilio API documentation](https://www.twilio.com/docs/messaging/tutorials/how-to-retrieve-and-modify-message-history#delete-or-redact-previously-sent-messages) for details.

### Delete Message

Use this command delete a text/sms/mms message in your Twilio account.

#### Input Data

When invoking this operation, an object with the following properties is required:

<table><thead><tr><th width="149">Property</th><th width="95">Type</th><th>Description</th></tr></thead><tbody><tr><td>sid</td><td><a href="../../page-flow/references/value-types">text</a></td><td>The unique Message SID identifying the message to be deleted.</td></tr></tbody></table>

#### Output

This command does not provide any output beyond the Success/Fail status.

***

## Advanced Functionality

In your app's Cloud Flow Web Hooks and Background Tasks, the [Custom Code](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/custom-code) block can be used to access and implement advanced functionality related to the Twilio messaging service.

To access the Twilio client initialized with credentials saved on this Twilio service connection, see the following example:

```javascript
// To use a twilio client initialized with credentials provided 
// in a Twilio connection
const client = zingyConn.twilio(connectionName);
```

You may also initialize a seperate Twilio client, by specifying account credentials directly:

```javascript
// To create a new twilio client specifying account credentials
const client = require('twilio')(accountSid, authToken);
```

After the `client` object is initialized, you can use it to call into the Twilio library. Refer to [Twilio library](https://www.npmjs.com/package/twilio) documentation for more information.
