我想在客户端使用Web聊天控件在现有Web应用程序中托管或嵌入Azure Web Chat bot。用户必须首先登录Web应用程序才能在Web应用程序中使用Web聊天机器人功能。
如果我的用户已经登录到我的Web应用程序,我可以使用什么机制将该用户传递给Web聊天控件JavaScript?
我正在查看示例here,嵌入网络聊天的源代码如下所示:
<!DOCTYPE html>
<html>
<body>
<div id="webchat" role="main"></div>
<script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
<script>
window.WebChat.renderWebChat({
directLine: window.WebChat.createDirectLine({ token: 'YOUR_DIRECT_LINE_TOKEN' }),
userID: 'YOUR_USER_ID',
username: 'Web Chat User',
locale: 'en-US',
botAvatarInitials: 'WC',
userAvatarInitials: 'WW'
}, document.getElementById('webchat'));
</script>
</body>
</html>
这是否意味着我必须生成或获取登录的用户ID和名称,并将其传递给Web应用程序上每个新用户会话的用户名和用户ID?
根据文档,userID,username,locale,botAvatarInitials和userAvatarInitials都是传递给renderWebChat方法的可选参数。
如果未指定userID,则默认为随机用户ID。不建议多个用户共享相同的用户ID;他们的用户状态将被共享。
在这个thread讨论了类似的问题。
另外请检查这个documentation,使用C#和JS通过bot服务为你的机器人使用身份验证。