[英]Twilio Chat - Joining a user to a channel with identity and friendlyName
How do i create a user and join that user into a channel with a friendly name?如何创建用户并将该用户加入一个友好名称的频道?
All the examples in the documentation located here assumes that a user with appropriate friendlyName is already present in the service instance.位于此处的文档中的所有示例都假定具有适当friendlyName 的用户已经存在于服务实例中。
So, if i want to join a user in my system to a channel, Do i need to first create a user using users rest api endpoint and then add that user as a member of a channel?因此,如果我想将系统中的用户加入频道,我是否需要先使用用户 rest api 端点创建用户,然后将该用户添加为频道的成员?
channel.members.create(user.identity)
Above code above throws 409 conflict error if i re-create a user.如果我重新创建用户,上面的代码会引发 409 冲突错误。 So i am forced to fetch a user, see if the user exists then create the user.
所以我被迫获取用户,查看用户是否存在然后创建用户。 If user already exists, then I have to update the user with friendlyName.
如果用户已经存在,那么我必须使用friendlyName 更新用户。
I am forced to check if the user in my system exists in that service instance everytime that user joins a channel.每次用户加入频道时,我都被迫检查我系统中的用户是否存在于该服务实例中。
Is there a way I can join a user to a channel with friendly name so Twilio creates if the user doesn't exist and update friendly name if user already is in twilio service instance?有没有办法可以将用户加入具有友好名称的频道,以便 Twilio 在用户不存在时创建,如果用户已经在 twilio 服务实例中,则更新友好名称?
This is the sequence of events I would like to see:这是我希望看到的事件序列:
2022 answer: 2022年答案:
const participant = await conversation.getParticipantByIdentity(userIdentity);
if (!participant) {
await conversation.join();
}
And yes, yon need to use Conversation API.是的,你需要使用对话 API。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.