我有一个即时消息传递Web应用程序,该应用程序使用twilio可编程聊天功能,并且会员订购了n个私人频道。我正在使用twilio chat javascript library。如何实时显示所有这些渠道的消息?
我有连接和频道列表
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)
}
})
});
答案 0 :(得分:1)
在聊天客户端对象上使用“ 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)
})
});