Reputation: 3425
I'm developing chatbots with Api.ai from last few months
I want to connect it with nodejs client and I successfully sent text queries
from nodejs to api.ai and get response back(as described in doc: https://github.com/api-ai/apiai-nodejs-client),
but I'm still unable to send Events
using nodejs sdk since no documentation is available in doc: https://github.com/api-ai/apiai-nodejs-client
please refer me to any helpful sample code or article
Upvotes: 1
Views: 1654
Reputation: 131
If you are using Node try the following:
var apiai = require('apiai');
var app = apiai(process.env.APIAI_TOKEN);
const sendEventToApiAi = (event, sessionId) => {
return new Promise(function(resolve, reject) {
let eventArg = {
"name": event.type
"data": event.data
};
var request = app.eventRequest(eventArg, {sessionId: sessionId});
request.on('response', function(response) {
console.log("sendEventToApiAi: response=" + JSON.stringify(response));
return resolve(response);
});
request.on('error', function(error) {
return reject(error);
});
request.end();
});
}
let event = { type: "CALCULATED_RESULTS" };
//Send Event to apiai Intent.
sendEventToApiAi(event, sessionId);
Upvotes: 1