【发布时间】:2020-09-07 17:40:58
【问题描述】:
如果我的令牌已过期,我想重新连接到 WebChat 中的旧机器人对话,如果网络连接丢失或其他情况可能会发生这种情况。
我基本上是这样使用网络聊天的:
directline = window.WebChat.createDirectLine({ token: token });
window.WebChat.renderWebChat({
directLine: directline
}, document.getElementById('webchat'));
我生成的令牌
cres = await fetch('https://directline.botframework.com/v3/directline/tokens/generate', {
body: JSON.stringify({ User: { Id: userID }, TrustedOrigins: [origin] }),
headers: {
authorization: `Bearer ${process.env.DIRECT_LINE_SECRET}`,
'Content-Type': 'application/json'
},
method: 'POST'
});
根据https://github.com/microsoft/BotFramework-WebChat/blob/master/docs/API.md
createDirectLine 采用 conversationId 参数,所以我尝试传递旧的对话 ID
directline = window.WebChat.createDirectLine({ token: token, conversationId: oldConvId });
为同一用户 ID 新生成的令牌。但随后renderWebChat 因令牌无效而失败,因为新令牌还获得了一个新的conversationId,它与directLine 调用中请求的不匹配。我怎么解决这个问题?要么以完全不同的方式重新连接,要么为给定的userId 和conversationId 生成一个新令牌。我在 v3/directline/token/generate API 中找不到任何东西来为给定的 conversationId 请求令牌。
【问题讨论】:
-
接受/赞成一个答案服务于更大的 Stack Overflow 社区和任何有类似问题的人。如果您觉得我的回答足够,请“接受”并点赞。如果没有,请告诉我我还能提供哪些帮助!
标签: node.js botframework web-chat