CTD
CTD

Reputation: 43

Heroku Hosting Microsoft Bot Framework Chatbot not working

I have done a Chat-bot using Microsoft Bot Framework. The bot is perfectly running fine on the emulator. However I want to Host it on it to Heroku.

My app.js code:

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: "xxx", /*changed*/
    appPassword: "xxx" /*changed*/
});

server.post('/api/messages', connector.listen());
var bot = new builder.UniversalBot(connector);


var recognizer = new apiairecognizer("xxx");
var intents = new builder.IntentDialog({
         recognizers: [recognizer]
});

bot.dialog('/',intents);

intents.matches('Intro',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.matches('Default Fallback Intent',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');
    }
});

I tried the following commands to push it on to Heroku:

  1. git remote rm heroku
  2. git init
  3. Created a file .gitignore and inside it node_modules/
  4. git add .
  5. git commit -m "basic bot setup done"
  6. Procfile and added the code web: node index.js
  7. heroku create
  8. heroku git:remote -a app name
  9. git push heroku master
  10. heroku open

I have also updated by messaging endpoint to Messaging Endpoint : http://appname.herokuapp.com/api/messages in Bot development Portal.

The build succeed. If I open http://appname.herokuapp.com/api/messages, I am seeing {"code":"MethodNotAllowedError","message":"GET is not allowed"} and on opening {"code":"ResourceNotFound","message":"/ does not exist"}

I am stuck here. I want to have the chat-bot on the page using the I Frame provided by Bot registration portal. How to proceed from here and make the bot working?

Upvotes: 0

Views: 715

Answers (2)

kmak
kmak

Reputation: 728

This means your bot is hosted and working. Your bot is basically an API that only accepts post requests:

server.post('/api/messages', connector.listen());

So when you are trying to access http://appname.herokuapp.com/api/messages in your browser you are making a GET request, which your API doesn't accept.

The iFrame will be the front end to your bot that will use your bot API hosted on heroku. Instructions for setting up the iFrame are here: https://learn.microsoft.com/en-us/bot-framework/channel-connect-webchat

You can test if the API is working on the bot portal https://dev.botframework.com/bots?id=[your-bot-id] by clicking the test button in the right hand corner that will open a web chat.

Upvotes: 0

itaintme
itaintme

Reputation: 1603

I had the same problem, fixed it by doing this. Open terminal/powershell in the app folder and type the following

heroku config:set MICROSOFT_APP_ID=YOUR_APP_ID MICROSOFT_APP_PASSWORD=YOUR_APP_PASSWORD

Upvotes: 3

Related Questions