Reputation: 3825
I am trying to make a Chat application which uses direct messaging between two users using Twilio Programmable Chat API. I am using the JS SDK. My problem is that I am not able to understand how to assign a channel name for Direct Messaging between two people so that at either end the person is aware of the channel association. I am not able to understand how to maintain the channel names so that I don't encounter a situation where I have n! channels, an association of 1 to many. Please help.
I am using the code below for the private channels.
// Create a Channel
messagingClient.createChannel({
uniqueName: 'general',
friendlyName: 'General Chat Channel',
isPrivate: true
}).then(function(channel) {
console.log('Created general channel:');
console.log(channel);
});
Upvotes: 2
Views: 471
Reputation: 73057
Twilio developer evangelist here.
If you are looking for a way to uniquely name the private channels between two users, then why not concatenate the identity's of the two users in your system.
Imagining that you are trying to create a channel for userA
and userB
and they both have an id
. Then create the unique channel name by sorting the ids and concatenating:
function generateChannelName(userA, userB) {
return [userA.id, userB.id].sort().join('-');
}
That way the channel name between two users will always be calculable and unique.
Let me know if that helps at all.
Upvotes: 4