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 `'stateChanged'` event and wait
// for the `'initialized'` state to be reported.
client.on('stateChanged', (state) => {
if (state === 'initialized') {
// Use the client
}
}
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 `'stateChanged'` event and wait
// for the `'initialized'` state to be reported.
client.on('stateChanged', (state) => {
if (state === 'initialized') {
// Use the client
}
}
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.0/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.0.1/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 | 94 |
Firefox for Android | 92 |
UC Browser for Android | 12.12 |
Chrome | 94, 93, 92 |
Edge | 94, 93, 92 |
Firefox | 93, 92, 91 |
Internet Explorer | 11 |
Safari for iOS | 15, 14.5-14.8 |
Safari | 15, 14.1, 14 |
Samsung Internet | 15.0, 14.0 |
See this link.
The status of the conversation, relative to the client: whether
the conversation has been joined
or the client is
notParticipating
in the conversation.
The reason for the updated
event being emitted 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.
The 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.
Push notification type.
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