我在使用MS Bot Framework时创建了一个机器人并将其部署到Azure。
部署后,当我们尝试'/api/messages'
网址时,僵尸程序会返回HTTP 500错误。
这是我的app.js:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const dialog_service_1 = require("./services/dialog-service");
const authentification_service_1 = require("./services/authentification-service");
const restify = require("restify");
const bot_service_1 = require("./services/bot-service");
const utilities_service_1 = require("./services/utilities-service");
require("dotenv").config();
let botService = new bot_service_1.BotService();
// let utilitiesService = new UtilitiesService(__dirname + '/assets/labels.json');
let dialogService = new dialog_service_1.DialogService(bot_service_1.BotService.bot);
let port = process.env.port || process.env.PORT || '3978';
const server = restify.createServer({
formatters: {
'text/html': function (req, res, body) {
return body.toString();
}
}
});
console.log('server created');
// change done for restify 5.X+ (mapParams should be specified @ true)
server.use(restify.plugins.bodyParser({
mapParams: true
}));
console.log('trying to listening..');
server.listen(port, () => {
console.log('%s server listening to %s', server.name, server.url);
});
console.log('listening');
console.log('mounting styles folder...');
//add the build/styles folder to the restify server
server.get(/\/styles\/?.*/, restify.plugins.serveStatic({
directory: __dirname + '/assets'
}));
console.log('mounted');
console.log('mounting api/messages endpoint...');
// entry point of your bot
server.post("/api/messages", bot_service_1.BotService.bot.connector("*").listen());
console.log('mounted...');
console.log('mounting api/oauthcallback endpoint...');
//callback handling
server.post("/api/oauthcallback", (req, res, next) => {
let authorizationCode = req.params.code;
if (authorizationCode !== undefined) {
authentification_service_1.AuthentificationService.acquireTokenWithAuthorizationCode(authorizationCode).then((response) => {
let state = req.params.state;
if (state) {
let address = JSON.parse(state);
response.state = state;
bot_service_1.BotService.bot.beginDialog(address, "/oauth-success", response);
}
utilities_service_1.UtilitiesService.readFile(__dirname + '/assets/html/callback.html').then(body => {
res.send(200, body, { "Content-Length": Buffer.byteLength(body).toString(), "Content-Type": "text/html" });
res.end();
});
}).catch((errorMessage) => {
var body = "<html><body>" + errorMessage + "</body></html>";
res.send(200, body, { "Content-Length": Buffer.byteLength(body).toString(), "Content-Type": "text/html" });
res.end();
});
}
else {
var body = "<html><body>" + "unable to retrieve the authentication code" + "</body></html > ";
res.send(200, body, { "Content-Length": Buffer.byteLength(body).toString(), "Content-Type": "text/html" });
res.end();
}
});
console.log('mounted');
//# sourceMappingURL=app.js.map
&#13;
我添加了一些日志来帮助我,所有console.log()
都已到达。所以似乎服务器启动良好......
感谢您的帮助。
答案 0 :(得分:0)
我注意到你没有启动机器人并开始对话。当我按原样尝试您的代码时,我收到502错误。当我为机器人引入代码时,错误消失,机器人响应,如预期的那样。
由于我无法访问您的所有文件,因此我不得不删除相关的代码调用。所以,我不能说你收到的错误是否与任何代码有关。
我在server.post中使用了connector.listen()来表示'api / messages'。如下所示,定义连接器遵循documentation中的基本设置,用于使用节点构建机器人。
希望这有帮助。
史蒂夫。
auto