node.js - Azure BotFrameworkAdapter 错误 400 缺少参数类型
问题描述
我已经通过新的 AppService linux 将我的 node.js 服务器部署到 Azure 中。它正确启动,因为如果我调用一个 http get 它返回正确的数据。但是当我尝试调用发布的网址时:
server.post('/api/messages', (req, res) => {
adapter.processActivity(req, res, async (context) => {
// Process bot activity
await botActivityHandler.run(context).catch((e) => { console.dir(e) });
});)}
它返回
UnhandledPromiseRejectionWarning: Error: BotFrameworkAdapter.processActivity(): 400 ERROR Error: BotFrameworkAdapter.parseRequest(): missing activity type.
我已经检查了机器人是否有正确的 appId 和 pwd,并且没问题。
这是我的 index.js 文件:
// index.js is used to setup and configure your bot
const path = require('path');
const express = require('express');
const bodyParser = require('body-parser');
// Import required bot services.
// See https://aka.ms/bot-services to learn more about the different parts of a bot.
const { BotFrameworkAdapter } = require('botbuilder');
// Import bot definitions
const { BotActivityHandler } = require('./botActivityHandler');
// Read botFilePath and botFileSecret from .env file.
const ENV_FILE = path.join(__dirname, '.env');
require('dotenv').config({ path: ENV_FILE });
// Create adapter.
const adapter = new BotFrameworkAdapter({
appId: "XXXXXXXXXXXXXXXXXXXXXX",
appPassword: "XXXXXXXXXXXXXXXXXXXXXXX"
});
adapter.onTurnError = async (context, error) => {
console.error(`unhandled error: ${error}`);
console.dir(`unhandled error: ${error}`);
await context.sendTraceActivity(
'OnTurnError Trace',
`${error}`,
'https://www.botframework.com/schemas/error',
'TurnError'
);
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 bot handlers
const botActivityHandler = new BotActivityHandler();
// Create HTTP server.
const server = express();
server.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
next();
});
server.use(bodyParser.json()); // to support JSON-encoded bodies
server.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}));
const port = process.env.port || process.env.PORT || 3978;
server.listen(port, () =>
console.log(`service listening at https://localhost:${port}`)
);
// Listen for incoming requests.
server.post('/api/messages', (req, res) => {
console.dir(adapter);
adapter.processActivity(req, res, async (context) => {
// Process bot activity
console.dir(context);
await botActivityHandler.run(context).catch((e) => { console.dir(e) });
});
});
server.post('/api/create/uat', (req, res) => {
console.dir(req.params);
});
server.get('/api/read/uat', (req, res) => {
console.dir(req.params);
});
server.post('/api/prova/post', (req, res) => {
console.dir(req.params);
});
在本地使用 ngrok 运行正常,有人可以帮助我吗?谢谢。
解决方案
正如@Leonardo 所建议的那样,可以通过更改 URL 来删除本地和分布式应用程序并设置新应用程序。
推荐阅读
- azure-data-explorer - 使用按 Z 排序的 top N 对 X 和 Y 进行汇总
- reactjs - React build 使用 Django 显示白页
- python - tkinter:通过单击移动图像
- css - 如何根据sass中的父属性计算子属性
- javascript - 使用 Javascript (VanillaJS) 添加点击事件并显示/隐藏下一个元素
- c# - 尝试连接到另一台计算机上存储的数据库时出现“等待操作超时”错误
- java - Spring gRPC - 如何使用正文信息拦截异常
- android - ForYouFragment 片段不更新
- java - 如何将值传递到地图中?
- c - 我遇到了一个使用列表的问题