我有一个即时消息 Web 应用程序,它使用 twilio 可编程聊天,成员订阅了“n”个私有(private) channel 。我正在使用 twilio chat javascript library .如何实时显示来自所有这些 channel 的消息?
我有连接和 channel 列表
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)
}
})
});
最佳答案
在聊天客户端对象上使用 'mesageAdded' 事件
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)
})
});
关于javascript - 如何在 Twilio 可编程聊天中收听来自多个 channel 的新消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54687896/