Denis Kislinskiy
Denis Kislinskiy

Reputation: 39

Dialogflow - Dynamic text response

How can I set dynamic args in Text response? not from user phrases

I have a case:

bot says: "Do you find a work?"

user says: "Yes"

Text response:

bot says: "I can offer you vacancy {random vacancy}"

Upvotes: 1

Views: 1607

Answers (2)

Alex Riquelme
Alex Riquelme

Reputation: 1554

You can't do it with a default text response, in fact, you need to enable webhook call for that intent in the fulfillment section. I'll show you how my intent looks like. enter image description here

Here you have the webhook code:

'use strict';
const http = require('http');


const request2 = require('request');

exports.dialogflowFirebaseFulfillment = (req, res) => {
  console.log('Dialogflow Request body: ' + JSON.stringify(req.body));
  
  let action = req.body.queryResult['intent']['displayName'];
  switch(action){
    case "work":
        // Get the city from a database
        let city="Randomcity";
        // Get the job from a database
        let job="randomjob";
        res.send(JSON.stringify({ 'fulfillmentText': "I can offer you this fantastic job in "+city+" city, doing "+job}));
               
          
    break;
    
    //Add more cases if you have more intents
    }
    
  
    
}

And this is the result:

enter image description here

Upvotes: 3

sid8491
sid8491

Reputation: 6800

There are two cases :
1. If you want to return random arguments, then you can simply set all possible arguments in the responses and DialogFlow will randomly select a response a send it to user.

enter image description here

  1. If the arguments are based on some criteria, then you need to enable webhook and you need to return the response from the webhook. This is the recommended option. And this is how fulfillment works.

Hope it helps.

Upvotes: 1

Related Questions