Twilio Chat is a service for messages delivery over ip networks. Visit our official site for more detalis: https://www.twilio.com/chat
To use the library you need to generate a token and pass it to the Chat Client constructor.
npm install --save twilio-chat
Using this method, you can require
twilio-chat
and then use the client:
const { Client } = require('twilio-chat');
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-chat';
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-chat.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/chat/v6.0/twilio-chat.min.js"></script>
Using this method, twilio-chat.js
will set a browser global Twilio.Chat
through which you can use the client:
const client = new Twilio.Chat.Client(token);
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.
Channel sorting order.
The conversational state of the channel.
The current state.
Date at which the latest channel state update happened.
The status of the channel, relative to the client: whether
the channel has been joined
or the client is
notParticipating
in the channel or has been invited
to
the channel.
Channel type.
The reason for the updated
event being emitted by a channel.
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 proceedPush notification type of a member.
The reason for the updated
event being emitted by a member.
Push notification type of a message.
The reason for the updated
event being emitted by a message.
The user's notification level for the channel. Determines
whether the currently logged-in user will receive pushes for events
in this channel. 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'
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.
Channel sorting criteria.