我正在尝试在 Twilio 上的可编程聊天中发送媒体消息。但根据文档,只有频道管理员和频道用户角色可以发送媒体消息。当我创建我的聊天客户端时,它会自动为他们分配服务管理员和服务用户角色。如何以频道管理员或频道用户的身份加入频道,以便发送媒体消息。
以下是我用于创建聊天客户端和加入频道的代码:
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);
});
});
};