0

Using the SendBird JavaScript SDK, I am able to correctly create a private group for 1-to-1 messaging:

var params = new sb.GroupChannelParams();
params.isPublic = false;
params.isEphemeral = false;
params.isDistinct = true;
params.addUserIds([1, 2]);
params.operatorIds = [1];
params.name = name;

sb.GroupChannel.createChannel(params, function(groupChannel, error) {
    if (error) {
        console.log(error);
        return false;
    }

    sb.GroupChannel.getChannel(groupChannel.url, function(groupChannel) {
        var userIds = [2];

        groupChannel.inviteWithUserIds(userIds, function(response, error) {
            if (error) {
                console.log(error);
                return false;
            }

            console.log(response);
        });
    });
});

This all works correctly, and both users are able to see the private chatroom when retrieving the group list. However, when either user attempts to join the private group, an error is encountered:

SendBirdException: Not authorized. "Can't join to non-public channel.".

To join the group, I'm using the following code:

sb.GroupChannel.getChannel(id, function(openChannel, error) {
    if (error) {
        console.log(error);
        return false;
    }

    console.log('Channel Found: ' + openChannel.name + '. Current Participants: ' + openChannel.participantCount);

    openChannel.join(function(response, error) {
        if (error) {
            console.log(error);
            return false;
        }

        console.log('Channel Joined: ' + openChannel.name + '. Current Participants: ' + openChannel.participantCount);

        // retrieving previous messages.
    });
});

The response from the above code is:

{
    "message": "Not authorized. \"Can't join to non-public channel.\".",
    "code": 400108,
    "error": true
}

Any help is much appreciated. Note, I've checked the documentation and it does not mention how to join a private group (only a public one). I don't see how the "creator" of the chatroom is able to join the room, despite being set as the "operator".

Niraj Shah
  • 15,087
  • 3
  • 41
  • 60

1 Answers1

0

It seems like you are trying to join the open channel while it is actually a group channel. You can join the group channel as a member by calling this method call.

if (groupChannel.isPublic) {
groupChannel.join(function(response, error) {
    if (error) {
        return;
    }
});

}

Instead of

openChannel.join(function(response, error) {
    if (error) {
        console.log(error);
        return false;
    }

    console.log('Channel Joined: ' + openChannel.name + '. Current Participants: ' + openChannel.participantCount);

    // retrieving previous messages.
});

https://docs.sendbird.com/javascript/group_channel#3_join_a_channel_as_a_member

erickimme
  • 323
  • 1
  • 4
  • 11
  • The `openChannel` is just a variable. You will notice that I'm using the `sb.GroupChannel` in the main function. The channel is not public, which was mentioned in my code too: `params.isPublic = false;`. – Niraj Shah Mar 20 '20 at 09:54
  • Hi @NirajShah, Can you set the isPublic as true to see if your user can join. As name represents, group channel is mostly used for private group channel where people join as a member by invitation. If you set isPublic's value to true, people can join the public group channel without invitation. Please find the description that is stated in our documentation "This is only for public group channels. Any user can join a public group channel as a member without an invitation and chat with other members in the channel" – erickimme Mar 21 '20 at 23:49
  • Yes, setting `isPublic = true` lets me create a room and join it no problem. However, I am specifically looking to create a private group channel between two users, that no one else can join (unless invited). – Niraj Shah Mar 23 '20 at 01:34