0

I am trying to send media messages in programmable chat on Twilio. But as per the docs, only Channel admin and Channel user roles can send media messages. When I create my chatClient, it automatically assigns them with Service admin and Service User role. How can I join the channel as a channel admin or channel user so that i can send media messages.

Below is the code I am using for creating chat client and joining the channel:

 initChat = () => {
    this.chatClient = new Chat(this.state.token);
    this.chatClient.initialize().then(this.clientInitiated.bind(this));
  };

clientInitiated = () => {
    this.setState({ chatReady: true }, () => {
      this.chatClient
        .getChannelByUniqueName(this.channelName)
        .then(channel => {
          if (channel) {
            return (this.channel = channel);
          }
        })
        .catch(err => {
          if (err.body.code === 50300) {
            return this.chatClient.createChannel({
              uniqueName: this.channelName
            });
          }
        })
        .then(channel => {
          this.channel = channel;
          window.channel = channel;
          if (channel.state.status !== "joined") {
            console.log("New member joining in");
            return this.channel.join();
          } else {
            console.log("already joined the channel earlier");
            return this.channel;
          }
        })
        .then(() => {
          console.log("Channel: ", this.channel);
          this.channel.getMessages().then(this.messagesLoaded);
          this.channel.on("messageAdded", this.messageAdded);              
        });
    });
  };
Kunal-KP
  • 1
  • 2

1 Answers1

0

Twilio developer evangelist here.

From the documentation:

Roles and Role Scopes

Chat Roles are divided into two "Scopes," Service and Channel. These determine how the Role permissions are applied depending on the context.

  • Service level Roles are assigned to Users and dictate which Channels the User can see, join, and create.
  • Channel level Roles are assigned to Members within a Channel. These roles determine what Members can do within that Channel, such as send Messages, add other Members, edit Messages and more.

So, while your chat client has a service role, your user's member in a channel will have a channel level role like channel admin or channel user and will be able to send media messages.

Check out the docs on roles and permissions and the REST API for roles for more information.

philnash
  • 70,667
  • 10
  • 60
  • 88