我正在努力将Microsoft Bot Framework与api.ai集成。我按照教程here进行了操作。在编码时,我还使用Heroku命令行将bot部署到Heroku。
我使用了以下代码:
(我已更改了我的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
但是在成功部署到Heroku之后,我看到以下错误: {“code”:“ResourceNotFound”,“message”:“/ api / messages不存在”}
即使我尝试从Bot框架模拟器测试机器人,我也看到以下错误: 请求“http://localhost:3978/api/messages”失败:[404]未找到
我有以下问题: 1.如何成功地将api.ai与Framework集成? 2.如何主持Heroku?
答案 0 :(得分:1)
似乎未定义TriggerTime = [B1 B2 ... B10];
Torque = [A1 A2 ... A10];
for i = 1:10
currentTriggerTime = TriggerTime(i);
currentTorque = Torque(i);
Code
end
路由。你错过了这一行api/messages
。
此外,您要定义连接器两次,server.post('/api/messages', connector.listen());
和ChatConnector
。请务必删除与ConsoleConnector
相关的代码。