Private/direct messages between users and group chat

How to send private or direct messages between users in channels and how to set up authentication for a group chat

In order to send "private" or direct messages between two or more users in a channel, this would be managed by restricting who can access that channel via token authentication.

Token permissions can be set to limit access to the channel for the required users, by setting your auth server to only allow permissions on a channel to certain client IDs as specified in this article.

Example:

Say you have the letters of the alphabet as client Ids, you can set up a channel and only allow 'a' and 'b' to publish and subscribe by giving their tokens the relevant permissions.  Any other client Ids would not have permissions for that channel and therefore could not 'publish', 'subscribe' or anything else like enter presence unless you update their permissions. Therefore, this acts as a private channel between 'a' and 'b'.

Following the above scenario, below is an example of permissions for different users in several channels called ‘private_chat_ab’, 'group_chat',  and 'alerts'.

 

Private chat between two users:

ClientID 'a' has the following permissions:

{

  "private_chat_ab": ["publish", "subscribe", "presence"],

  "group_chat": ["publish", "subscribe", "history"],

  "alerts": ["subscribe"]

}

ClientID 'b' has the following permissions:

{

  "private_chat_ab": ["publish", "subscribe", "presence"],

  "group_chat": ["publish", "subscribe", "history"],

  "alerts": ["subscribe"]

}

 

Group chat:

ClientID 'a' has the following permissions:

{

  "private_chat_ab": ["publish", "subscribe", "presence"],

  "group_chat": ["publish", "subscribe", "history"],

  "alerts": ["subscribe"]

}

ClientID 'b' has the following permissions:

{

  "private_chat_ab": ["publish", "subscribe", "presence"],

  "group_chat": ["publish", "subscribe", "history"],

  "alerts": ["subscribe"]

}

 

ClientID 'c' has the following permissions:

{

  "group_chat": ["publish", "subscribe", "history"],

  "alerts": ["subscribe"]

}

 

ClientID 'd' has the following permissions:

{

  "group_chat": ["publish", "subscribe", "history"],

  "alerts": ["subscribe"]

}

 

* This means that clients 'a', 'b', 'c' and 'd' would all have permissions to publish and subscribe in the group_chat channel, but only certain users ('a' and 'b') have permissions for the dedicated private_chat_ab channel.

 

For more information on the different permissions that can be assigned to users on a channel and examples, please see here.

You can also find a demo on how to implement token authentication and how to assign permissions via this link.

 

For further details on authentication, please see this guide