Twilio Conversations: Create meaningful connections with customers across various communication channels. Visit our official site for more detalis: https://www.twilio.com/conversations
To use the library you need to generate a token and pass it to the Conversations Client constructor.
npm install --save @twilio/conversations
Using this method, you can require
twilio-conversations
and then use the
client:
const { Client } = require('@twilio/conversations');
const client = new Client(token);
// Before you use the client, subscribe to the `'initialized'` event.
client.on('initialized', () => {
// Use the client.
});
// To catch client initialization errors, subscribe to the `'initFailed'` event.
client.on('initFailed', ({ error }) => {
// Handle the error.
});
The SDK could also be imported using the ES module syntax:
import { Client } from '@twilio/conversations';
const client = new Client(token);
// Before you use the client, subscribe to the `'initialized'` event.
client.on('initialized', () => {
// Use the client.
});
// To catch client initialization errors, subscribe to the `'initFailed'` event.
client.on('initFailed', ({ error }) => {
// Handle the error.
});
Releases of twilio-conversations.js
are hosted on a CDN, and you can include these
directly in your web app using a <script>
tag.
<script src="https://media.twiliocdn.com/sdk/js/conversations/v2.3/twilio-conversations.min.js"></script>
Using this method, twilio-conversations.js
will set a browser global Twilio.Conversations
through which you can use the client:
const client = new Twilio.Conversations.Client(token);
The CDN consumption described above allows you to consume latest bug fixed versions automatically, but does not prevent from detecting malicious modifications in the SDK code.
If you require more security you will have to consume SDK by using SRI and using an exact version number. While less flexible it is significantly more secure, which is required by some applications.
To consume securely use the following script snippet format:
<script src="https://media.twiliocdn.com/sdk/js/conversations/releases/2.3.0/twilio-conversations.min.js"
integrity="sha256-<HASH FROM THE CHANGELOGS PAGE>"
crossorigin="anonymous"></script>
Find the hash of each release published on the Changelog page.
See this link.
A union of possible data types in rich content templates.
A union of possible actions used in ContentDataCallToAction and ContentDataCard.
Used for unknown action types which aren't present in the current version of the Conversations SDK.
Full data as a stringified JSON. This could be used for future content types and fields which are not yet supported by the newest version of the Conversations SDK, or for using newer types in the older versions of the SDK.
The type discriminant.
Shows a button that calls a phone number.
Phone number to call when the recipient taps the button.
Full data as a stringified JSON. This could be used for future content types and fields which are not yet supported by the newest version of the Conversations SDK, or for using newer types in the older versions of the SDK.
Display value for the action.
The type discriminant.
Shows a button that sends back a predefined text.
Postback payload. This field is not visible to the end user.
Index for the action.
Full data as a stringified JSON. This could be used for future content types and fields which are not yet supported by the newest version of the Conversations SDK, or for using newer types in the older versions of the SDK.
Display value for the action. This is the message that will be sent back when the user taps on the button.
The type discriminant.
Shows a button that redirects recipient to a predefined URL.
Full data as a stringified JSON. This could be used for future content types and fields which are not yet supported by the newest version of the Conversations SDK, or for using newer types in the older versions of the SDK.
Display value for the action.
The type discriminant.
URL to direct to when the recipient taps the button.
Buttons that let recipients tap to trigger actions such as launching a website or making a phone call. Represents the twilio/call-to-action content type.
Buttons that recipients can tap on to act on the message.
The text of the message you want to send. This is included as a regular text message.
Full data as a stringified JSON. This could be used for future content types and fields which are not yet supported by the newest version of the Conversations SDK, or for using newer types in the older versions of the SDK.
The type discriminant.
Shows a menu of up to 10 options, which offers a simple way for users to make a selection. Represents the twilio/card content type.
Buttons that the recipients can tap on to act on the message.
URLs of the media to send with the message.
Full data as a stringified JSON. This could be used for future content types and fields which are not yet supported by the newest version of the Conversations SDK, or for using newer types in the older versions of the SDK.
Subtitle of the card.
Title of the card.
The type discriminant.
Represents an item in the ContentDataListPicker.
Description of the item.
Unique item identifier. Not visible to the recipient.
Display value of the item.
Shows a menu of up to 10 options, which offers a simple way for users to make a selection. Represents the twilio/list-picker content type.
The text of the message you want to send. This is rendered as the body of the message.
Display value of the primary button.
List item objects displayed in the list. See ContentDataListItem.
Full data as a stringified JSON. This could be used for future content types and fields which are not yet supported by the newest version of the Conversations SDK, or for using newer types in the older versions of the SDK.
The type discriminant.
Contains a location pin and an optional label, which can be used to enhance delivery notifications or connect recipients to physical experiences you offer. Represents the twilio/location content type.
The label to be displayed to the end user alongside the location pin.
The latitude value of the location pin you want to send.
The longitude value of the location pin you want to send.
Full data as a stringified JSON. This could be used for future content types and fields which are not yet supported by the newest version of the Conversations SDK, or for using newer types in the older versions of the SDK.
The type discriminant.
Used to send file attachments, or to send long texts via MMS in the US and Canada. Represents the twilio/media content type.
The text of the message you want to send.
URLs of the media you want to send.
Full data as a stringified JSON. This could be used for future content types and fields which are not yet supported by the newest version of the Conversations SDK, or for using newer types in the older versions of the SDK.
The type discriminant.
Used for unknown content types which aren't present in the current version of the Conversations SDK.
Full data as a stringified JSON. This could be used for future content types and fields which are not yet supported by the newest version of the Conversations SDK, or for using newer types in the older versions of the SDK.
The type discriminant.
Let recipients tap, rather than type, to respond to the message. Represents the twilio/quick-reply content type.
The text of the message you want to send. This is included as a regular text message.
Full data as a stringified JSON. This could be used for future content types and fields which are not yet supported by the newest version of the Conversations SDK, or for using newer types in the older versions of the SDK.
Up to 3 buttons can be created for quick reply. See ContentDataReply.
The type discriminant.
Shows a button that sends back a predefined text. Used in ContentDataQuickReply.
Postback payload. This field is not visible to the end user.
Display value of the action. This is the message that will be sent back when the user taps on the button.
Contains only the plain text-based content. Represents the twilio/text content type.
The text of the message you want to send.
Full data as a stringified JSON. This could be used for future content types and fields which are not yet supported by the newest version of the Conversations SDK, or for using newer types in the older versions of the SDK.
The type discriminant.
Status of the conversation, relative to the client: whether the conversation
has been joined
or the client is notParticipating
in the conversation.
Reason for the updated
event emission by a conversation.
Signifies the amount of participants which have the status for the message.
Message delivery status.
Represents a JSON array.
Represents a JSON object.
Represents a JSON value.
Category of media. Possible values are as follows:
'media'
'body'
'history'
Type of a message.
The reason for the updated
event being emitted by a message.
User's notification level for the conversation. Determines
whether the currently logged-in user will receive pushes for events
in this conversation. Can be either muted
or default
, where
default
defers to the global service push configuration.
Notifications channel type. Possible values are as follows:
'fcm'
'apn'
Email participation level. to = to/from cc = cc
Type of a participant.
The reason for the updated
event being emitted by a participant.
State of the client. Possible values are as follows:
'failed'
- the client failed to initialize'initialized'
- the client successfully initializedThe reason for the updated
event being emitted by a user.
Connection state of the client. Possible values are as follows:
'connecting'
- client is offline and connection attempt is in process'connected'
- client is online and ready'disconnecting'
- client is going offline as disconnection is in process'disconnected'
- client is offline and no connection attempt is in process'denied'
- client connection is denied because of invalid JWT access token. User must refresh token in order to proceed