首页 > 解决方案 > 有没有办法将私人频道添加到 twilio 可编程聊天中?

问题描述

我正在尝试使用 c# 和使用 mvc 格式的 .net 核心框架构建一个 Web 应用程序。我们正在寻求添加应用内聊天功能,并决定使用 Twilio 的可编程聊天产品。我们一直在浏览 Twilio 的文档,发现了这个 .net 核心入门应用程序,其中包含我们聊天功能的基础(使用下面的链接)。它似乎工作正常,但我们正在写信给我的同事和我无法从不同设备看到彼此的消息的通用频道。我可以在单独的选项卡中向自己发送消息,但我们无法从运行相同凭据的不同设备相互发送消息。

我们的目标是在两个用户(例如宠物主人和兽医)之间建立一个可以通过该渠道成功沟通的私人聊天。下面的代码是从链接的仓库中提取的。它正在创建一个通用频道,但我们正在寻找一种方法来创建一个私人频道以容纳多个用户。

后台有什么具体的功能或者方法可以设置私频道吗?还是全部通过客户端?

https://github.com/TwilioDevEd/sdk-starter-csharp

function createOrJoinGeneralChannel() {
    // Get the general chat channel, which is where all the messages are
    // sent in this simple application
    print('Attempting to join "general" chat channel...');
    chatClient.getChannelByUniqueName('general')
        .then(function (channel) {
            generalChannel = channel;
            console.log('Found general channel:');
            console.log(generalChannel);
            setupChannel();
        }).catch(function () {
            // If it doesn't exist, let's create it
            console.log('Creating general channel');
            chatClient.createChannel({
                uniqueName: 'general',
                friendlyName: 'General Chat Channel'
            }).then(function (channel) {
                console.log('Created general channel:');
                console.log(channel);
                generalChannel = channel;
                setupChannel();
            }).catch(function (channel) {
                console.log('Channel could not be created:');
                console.log(channel);
            });
        });
}

// Set up channel after it has been found
function setupChannel() {
    // Join the general channel
    generalChannel.join().then(function (channel) {
        print('Joined channel as '
            + '<span class="me">' + username + '</span>.', true);
    });

    // Listen for new messages sent to the channel
    generalChannel.on('messageAdded', function (message) {
        printMessage(message.author, message.body);
    });
}

标签: javascriptc#asp.net-coretwiliotwilio-programmable-chat

解决方案



推荐阅读