将 Microsoft Bot Framework 与 api.ai 集成
Integrating Microsoft Bot Framework with api.ai
我正在努力将 Microsoft Bot Framework 与 api.ai 集成。我遵循了教程 here。在编码方面,我还使用 Heroku 命令行将机器人部署到 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"
}
}
我的程序文件
web: node app.js
但是在成功部署到 Heroku 之后,我看到了以下错误:
{"code":"ResourceNotFound","message":"/api/messages 不存在"}
即使我尝试从 Bot Framework Emulator 测试机器人,我也会看到以下错误:
对“http://localhost:3978/api/messages”的请求失败:[404] 未找到
我有以下问题:
1. api.ai如何与Framework成功集成?
2. 如何托管Heroku?
似乎没有定义api/messages
路由。您缺少这一行 server.post('/api/messages', connector.listen());
。
此外,您定义了两次连接器,ChatConnector
和 ConsoleConnector
。确保删除与 ConsoleConnector
相关的代码。
我正在努力将 Microsoft Bot Framework 与 api.ai 集成。我遵循了教程 here。在编码方面,我还使用 Heroku 命令行将机器人部署到 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"
}
}
我的程序文件
web: node app.js
但是在成功部署到 Heroku 之后,我看到了以下错误: {"code":"ResourceNotFound","message":"/api/messages 不存在"}
即使我尝试从 Bot Framework Emulator 测试机器人,我也会看到以下错误: 对“http://localhost:3978/api/messages”的请求失败:[404] 未找到
我有以下问题: 1. api.ai如何与Framework成功集成? 2. 如何托管Heroku?
似乎没有定义api/messages
路由。您缺少这一行 server.post('/api/messages', connector.listen());
。
此外,您定义了两次连接器,ChatConnector
和 ConsoleConnector
。确保删除与 ConsoleConnector
相关的代码。