【问题标题】:BotFramework WebChat not sending messagesBotFramework WebChat 不发送消息
【发布时间】:2020-02-18 01:41:56
【问题描述】:

我正在尝试运行机器人构建器示例之一,以检查从网络聊天开始将自适应卡片发送到多个渠道的机会。该示例可以在这里找到:https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/javascript_nodejs/07.using-adaptive-cards

我设法建立了与框架模拟器的连接,但是当更改为在 azure 控制台中使用 webChat 测试对其进行测试时,似乎 webChat 无法发送消息。

当我使用 SDK V4 时,我明白我根本不需要关心 SSL 连接,也不需要关心 A 类证书 - 这一切都由 SDK/框架完成。

所以我的 bot 在 http 协议下作为 restify-server 运行,但是 botservice 的配置表明服务端点应该支持 https。我需要为此担心吗?

这里是示例代码:

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

const path = require('path');
const restify = require('restify');

// Import required bot services.
// See https://aka.ms/bot-services to learn more about the different parts of a bot.
const { BotFrameworkAdapter } = require('botbuilder');

const { AdaptiveCardsBot } = require('./bots/adaptiveCardsBot');

// Read botFilePath and botFileSecret from .env file.
const ENV_FILE = path.join(__dirname, '.env');
require('dotenv').config({ path: ENV_FILE });

// Create adapter. See https://aka.ms/about-bot-adapter to learn more about adapters.
const adapter = new BotFrameworkAdapter({
    appId: process.env.MicrosoftAppID,
    appPassword: process.env.MicrosoftAppPassword
});

// Catch-all for errors.
adapter.onTurnError = async (context, error) => {
    // This check writes out errors to console log .vs. app insights.
    // NOTE: In production environment, you should consider logging this to Azure
    //       application insights.
    console.error(`\n [onTurnError] unhandled error: ${ error }`);

    // Send a trace activity, which will be displayed in Bot Framework Emulator
    await context.sendTraceActivity(
        'OnTurnError Trace',
        `${ error }`,
        'https://www.botframework.com/schemas/error',
        'TurnError'
    );

    // Send a message to the user
    await context.sendActivity('The bot encountered an error or bug.');
    await context.sendActivity('To continue to run this bot, please fix the bot source code.');
};

// Create the AdaptiveCardsBot.
const bot = new AdaptiveCardsBot();

// Create HTTP server
const server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function() {
    console.log(`\n${ server.name } listening to ${ server.url }`);
    console.log('\nGet Bot Framework Emulator: https://aka.ms/botframework-emulator');
    console.log('\nTo talk to your bot, open the emulator select "Open Bot"');
});

// Listen for incoming requests.
server.post('/api/messages', (req, res) => {
    adapter.processActivity(req, res, async (context) => {
        await bot.run(context);
    });
});```



【问题讨论】:

    标签: node.js botframework


    【解决方案1】:

    这可能与 HTTP(S)/SSL 没有任何关系。这听起来像一个部署问题。这是一些common deployment troubleshooting

    常见部署问题

    推荐步骤

    • 通过Azure Portal > Your Resource Group > Your Bot > Test in Web Chat 测试“网络聊天中的测试”是否有效。
      • 如果有效,则说明您的部署成功,您需要排除客户端无法连接到已部署机器人的问题
      • 如果它不起作用,请按照本文档中的其他故障排除步骤进行操作
    • 如果您在执行部署 CLI 命令时遇到错误,请确保您拥有最新版本的 Azure CLI
      • 一些 CLI 命令会在没有太多解释的情况下失败。这通常是格式错误。对于您的 CLI 命令,请确保:
      • 整个命令有适当的间距
      • 用户提供的字符串用引号括起来
      • 用户提供的资源名称字符串不含特殊字符(这主要适用于应用服务计划名称)。详情请见Naming rules and restrictions
    • 确保在部署之前运行the az bot prepare-deploy step。在访问https://<yourBot>.azurewebsites.net 时,缺少此步骤通常表现为机器人无法启动或 404 错误(由于缺少/不正确的web.config
    • 确保https://<yourBot>.scm.azurewebsites.net/dev/wwwroot/ 的文件/文件夹结构与您的本地机器人相似。对于 Node 机器人,它看起来与您的本地机器人文件大致相同。对于 C# 机器人,它将有很多 Microsoft.*.dll 文件以及 <yourBot>.dll。所有部署的机器人都应该有一个web.config 文件
      • 对于节点机器人,您还需要部署 node_modules.env。对于 C# 机器人,您需要 appsettings.json。如果您的机器人缺少.envappsettings.json,您需要上传它,或者在Azure Portal > Your Resource Group > Your App Service > Configuration 中复制相应的键和值
      • the code deployment step 上展开:部署时,压缩项目文件夹的内容,而不是文件夹本身。您的 zip 文件应具有以下结构:
      • code.zip/[each project file and folder]不是 code.zip/myBot/[each project file and folder]
    • 确保您在 appsettings.json/.env/App Service Configuration 中的 MicrosoftAppId 和 MicrosoftAppPassword 与在您的 App Registration 中找到的相匹配
    • 通过关注these steps,确保“任何组织目录中的帐户”可以访问您的应用注册
    • 转到https://<yourBot>.scm.azurewebsites.net/dev/wwwroot/:output,单击“运行”,然后查看“输出”窗口中是否出现任何错误

    推荐文件


    请关注文档并告诉我进展如何。如果事实证明这不是是部署问题,我会调整这个答案。

    【讨论】:

    • 感谢您的建议,我找到了一个使用 ngrok 的临时解决方案,该代理现在位于我的 http 服务器(机器人)和机器人服务之间。
    • 但是由于我的服务器地址暴露在互联网上,我仍然不完全理解连接的概念。所以现在我很好,谢谢。当我再次遇到该主题时,我会仔细阅读故障排除文档。
    • @Andre。听起来不错。让我知道如果你有什么想要我告诉你的。如果它充分解决了您的问题/问题,请随时“接受”我的回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多