3

I have an instant messaging web application using twilio programmable chat with 'n' number of private channels subscribed by a member. I am using twilio chat javascript library. How can I show messages from all these channels in real time?

I have the connection and channels list

Twilio.Client.create(token).then(client => {
    this.chatClient = client
    this.chatClient.getSubscribedChannels().then(function (paginator) {
        for (var i = 0; i < paginator.items.length; i++) {
            const channel = paginator.items[i]
            console.log('Channel: ' + channel.friendlyName)
        }
    })
});
LJP
  • 1,811
  • 4
  • 23
  • 34

1 Answers1

4

Use 'mesageAdded' event on the chat client object

Twilio.Client.create(token).then(client => {
    this.chatClient = client
    this.chatClient.getSubscribedChannels().then(function (paginator) {
        console.log(paginator.items)
    })

    this.chatClient.on('messageAdded', function (message) {
        console.log(message)
    })
});
LJP
  • 1,811
  • 4
  • 23
  • 34
  • 2
    Is there a way to do this only for one active channel? – Mohit Jan 04 '20 at 01:18
  • @Mohit If you haven't already found the solution, I posted an anwer [here](https://stackoverflow.com/questions/60175918/how-to-listen-for-messages-on-a-single-channel-in-twilio-programmable-chat/60175919#60175919) on how to do this for a single channel – That1Guy Feb 11 '20 at 19:22