简体   繁体   中英

Is there a way to add private channels to twilio programmable chat?

I am trying to build a web app using c# and .net core framework using mvc format. We are looking to add an in-app chat feature and decided to go with Twilio's programmable chat product. We've been going through Twilio's documentation and came across this .net core starter app containing the groundwork for our chat feature (using the link below). It seems to be working fine but we are writing to the general channel where my colleague and I are unable to see each others' messages from separate devices. I am able to message myself in separate tabs but we aren't able to message each other from different devices running the same credentials.

Our goal is to set up a private chat between two users (eg Pet Owners and Vets) that can successfully communicate across that channel. The code below is pulled from the linked repo. It's creating a general channel but we are looking for a way to create a private channel to accommodate multiple users.

Is there any specific functions or methods on the backend to set up a private channel? Or is it all via the client side?

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

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