node.js - Twilio 可编程聊天 getChannelByUniqueName 引发“禁止”错误
问题描述
在我的后端服务中创建一个频道后,我试图在我的反应前端中加入这个频道,像这样的 useEffect 钩子:
const initChat = async () => {
const chatClient = await Client.create(props.token);
const channel = await chatClient.getChannelByUniqueName(props.room);
if (channel) {
if (channel.status !== "joined") {
chatClient.on("channelJoined", () => {
registerChannelListeners(channel);
});
await channel.join();
} else {
registerChannelListeners(channel);
}
setChannel(channel);
setMessages((await channel?.getMessages()).items);
}
};
}
最初导航到页面时,错误
upstream.js?a850:136 Uncaught (in promise) Error: Forbidden
at Upstream.actualSend (upstream.js?a850:136)
偶尔被抛出。
重新加载页面时,一切正常。
有问题的行似乎是:
const channel = await chatClient.getChannelByUniqueName(props.room);
因为没有进一步的代码被执行。token
并且room
都分配有有效值。
在解码的套接字消息中,此错误消息是从 twilio 发送的:
{"method":"reply"...,"http_status":{"code":403,"status":"Forbidden"}}
{"status":403,"message":"User not member of channel","code":50400}
尽管两个参与者都是通过后端通过此功能邀请的:
inviteParticipantToChannel(participant: Participant, channelSid: string) {
this.logger.log(
`Inviting paricipant ${participant.getIdentifier()} to channel ${channelSid}`,
);
return this.twilioClient.chat
.services(process.env.TWILIO_CHAT_SERVICE_ID)
.channels(channelSid)
.invites.create({ identity: participant.getIdentifier() });
}
为了让参与者能够找到/加入频道,我还需要做更多的事情吗?
解决方案
您是否尝试过设置短暂的超时?twilio 的频道资源可能需要一些时间。
推荐阅读
- r - 为什么函数和条件语句会给出错误的输出?
- oracle - 在 oracle apex 中动态设置 pl/sql 代码
- mongodb - MongoDB:无法解析 $convert 中的 objectId '',没有 onError 值:解析为 OID 的字符串长度无效,预期为 24,但发现为 0
- c# - 通过鼠标单击跳转到选定的对象
- bash - 如何在 Slurm 中使用用户输入
- python - 如何根据 2 个数据框之间的通用列表元素分配列值
- google-bigquery - 语法错误:应为“)”,但在 [62:23] 获得标识符“ciclos”
- c++ - 将 NORMAL 添加到 inputLayout 时出错
- task - 工作流无法启动,因为没有在工作流任务列表中插入记录
- reactjs - 如何使用 ansbile 为 nginx 构建 reactjs 文件,然后将这些文件同步到 ansible 库存?