Reputation: 67
I am using Dialogflow to build a chatbot and I am using Axios to make some posts and get requests, but sometimes agent.add() inside that HTTP call doesn't work.
I am attaching the sample code.
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
// Using some external libraries
//axios for using third party api hosted as http.
const axios = require('axios');
// xml2js for parsing xml output in response
const xml2js = require('xml2js');
const json = require('json');
// Accessing firebase admin
const admin = require('firebase-admin');
function name(agent){
return axios.post('http://some-api,
{"name": "Kyle"}).then((result) => {
console.log('Store datato api');
agent.add('What is your email id'); // Sometimes its working and sometimes its not
//return Promise.resolve(agent); // I tried this as well but the same issue.
});
}
What could be appropiate changes, as I was going through all other questions on Stackoverflow, I tried returning pomise as well, but didn't work.
Upvotes: 0
Views: 454
Reputation: 548
It looks like you've structured your Promise incorrectly. This is the format I use to return responses that require Promises:
function name(agent) {
const promise = new Promise(resolve => {
// logic goes here
resolve(agent.add(output));
});
return promise;
}
If this doesn't work, check other points it may be failing at - are you sure your webhook isn't failing in the POST request?
Upvotes: 1