Javascript azure部署后节点Bot框架Bot获取http 500错误

Javascript azure部署后节点Bot框架Bot获取http 500错误,javascript,azure,botframework,Javascript,Azure,Botframework,我在使用MS bot Framework时创建了一个bot,并将其部署到Azure 部署后,当我们尝试'/api/messages'URL时,bot返回HTTP 500错误 这里是我的app.js: “严格使用”; defineProperty(导出,“\uu esModule”{value:true}); const dialog_service_1=需要(“./服务/对话服务”); const authentication_service_1=需要(“./服务/认证服务”); const

我在使用MS bot Framework时创建了一个bot,并将其部署到Azure

部署后,当我们尝试
'/api/messages'
URL时,bot返回HTTP 500错误

这里是我的app.js:

“严格使用”;
defineProperty(导出,“\uu esModule”{value:true});
const dialog_service_1=需要(“./服务/对话服务”);
const authentication_service_1=需要(“./服务/认证服务”);
const restify=require(“restify”);
const bot_服务_1=要求(“/服务/bot服务”);
const utilities_service_1=需要(“./服务/公用设施服务”);
require(“dotenv”).config();
让botService=new bot_service_1.botService();
//让utilitiesService=new utilitiesService(_dirname+'/assets/labels.json');
让dialogService=newdialog\u service\u 1.dialogService(bot\u service\u 1.BotService.bot);
让port=process.env.port | | process.env.port | | | 3978';
const server=restify.createServer({
格式化程序:{
“文本/html”:函数(请求、回复、正文){
返回body.toString();
}
}
});
log('server created');
//对restify 5.X+所做的更改(应在@true时指定mapParams)
使用(restify.plugins.bodyParser({
mapParams:对
}));
log('尝试侦听..');
服务器。侦听(端口,()=>{
console.log(“%s服务器正在侦听%s”、server.name、server.url);
});
console.log('listing');
log('mounting styles folder…');
//将build/styles文件夹添加到restify服务器
server.get(/\/styles\/?*/,restify.plugins.serveStatic({
目录:_dirname+'/assets'
}));
console.log('mounted');
log('mounting api/messages端点…');
//你的机器人的入口点
server.post(“/api/messages”,bot\u service\u 1.BotService.bot.connector(“*”.listen());
console.log('mounted…');
log('mounting api/oauthcallback端点…');
//回调处理
server.post(“/api/oauthcallback”,(req、res、next)=>{
让authorizationCode=req.params.code;
if(授权代码!==未定义){
authentification\u服务\u 1.AuthentificationService.acquireTokenWithAuthorizationCode(authorizationCode)。然后((响应)=>{
let state=req.params.state;
如果(州){
let address=JSON.parse(state);
response.state=状态;
bot\u service\u 1.BotService.bot.beginDialog(地址,“/oauth success”,响应);
}
utilities_service_1.UtilitesService.readFile(__dirname+'/assets/html/callback.html')。然后(body=>{
res.send(200,body,{“内容长度”:Buffer.byteLength(body.toString(),“内容类型”:“text/html”});
res.end();
});
}).catch((错误消息)=>{
var body=“”+错误消息+”;
res.send(200,body,{“内容长度”:Buffer.byteLength(body.toString(),“内容类型”:“text/html”});
res.end();
});
}
否则{
var body=“”+”无法检索身份验证代码“+”;
res.send(200,body,{“内容长度”:Buffer.byteLength(body.toString(),“内容类型”:“text/html”});
res.end();
}
});
console.log('mounted');

//#sourceMappingURL=app.js.map
我注意到您没有启动bot和启动对话框。当我按原样尝试您的代码时,我收到一个502错误。当我为bot引入代码时,错误消失,bot响应,正如预期的那样

由于我无法访问您的所有文件,因此我必须删除关联的代码调用。所以,我不能说你收到的错误是否与这些代码有关

我在server.post中使用connector.listen()表示“api/messages”。定义连接器(如下所示)遵循中的基本设置,用于使用节点构建机器人

希望这有帮助

史蒂夫

'use string';

const builder = require('botbuilder');
const restify = require('restify');
require('dotenv').config();

let port = process.env.port || process.env.PORT || '3978';

let server = restify.createServer({
    formatters: {
        'text/html': function (req, res, body) {
            return body.toString();
        }
    }
});

// change done for restify 5.X+ (mapParams should be specified @ true)
server.use(restify.plugins.bodyParser({
    mapParams: true
}));

server.listen(port, () => {
    console.log('%s server listening to %s', server.name, server.url);
});

// entry point of your bot
let connector = new builder.ChatConnector({
    appId: process.env.MicrosoftAppId,
    appPassword: process.env.MicrosoftAppPassword,
    openIdMetadata: process.env.BotOpenIdMetadata
});

server.post('/api/messages', connector.listen());

//callback handling
server.post('/api/oauthcallback', (req, res, next) => {
    var authorizationCode = req.params.code;
    if (authorizationCode !== undefined) {
        console.log('authorization code provided');
    }
    else {
        console.log('authorization code not provided');
    }
});

// inMemoryStorage should only be used for testing. It is not stable for a production environment
let inMemoryStorage = new builder.MemoryBotStorage();
let bot = new builder.UniversalBot(connector).set('storage', inMemoryStorage);

bot.dialog('/', [
    function (session) {
        session.send('Hi');
    }
]);

您是否直接调用
api/messages
。当bot在配置的通道上接收用户消息时,bot框架会自动调用该端点。不需要手动调用它。这就是您正在做的吗?这是bot框架配置中定义的端点。我的意思是,您是否手动调用该端点。不需要手动调用该端点。该端点上唯一重要的代码是调用bot connector的listen方法。你好,Steven,它在本地工作,所以我认为这不是真正的代码问题。。但是对于信息,thébot是通过bot服务初始化的initialization@Filsdegandalf,很高兴你成功了!如果您觉得我的回答足够,请“接受”它,以便我可以从我的支持跟踪器中清除此票据。这样做也将有利于其他有类似问题的人。如果没有,让我知道我还能提供什么帮助!