首页 > 解决方案 > 如何在 MS botframework 中添加/创建其他端点

问题描述

我们正在尝试使用使用 Nodejs 的 MS bot 框架为两个渠道 WebChat 和 Skype for Business 开发一个机器人。我们已经在 Azure 上托管了机器人,并且已经注册了默认端点“/api/messages”。我们现在正在异步进行第三方 API 调用,我们希望创建另一个自定义端点,可以在其中检索回调,然后以某种方式将响应显示给用户。假设有 100 个用户正在与 BOT 交互,因此进行了 100 个异步调用。当回调返回时,我们希望它们返回到这个新端点,然后响应应该以某种方式显示给相应的用户/窗口。我们总共有四个基于用户上下文的不同 API 调用。我将如何实现此功能?

标签: node.jsbotframework

解决方案


首先,关于 Skype for Business,请注意以下几点

Bot Framework 中的 Skype for Business 频道将于 2019 年 6 月 30 日弃用。

在该日期之后,没有新的机器人能够添加 Skype for Business 频道。现有机器人将继续工作到 2019 年 10 月 31 日。Microsoft Teams 是 Microsoft 的首选通信工具。了解如何将您的机器人连接到 Microsoft Teams

话虽如此,如果我正确理解了您的问题,您可以以与“api/messages”端点相同的方式轻松创建其他端点。结帐 BotBuilder-样品编号。16.proactive-messages演示使用第二个端点来发起主动消息。

本质上,您的代码将如下所示:

// Listen for incoming activities and route them to your bot main dialog.
server.post('/api/messages', (req, res) => {
    adapter.processActivity(req, res, async(turnContext) => {
        // route to main dialog.
        await bot.run(turnContext);
    });
});
// Listen for incoming notifications and send proactive messages to users.
server.get('/api/notify', async(req, res) => {
    for (let conversationReference of Object.values(conversationReferences)) {
        await adapter.continueConversation(conversationReference, async turnContext => {
            await turnContext.sendActivity('proactive hello');
        });
    }
    res.setHeader('Content-Type', 'text/html');
    res.writeHead(200);
    res.write('<html><body><h1>Proactive messages have been sent.</h1></body></html>');
    res.end();

希望有帮助!


推荐阅读