'Private Messaging with Twilio IP Messaging

Communication in Twilio IP Messaging is based on channels. I mastered authentication, I implemented communication via public channels, and now I want to implement private communication between two users, how should I approach it? I think that I have to create a private channel

messagingClient.createChannel({
    uniqueName: 'secret',
    friendlyName: 'Private Chat Channel',
    isPrivate: true
}).then(function(channel) {
    console.log('Created private channel:');
    console.log(channel);
});

Private channel means that it's just hidden from others, but how to forcefully restrict users from joining the channel making it more secure?



Solution 1:[1]

Twilio developer evangelist here.

Firstly, according to the latest documentation, if you want to set the channel to be private you need to do so by setting its Type to private.

messagingClient.createChannel({
    uniqueName: 'secret',
    friendlyName: 'Private Chat Channel',
    type: 'private'
}).then(function(channel) {
    console.log('Created private channel:');
    console.log(channel);
});

Then, when you have made a channel private, other users are only able to join that channel by invitation. That is a restriction that is controlled within the API, so as long as you have set the channel to be private, you do not need to worry about the rest of it.

Let me know if this helps.

Solution 2:[2]

Make sure you change isPrivate: true
to type: 'private'

Also you could have authenticator functions, like, if (user.username === 'donald'){ } etc.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 philnash
Solution 2 Evan Erickson