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.2/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.2.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.
Browser | Supported Versions |
---|---|
Chrome for Android | 104 |
Firefox for Android | 101 |
UC Browser for Android | 12.12 |
Chrome | 104, 103, 102 |
Edge | 104, 103, 102 |
Firefox | 103, 102, 101 |
Internet Explorer | 11 |
Safari for iOS | 15.6, 15.5 |
Safari | 15.6, 15.5, 15.4 |
Samsung Internet | 18.0, 17.0 |
See this link.
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