Class: Webchat
The Webchat Class allows you to inject Flex 1.X Webchat into your website or application
Throughout this page, you will see
webchatClient
with a lowercase "w" andWebchat
with an uppercase "W".
Webchat
refers to theWebchat
object provided by the SDK.
webchatClient
represents an instance of aWebchat
, created with thenew
keyword:
Instantiate a Webchat Client
A new instance of Webchat
should be constructed by using the new keyword and passing the Config payload as the first argument.
Initiate a Basic Webchat Client
const webchat = new Webchat({
accountSid: "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
flowSid: "FOXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
});
To see all of the possible properties, see the Config interface section.
Hierarchy
EventEmitter
↳
Webchat
Accessors
client
• get
client(): FlexWebChat
Returns the underlaying Twilio SDK FlexWebchat
for advanced configuration and usage
//Posting question from preengagement form as users first chat message
webchatClient.client.Actions.on("afterStartEngagement", (payload) => {
const { question } = payload.formData;
if (!question)
return;
const { channelSid } = webchatClient.client.manager.store.getState().flex.session;
webchatClient.client.manager
.chatClient.getChannelBySid(channelSid)
.then(channel => channel.sendMessage(question));
});
Returns
FlexWebChat
isSupported
• get
isSupported(): boolean
Returns if Webchat is Supported in the current Browser / Context
console.info(webchatClient.isSupported)
Returns
boolean
ready
• get
ready(): boolean
Is the webchatClient
ready?
webchatClient.ready ? console.info("Ready") ? console.info("Not Ready")
Returns
boolean
Methods
init
▸ init(): Promise
<void
>
Init the Webchat Client
Should only be used if the
Webchat
is destroyed and a "re-init" is required for some bizare reason
await webchatClient.init();
Returns
Promise
<void
>