1

Is there any listener to check the Twilio chat channel update? I need to check is the chat channel active or inactive in customer web chat. Based on the status I will show/hide some components. Sometimes I need to inactive a chat channel using REST API. How can I detect these changes in the customer web chat panel?

Client-side is developed by ReactJS. Thanks in advance.

1 Answers1

0

Looks like there could be two ways to do this:

1. Use Twilio webhooks:

https://www.twilio.com/docs/chat/webhook-events

You'll need to register the webhook in your chat channel for the event you want to listen to and tell it what endpoint to send the request to, then you can handle the request in your server's REST API. This lets you send all updates directly to your server straight form Twilio

Alternatively,

2. Use a ChannelListener in your javascript

New message in the channel:

// Listen for new messages sent to a channel
myChannel.on('messageAdded', function(message) {
  console.log(message.author, message.body);
});

Channel updated:

// A channel's attributes or metadata have changed.
chatClient.on('channelUpdated', function(channel) {
  console.log('Channel updates: ' + channel.sid);
});
R10t--
  • 803
  • 7
  • 16
  • Hi @R10t--, it's not working in my end. Can you suggest me is there any listener in FlexWebChat to check channel status. I found `handleChannelUpdated` in ChatListener. But I don't know how to use this. Do you have any idea? – Md Sadequr Rahman Nov 01 '19 at 19:51
  • I looked at the flex [WebChat api](https://www.twilio.com/docs/flex/installing-and-using-flex-webchat) and you should be able to do this: `Twilio.FlexWebChat.createWebChat(appConfig).then(webchat => { const { manager } = webchat; manager.on('channelUpdated', function(channel) { console.log('Channel updates: ' + channel.sid); }); ` – R10t-- Nov 01 '19 at 20:30
  • Thanks @R10t--, I am using FlexWebChat.MessagingCanvas.Content.add(); How can I add a listener to that component? – Md Sadequr Rahman Nov 01 '19 at 20:50
  • how to detach these event listeners? – Masroor Nov 18 '20 at 11:40