Dialogflow es agent.add()有时无法在dialogflow中给出结果

Dialogflow es agent.add()有时无法在dialogflow中给出结果,dialogflow-es,Dialogflow Es,我正在使用Dialogflow构建聊天机器人,我正在使用Axios发布一些帖子并获取请求,但有时HTTP调用中的agent.add不起作用 我附上样本代码 const functions = require('firebase-functions'); const {WebhookClient} = require('dialogflow-fulfillment'); const {Card, Suggestion} = require('dialogflow-fulfillment'); /

我正在使用Dialogflow构建聊天机器人,我正在使用Axios发布一些帖子并获取请求,但有时HTTP调用中的agent.add不起作用

我附上样本代码

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.


                    });


  }

什么是适当的改变,当我在检查Stackoverflow上的所有其他问题时,我也尝试了返回pomise,但没有成功。

看起来你的承诺结构不正确。这是我用于返回需要承诺的响应的格式:

function name(agent) {
    const promise = new Promise(resolve => {

        // logic goes here

        resolve(agent.add(output));
    });
    return promise;
}

如果这不起作用,请检查它可能失败的其他点-您确定您的webhook在POST请求中没有失败吗?

我正在寻求帮助,如果有人知道,请查看。是的,我确定它没有在POST请求中失败,因为当我发帖的时候,我正在把它写进谷歌的工作表中,它被存储在那里,而且我还可以查看工作正常的日志。我调用这样的API有很多目的,所以创建一个承诺并像这样返回是个好主意吗?我创建了承诺并返回了它们,如图所示,这并没有导致任何性能下降或响应失败。我建议重新构造您的代码,使您的POST请求包含在承诺中,使用resolveagent解决该承诺。添加“您的电子邮件id是什么”;在您的.then方法中。最后,在方法之外返回承诺。然后,非常感谢,我会这样做,看看它是否工作良好。