My service is sending back an asynchronous response back to api.ai after a request, which is being displayed on the user interface (Slack, Skype etc).
But I am not able to send a response to the interface after the requested operation is completed (after 5 seconds).
const apiai = require('apiai');
module.exports = (server, config) => {
const app = apiai('<Client access token>');
server.post('/', (req, resp) => {
let body = '';
req.on('data', function(data) {
body += data;
});
req.on('end', function() {
body = JSON.parse(body);
resp.send({
speech: 'Please wait...',
});
const sessionId = body.sessionId;
setTimeout(() => {
const evt = app.eventRequest({
name: 'testevent', data: { },
}, { sessionId });
evt.on('response', resp2 => {
debugger;
});
evt.on('error', err => {
debugger;
});
evt.end();
}, 10 * 1000);
});
});
};
In the object resp2
, I see the result.fulfillment.speech
has the response text which should have been sent to the interface. But it is not.
Is there a way to achieve this?