[英]Proactive message not working in MS Teams after bot is restarted
我有一个主动消息传递端点,当用户积极参与对话时,它可以正常工作。 例如,用户要求检索发票数据的一个用例是异步发生的,并通过主动消息发回。 这工作正常。 但是,如果尝试在几周后继续对话,则continueConversation
操作将失败。 如果我将 go 加入团队并与机器人开始新的对话,那么重新发送主动消息(不更改任何内容)将再次起作用。
在我的一个用例中,机器人需要在未来 1 周以上跟进用户。 所以我需要弄清楚如何向团队用户发送主动消息,即使他们最近没有与机器人交谈过。 我不确定为什么continueConversation
不起作用,因为对话 ID 没有改变(并且几个月没有改变,可能永远不会改变)。
这是我用来发送主动消息的 function。
server.post('/api/notify', async (req, res) => {
//console.log(req.body);
try {
const conversationReference = req.body.conversationReference;
await adapter.continueConversation(conversationReference, async turnContext => {
// If you encounter permission-related errors when sending this message, see
// https://aka.ms/BotTrustServiceUrl
await turnContext.sendActivity(req.body.message);
});
res.setHeader('Content-Type', 'text/html');
res.writeHead(200);
res.write('<html><body><h1>Proactive messages have been sent.</h1></body></html>');
res.end();
} catch (error) {
console.log('Bad Request. Please ensure your message contains the conversation reference and message text.');
console.log(error);
appInsightsClient.trackTrace({
message: `${error.name} - ${path.basename(__filename)}`,
severity: 4,
properties: {'error':error.message,'callStack':error.stack, 'botName': process.env.botName}
});
res.setHeader('Content-Type', 'text/html');
res.writeHead(400);
res.write('<html><body><p>Bad Request. Please ensure your message contains the conversation reference and message text.</p></body></html>');
res.end();
}
});
正如我自己的代码中的链接所说,
如果您的机器人重新启动,等待主动消息的用户将无法收到它,除非他们在重新启动后再次向该机器人发送消息。
所以这正是问题所在。 但是该页面上的说明并未提供完整的详细信息。 您必须通过const { MicrosoftAppCredentials } = require('botframework-connector')
添加 class 并将 serviceUrl 设置为通过(在conversationReference.serviceUrl
已经可用)。
因此,通过这些更改,我添加了MicrosoftAppCredentials.trustServiceUrl(conversationReference.serviceUrl);
在我发送主动消息之前,即使在机器人重新启动后它也开始正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.