重新启动漫游器后,主动消息在MS Teams中不起作用 [英] Proactive message not working in MS Teams after bot is restarted

查看:56
本文介绍了重新启动漫游器后,主动消息在MS Teams中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主动消息传递终结点,当用户积极参与对话时,该终结点可以正常工作.例如,在一个用例中,用户要求检索发票数据,该数据是异步发生的,并通过主动消息发送回去.这很好.但是,如果尝试在几周后继续进行对话,则 continueConversation 操作将失败.如果我进入团队并与机器人发起新的对话,那么重新发送主动消息(不进行任何更改)将再次起作用.

I have a proactive messaging endpoint that works fine when a user is actively engaged in a conversation. For example, one use case where user asks for invoice data to be retrieved, which happens asynchronously and is sent back via proactive message. This works fine. But if a try to continue a conversation weeks later, the continueConversation action is failing. If I go into teams and initiate a new conversation with the bot, then resending the proactive message (without changing anything) works again.

在我的一个使用案例中,该机器人需要在未来1周内与用户进行跟进.因此,我需要弄清楚如何向团队用户发送主动消息,即使他们最近没有与机器人聊天.我不确定为什么 continueConversation 不能正常工作,因为对话ID不变(而且几个月内也没有变化,也许从未改变).

In one of my use cases, the bot needs to follow up with the user 1+ weeks in the future. So I need to figure out how to send a proactive message to a teams user even if they haven't recently conversed with the bot. I'm not sure why continueConversation isn't working because the conversation ID doesn't change (and hasn't changed in months, probably not ever).

这是我用来发送主动消息的功能.

Here is the function I am using to send the proactive message.

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();
    }
});

推荐答案

使用我自己的代码中的链接说,

As the link in my own code says,

如果您的漫游器已重新启动,则等待主动消息的用户将无法接收它,除非他们在重新启动后再次向该漫游器发送了消息.

If your bot is restarted, a user awaiting a proactive message cannot receive it unless they have messaged the bot again after it restarted.

这就是问题所在.但是该页面上的说明未提供完整的详细信息.您必须通过 const {MicrosoftAppCredentials} = require('botframework-connector')添加类,并将serviceUrl设置为通过(在 conversationReference.serviceUrl ).

So that was exactly what the issue was. But the instructions on that page aren't giving the full details. You have to add the class via const { MicrosoftAppCredentials } = require('botframework-connector') as well as set the serviceUrl to pass (which is already available at conversationReference.serviceUrl).

因此,通过这些更改,我添加了 MicrosoftAppCredentials.trustServiceUrl(conversationReference.serviceUrl); ,然后再发送主动消息,即使重新启动bot,它也能正常工作.

So with these changes I added MicrosoftAppCredentials.trustServiceUrl(conversationReference.serviceUrl); before I send the proactive message and it started working fine even after bot was restarted.

这篇关于重新启动漫游器后,主动消息在MS Teams中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆