以频道管理员的身份加入Twilio上的可编程聊天中的频道以发送消息中的媒体

时间:2018-10-10 09:25:13

标签: twilio twilio-api twilio-programmable-chat

我正在尝试在Twilio上的可编程聊天中发送媒体消息。但是根据文档,只有 Channel admin Channel user 角色可以发送媒体消息。 当我创建chatClient时,它将自动为他们分配 Service admin Service User 角色。如何以频道管理员或频道用户的身份加入频道,以便我可以发送媒体消息。

以下是我用于创建聊天客户端和加入频道的代码:

 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);              
        });
    });
  };

1 个答案:

答案 0 :(得分:0)

这里是Twilio开发人员的传播者。

来自the documentation

  

角色和角色范围

     

聊天角色分为两个“作用域”,即服务和渠道。这些   确定角色权限的应用方式取决于   上下文。

     
      
  • 服务级别角色已分配给用户,并指示用户可以查看,加入和创建哪些渠道。
  •   
  • 频道级别角色已分配给频道内的成员。这些角色确定成员可以在该频道中执行的操作,例如发送消息,添加其他成员,编辑消息等等。
  •   

因此,当您的聊天客户端具有服务角色时,您用户在频道中的成员将具有频道级别的角色,例如频道管理员或频道用户,并且能够发送媒体消息。

查看docs on roles and permissionsREST API for roles以获得更多信息。

相关问题