'Dialogflow, agent.add("My message") does not execute

I am playing around with dialogflow action. I have one intent that asks for three questions and then I do REST call to my low-code platform with the responses from the users. Everything looks fine and I get the result back nice and tidy to my own platform. But I want to inform the user that I have accepted the call and created the object. Therefore in my REST response I have a QuoteName and a QuoteNr that I would like to send to the agent to display to the user as the end of conversation.

Before I do this I put this information into the console.log() and I can see that it is printed in the log.

Log from dialogflow

But my dialogflows response is "XXXXX can't respond right now, please try again later." even if I got the REST call and everything working as supposed???

What is going on here?

Here is my inline editor code:

// See https://github.com/dialogflow/dialogflow-fulfillment-nodejs
// for Dialogflow fulfillment library docs, samples, and to report issues

'use strict';



const axios = require('axios');
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');

 
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
 
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  const agent = new WebhookClient({ request, response });
  console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
  console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
 
  function Auth() {
    console.log("Getting the token");
    axios.post('https://b4c5e131-eff9-44e0-a8dc-3764f17a1220.app.flowfactory.se/Auth/[email protected]&password=APassword', {
        params: {
        }
    })
    .then((response) => {
        let upload = indoor(response.data.AccessToken, agent);
    })
    .catch(function(error) {
    console.log(error);
  });
}
  function indoor(token, agent){
  console.log("Making the call againts indoor");
    
    const config = {
    headers: { Authorization: 'Bearer ' + token, }
};

const bodyParameters = {
   Customer: agent.parameters.customer,
  Value: agent.parameters.quotevalue, 
  Description: agent.parameters.description
};

axios
 .post( 
  'https://b4c5e131-eff9-44e0-a8dc-3764f17a1220.app.flowfactory.se/externalapi/V1/QuickQuote/CreateQuickQuote',
  bodyParameters,
  config
).then((response) => {
    console.log(response.data.QuoteName + " - " + response.data.QuoteNr);
   let msgToUser = theResponseBack(response.data.QuoteName, response.data.QuoteNr, agent);
   agent.add("Skapade ett utkast av en offert åt dig i system.");
  })
  .catch(function(error) {
    console.log(error);
  });
}
  function theResponseBack(qName,qNr, agent) {
    console.log("Sending message back to user");
    agent.add("Skapade offert " + qName + " - " + qNr);
  }
  let intentMap = new Map();
  intentMap.set('QuickQuote', Auth);
  agent.handleRequest(intentMap);
});


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source