0
votes

I have built a bot using Microsoft Bot Framework capable of talking to api.ai. Right now for a given user input, a reply is received. However, api.ai has the concept of contexts for which maintaining session is important. How can I achieve sessions from Microsoft Bot Framework?

My bot code (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?");
});`
1
Bot Framework SDK does not currently support API.ai out of the box. You would need to implement a custom solution.nwxdev
How can I do that? Can you help me out?AITea

1 Answers

0
votes

As I understand you use the Microsoft Framework as a webhook for api.ai while api.ai receives its messenges through a integration or whatever.

You don't have to handle this, as api.ai sends a POST request to your webhook, on which you send a response back. Since this is one https-tcp connection, there is no need to handle the session id in the webhook. This is what api.ai and its integrations handle. Thats all for contexts.

If you want to identify a specific user through different sessions you have to think about something own.


When using the API and no integration

You have to keep track of a session id. You have to provide this id in each query.

A response from query will also contain this id.

Search for sessionId in the docs. https://api.ai/docs/reference/agent/query#query_parameters_and_json_fields