我用Luis和heroku创建了一个Microsoft聊天机器人,但该机器人仅在本地主机上运行。
我已经按照以下步骤进行操作: https://docs.microsoft.com/en-us/azure/bot-service/bot-service-troubleshoot-authentication-problems?view=azure-bot-service-4.0
每个步骤都成功,即使我使用我的Bot-Id和Bot-Password在本地主机上对其进行测试,应用程序也正在运行。
但是,如果我尝试在Azure的Web聊天中使用我的漫游器或在Microsoft Teams中实现它,那么它将无法正常工作。
这是heroku应用程序的地址: https://movie-booking-bot.herokuapp.com/
有人知道为什么它不起作用吗?我的代码有问题吗?还是我缺少一些配置?
问题陈述:
Bot仅在localhost上响应。如果我正在通过网络聊天或通过Teams测试该机器人,则不会收到任何消息。
预先感谢您的帮助。
我在网络聊天中发送消息时从heroku获取的以下日志:
2019-06-29T20:12:14.084375+00:00 heroku[router]: at=info method=POST path="/api /messages" host=movie-booking-bot.herokuapp.com request_id=4b72f187-1e7f-480b-bb77-3f68ea0842e4 fwd="13.94.244.42" dyno=web.1 connect=0ms service=3ms status=202 bytes=117 protocol=https
2019-06-29T20:12:16.293731+00:00 heroku[router]: at=info method=POST path="/api/messages" host=movie-booking-bot.herokuapp.com request_id=b2634bfe-855e-49d6-855a-93a2ce746ecb fwd="13.94.244.42" dyno=web.1 connect=1ms service=2ms status=202 bytes=117 protocol=https
2019-06-29T20:12:16.325668+00:00 heroku[router]: at=info method=POST path="/api/messages" host=movie-booking-bot.herokuapp.com request_id=550e1f4b-0cf8-4224-971e-bf007be659bc fwd="13.94.244.42" dyno=web.1 connect=1ms service=4ms status=202 bytes=117 protocol=https
2019-06-29T20:12:16.326065+00:00 app[web.1]: The Bot State API is deprecated. Please refer to https://aka.ms/I6swrh for details on how to replace with your own storage.
2019-06-29T20:12:16.487948+00:00 app[web.1]: Error: GET to 'https://state.botframework.com/v3/botstate/webchat/conversations/GHZx9biLjXS1vmTW2BqFUS-h/users/DUnoSSshPmV' failed: [405] Method Not Allowed
2019-06-29T20:12:16.487952+00:00 app[web.1]: at Request._callback (/app/node_modules/botbuilder/lib/bots/ChatConnector.js:675:46)
2019-06-29T20:12:16.487954+00:00 app[web.1]: at Request.self.callback (/app/node_modules/request/request.js:185:22)
2019-06-29T20:12:16.487956+00:00 app[web.1]: at Request.emit (events.js:198:13)
2019-06-29T20:12:16.487958+00:00 app[web.1]: at Request.EventEmitter.emit (domain.js:448:20)
2019-06-29T20:12:16.487960+00:00 app[web.1]: at Request.<anonymous> (/app/node_modules/request/request.js:1161:10)
2019-06-29T20:12:16.487961+00:00 app[web.1]: at Request.emit (events.js:198:13)
2019-06-29T20:12:16.487963+00:00 app[web.1]: at Request.EventEmitter.emit (domain.js:448:20)
2019-06-29T20:12:16.487964+00:00 app[web.1]: at IncomingMessage.<anonymous> (/app/node_modules/request/request.js:1083:12)
2019-06-29T20:12:16.487966+00:00 app[web.1]: at Object.onceWrapper (events.js:286:20)
2019-06-29T20:12:16.487967+00:00 app[web.1]: at IncomingMessage.emit (events.js:203:15)
var builder = require('botbuilder');
var restify = require('restify');
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function() {
console.log('%s listening to %s', server.name, server.url);
});
var connector = new builder.ChatConnector({
appId: 'ID',
appPassword: 'PASSWORD'
});
server.post('/api/messages', connector.listen());
var bot = new builder.UniversalBot(connector);
var LuisAPPId= "ID";
var LuisAPIKey ="Password";
var LuisAPIHostName ="westus.api.cognitive.microsoft.com";
const LuiSModelURL ='https://' + LuisAPIHostName + '/luis/v2.0/apps/' +LuisAPPId +'?subscription-key=' + LuisAPIKey;
var recognizer = new builder.LuisRecognizer(LuiSModelURL);
var intents = new builder.IntentDialog({
recognizers: [recognizer]
});
bot.dialog('/', intents);
intents.matches('Greet', (session, args, next) => {
session.send("Hello I`am your digital cinema assitents. I can inform you about movies or book direct one or several tickets for you.");
});
var movies = [
"spider-man",
"rampage",
"the avengers",
"jurassic world"
];
intents.matches('ShowNowPlaying', (session, args, next) => {
session.send("Hey this is our programm of movies which are played :)\n\n" + movies.join("\n\n"));
});
intents.matches('BookTicket', [(session, args, next) => {
console.log(JSON.stringify(args));
var movieEntity = args.entities.filter(e => e.type == 'Movies');
var NumOfTicketsEntity = args.entities.filter(e => e.type == 'builtin.number');
if(movieEntity.length > 0)
{
session.userData.movie = movieEntity[0].resolution.values[0];
}
else {
delete session.userData.movie;
}
if(NumOfTicketsEntity.length > 0) {
session.userData.NumOfTickets = NumOfTicketsEntity[0].resolution.value;
} else {
delete session.userData.NumOfTickets;
}
if(!session.userData.movie) {
session.beginDialog('askMovie');
}
else{
next();
}
}, (session, args, next) => {
if(!session.userData.NumOfTickets) {
session.beginDialog('askNumOfTickets');
}
else{
next();
}
}, (session, args, next) => {
session.send("Sure, I have booked you " + session.userData.NumOfTickets + " tickets for " + session.userData.movie + ". Have Fun")
}]);
bot.dialog('askMovie', [(session, args, next) => {
builder.Prompts.choice(session, 'What movie would you like to watch?', movies);
}, (session, results) => {
session.userData.movie = results.response.entity;
session.endDialogWithResult(results);
}]);
bot.dialog('askNumOfTickets', [(session, args, next) => {
builder.Prompts.number(session, 'Great! How many tickets do you would like to have?');
}, (session, results) => {
session.userData.NumOfTickets = results.response;
session.endDialogWithResult(results);
}])