AITea
AITea

Reputation: 41

Integrating Microsoft Bot Framework with api.ai

I am working on integrating Microsoft Bot Framework with api.ai. I followed the tutorials here. On coding, I also deployed the bot to Heroku using Heroku command line.

I have used the code as below:

(I have changed my APP ID and Password):

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?");
});` 

My 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"
  }
}

My Procfile

web: node app.js

But after successfully deploying to Heroku, I am seeing the following error: {"code":"ResourceNotFound","message":"/api/messages does not exist"}

Even when I tried testing the bot from Bot Framework Emulator, I am seeing the below error: Request to 'http://localhost:3978/api/messages' failed: [404] Not Found

I have following questions: 1. How to successfully integrate api.ai with Framework? 2. How to host it Heroku?

Upvotes: 1

Views: 832

Answers (1)

Ezequiel Jadib
Ezequiel Jadib

Reputation: 14787

It seems that the api/messages route is not defined. You are missing this line server.post('/api/messages', connector.listen());.

Also, you are defining the connector twice, the ChatConnector and the ConsoleConnector. Make sure to delete the code related to the ConsoleConnector.

Upvotes: 1

Related Questions