我正在將Microsoft Bot Framework與api.ai集成。我遵循教程here。在編碼方面,我還使用Heroku命令行將機器人部署到Heroku。將Microsoft Bot Framework與api.ai集成
我用下面的代碼:
(我改變了APP ID和密碼):
var builder = require('botbuilder');
var restify = require('restify');
var apiairecognizer = require('api-ai-recognizer');
var request = require('request');
//=========================================================
// Bot Setup
//=========================================================
// Setup Restify Server
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function() {
console.log('%s listening to %s', server.name, server.url);
});
// Create chat bot
var connector = new builder.ChatConnector({
appId: '4c8f3u2b-c56n-4117-bc16-ec31eeb5d25c',
appPassword: '4CBNO8vBGtdcGh9PoiVYottY'
});
var connector = new builder.ConsoleConnector().listen();
var bot = new builder.UniversalBot(connector);
var recognizer = new apiairecognizer("84c78b2c15684c7380c6a74c8fbb343f");
var intents = new builder.IntentDialog({
recognizers: [recognizer]
});
bot.dialog('/',intents);
intents.matches('Flow_1',function(session, args){
var fulfillment = builder.EntityRecognizer.findEntity(args.entities, 'fulfillment');
if (fulfillment){
var speech = fulfillment.entity;
session.send(speech);
}else{
session.send('Sorry...not sure how to respond to that');
}
});
intents.onDefault(function(session){
session.send("Sorry...can you please rephrase?");
});`
我的package.json
{
"name": "nodebot",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"api-ai-recognizer": "^1.0.1",
"botbuilder": "^3.8.4",
"restify": "^4.3.0"
}
}
我Procfile
web: node app.js
但是, r成功部署到Heroku,我看到以下錯誤: {「code」:「ResourceNotFound」,「message」:「/ api/messages does not exist」}
即使當我嘗試從Bot框架模擬器,我看到下面的錯誤: 請求「http://localhost:3978/api/messages」失敗:[404]未找到
我有以下幾個問題:1。 如何成功地與框架集成api.ai? 2.如何承載Heroku?
請幫助我如何維護api.ai中的會話。 – AITea
此外,當我部署到Heroku:開放時: https://pacific-hamlet-32804.herokuapp.com 其顯示 {「code」:「ResourceNotFound」,「message」:「/ does not exist」} 開啓 https://pacific-hamlet-32804.herokuapp.com/api/messages 其顯示 {「code」:「MethodNotAllowedError」,「message」:「GET is not allowed」} – AITea
GET錯誤是可以的,因爲路由只是用於POST –