如何在 Twilio 可编程聊天中收听来自多个频道的新消息? [英] How to listen for new message from multiple channels in Twilio programmable chat?

查看:48
本文介绍了如何在 Twilio 可编程聊天中收听来自多个频道的新消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 twilio 可编程聊天的即时消息网络应用程序,其中包含一个成员订阅的n"个私人频道.我正在使用 twilio chat javascript 库.如何实时显示来自所有这些频道的消息?

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?

我有连接和频道列表

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' 事件

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

这篇关于如何在 Twilio 可编程聊天中收听来自多个频道的新消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆