【发布时间】: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