3

I am developing a 1:1 chat application. I use a PHP server to create the private channel before starting the application. The channels are created correctly.

The user tokens are genereated, chat client also created correctly. I see that the user is also created in the service.

When joining the private channel, it throws the error.

code:50400 message:"User not member of channel" status:403

Javascript code:

    Twilio.Chat.Client.create(token,clientOptions).then(client => {
        chatClient = client;
        showMessage('Connecting.....');             
        chatClient.getChannelBySid(channelid)
        .then(function(chosenChannel) {
            showMessage('Joining Chat.....'); 
            myChannel=chosenChannel;                
            joinChannel();
        })
        .catch(function(err) {
            console.log(err);
        })
    }); 

It shows the message 'Connecting....' and then stops with the error.

PHP Code:

$client = new Client("sid", "token");       

$channel = $client->chat->services("serviceid")->channels
           ->create(array('friendlyName' => $friendlyName, 'uniqueName' => $uniqueName, 'type' => 'private'));
arun kumar
  • 703
  • 2
  • 13
  • 33

1 Answers1

5

Twilio developer evangelist here.

When you create a private channel there's no way to define at that stage who is allowed to enter the channel. From the documentation:

Private Channels are not visible to Users that have not been invited or added to them. Private Channel Members can only be added by other Members with sufficient permissions, or via the REST API as controlled by your business logic.

So, in order for a user to join a private channel you need to either:

Let me know if that makes sense at all

philnash
  • 70,667
  • 10
  • 60
  • 88