简体   繁体   中英

How to listen for new message from multiple channels in Twilio programmable chat?

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)
        }
    })
});

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)
    })
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM