When I use Promise with dialogflow library in server - get Error












1















I try to execute this code on Firebase Cloud Functions



const functions = require('firebase-functions');
const admin = require('firebase-admin');
const firebase_database = require('./conf/firebase');
const { WebhookClient } = require('dialogflow-fulfillment');

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
function searcheColleagueByName(agent){
var lastname = agent.parameters.lastname;
firebase_database.ref().once('value')
.then(team => {
agent.add("some name " + lastname);
})
.catch(err=>{
agent.add("something wrong");
})
}


and after when i make request to my bot from telegram I get error in firebase console:



Error: No responses defined for platform: null
at V2Agent.sendResponses_ (/srv/node_modules/dialogflow-fulfillment/src/v2-agent.js:243:13)
at WebhookClient.send_ (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:505:17)
at promise.then (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:316:38)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:228:7)


What's wrong? why when I use promisse my agent can't give me an answer?










share|improve this question

























  • You only define a function in the body of the onRequest callback; you don't do or return anything. NB: where would you get the value of agent from? Also, your code has more opening parentheses and braces than closing ones. Please take care of indenting you code properly.

    – trincot
    Nov 19 '18 at 20:28


















1















I try to execute this code on Firebase Cloud Functions



const functions = require('firebase-functions');
const admin = require('firebase-admin');
const firebase_database = require('./conf/firebase');
const { WebhookClient } = require('dialogflow-fulfillment');

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
function searcheColleagueByName(agent){
var lastname = agent.parameters.lastname;
firebase_database.ref().once('value')
.then(team => {
agent.add("some name " + lastname);
})
.catch(err=>{
agent.add("something wrong");
})
}


and after when i make request to my bot from telegram I get error in firebase console:



Error: No responses defined for platform: null
at V2Agent.sendResponses_ (/srv/node_modules/dialogflow-fulfillment/src/v2-agent.js:243:13)
at WebhookClient.send_ (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:505:17)
at promise.then (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:316:38)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:228:7)


What's wrong? why when I use promisse my agent can't give me an answer?










share|improve this question

























  • You only define a function in the body of the onRequest callback; you don't do or return anything. NB: where would you get the value of agent from? Also, your code has more opening parentheses and braces than closing ones. Please take care of indenting you code properly.

    – trincot
    Nov 19 '18 at 20:28
















1












1








1








I try to execute this code on Firebase Cloud Functions



const functions = require('firebase-functions');
const admin = require('firebase-admin');
const firebase_database = require('./conf/firebase');
const { WebhookClient } = require('dialogflow-fulfillment');

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
function searcheColleagueByName(agent){
var lastname = agent.parameters.lastname;
firebase_database.ref().once('value')
.then(team => {
agent.add("some name " + lastname);
})
.catch(err=>{
agent.add("something wrong");
})
}


and after when i make request to my bot from telegram I get error in firebase console:



Error: No responses defined for platform: null
at V2Agent.sendResponses_ (/srv/node_modules/dialogflow-fulfillment/src/v2-agent.js:243:13)
at WebhookClient.send_ (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:505:17)
at promise.then (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:316:38)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:228:7)


What's wrong? why when I use promisse my agent can't give me an answer?










share|improve this question
















I try to execute this code on Firebase Cloud Functions



const functions = require('firebase-functions');
const admin = require('firebase-admin');
const firebase_database = require('./conf/firebase');
const { WebhookClient } = require('dialogflow-fulfillment');

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
function searcheColleagueByName(agent){
var lastname = agent.parameters.lastname;
firebase_database.ref().once('value')
.then(team => {
agent.add("some name " + lastname);
})
.catch(err=>{
agent.add("something wrong");
})
}


and after when i make request to my bot from telegram I get error in firebase console:



Error: No responses defined for platform: null
at V2Agent.sendResponses_ (/srv/node_modules/dialogflow-fulfillment/src/v2-agent.js:243:13)
at WebhookClient.send_ (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:505:17)
at promise.then (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:316:38)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:228:7)


What's wrong? why when I use promisse my agent can't give me an answer?







javascript firebase-realtime-database dialogflow google-assistant-sdk






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 21:45









Prisoner

34.7k33258




34.7k33258










asked Nov 19 '18 at 20:16









missing17missing17

298




298













  • You only define a function in the body of the onRequest callback; you don't do or return anything. NB: where would you get the value of agent from? Also, your code has more opening parentheses and braces than closing ones. Please take care of indenting you code properly.

    – trincot
    Nov 19 '18 at 20:28





















  • You only define a function in the body of the onRequest callback; you don't do or return anything. NB: where would you get the value of agent from? Also, your code has more opening parentheses and braces than closing ones. Please take care of indenting you code properly.

    – trincot
    Nov 19 '18 at 20:28



















You only define a function in the body of the onRequest callback; you don't do or return anything. NB: where would you get the value of agent from? Also, your code has more opening parentheses and braces than closing ones. Please take care of indenting you code properly.

– trincot
Nov 19 '18 at 20:28







You only define a function in the body of the onRequest callback; you don't do or return anything. NB: where would you get the value of agent from? Also, your code has more opening parentheses and braces than closing ones. Please take care of indenting you code properly.

– trincot
Nov 19 '18 at 20:28














1 Answer
1






active

oldest

votes


















0














The problem is that, if you're using an async function, then your intent handler must also return a Promise. It isn't enough that you send the reply as part of the then() clause, you must also return the Promise that the then() is part of.



In your case, this looks fairly easy. In the searchColleagueByName() function, you would return then once().then().catch() result, which is a Promise. (Since then() and catch() return a Promise.)



So it might look something like this:



   return firebase_database.ref().once('value')
.then(team => {
agent.add("some name " + lastname);
})
.catch(err=>{
agent.add("something wrong");
})





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53382012%2fwhen-i-use-promise-with-dialogflow-library-in-server-get-error%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The problem is that, if you're using an async function, then your intent handler must also return a Promise. It isn't enough that you send the reply as part of the then() clause, you must also return the Promise that the then() is part of.



    In your case, this looks fairly easy. In the searchColleagueByName() function, you would return then once().then().catch() result, which is a Promise. (Since then() and catch() return a Promise.)



    So it might look something like this:



       return firebase_database.ref().once('value')
    .then(team => {
    agent.add("some name " + lastname);
    })
    .catch(err=>{
    agent.add("something wrong");
    })





    share|improve this answer




























      0














      The problem is that, if you're using an async function, then your intent handler must also return a Promise. It isn't enough that you send the reply as part of the then() clause, you must also return the Promise that the then() is part of.



      In your case, this looks fairly easy. In the searchColleagueByName() function, you would return then once().then().catch() result, which is a Promise. (Since then() and catch() return a Promise.)



      So it might look something like this:



         return firebase_database.ref().once('value')
      .then(team => {
      agent.add("some name " + lastname);
      })
      .catch(err=>{
      agent.add("something wrong");
      })





      share|improve this answer


























        0












        0








        0







        The problem is that, if you're using an async function, then your intent handler must also return a Promise. It isn't enough that you send the reply as part of the then() clause, you must also return the Promise that the then() is part of.



        In your case, this looks fairly easy. In the searchColleagueByName() function, you would return then once().then().catch() result, which is a Promise. (Since then() and catch() return a Promise.)



        So it might look something like this:



           return firebase_database.ref().once('value')
        .then(team => {
        agent.add("some name " + lastname);
        })
        .catch(err=>{
        agent.add("something wrong");
        })





        share|improve this answer













        The problem is that, if you're using an async function, then your intent handler must also return a Promise. It isn't enough that you send the reply as part of the then() clause, you must also return the Promise that the then() is part of.



        In your case, this looks fairly easy. In the searchColleagueByName() function, you would return then once().then().catch() result, which is a Promise. (Since then() and catch() return a Promise.)



        So it might look something like this:



           return firebase_database.ref().once('value')
        .then(team => {
        agent.add("some name " + lastname);
        })
        .catch(err=>{
        agent.add("something wrong");
        })






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 '18 at 21:02









        PrisonerPrisoner

        34.7k33258




        34.7k33258
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53382012%2fwhen-i-use-promise-with-dialogflow-library-in-server-get-error%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Guess what letter conforming each word

            Port of Spain

            Run scheduled task as local user group (not BUILTIN)