Search code examples
node.jsdialogflow-es

Need to store parameter values that I get from previous conversation into a variable and merge it dialogflow


The flow :

User: Hi.
Bot: Spell the characters.
User: joh.
Bot: continue.
User: ny.
Bot: continue.
User: thats it.
Bot: Thank you ,johny(joh+ny)

Here, how can I store all the uservalues into a variable and merge them and display to user?I tried using context. I created a globalparameter context that has the values displayed.

For this,I have created 2 intents

First intent: firstnameletters Second intent: Thank you

In Firstintent,

const first_name_letters = async (df,globalParameter) =>{
              
let name=df._request.queryResult.parameters.alphabets;//slot values like joh 
df.setResponseText(("name").replace("name",name).split('').join(' ')+"\n\n"+"continue");
}

The code below when I print globalparameter:

const first_name_letters = async (df,globalParameter) =>{
        console.log("globalparametr ",globalParameter); 
        let name=df._request.queryResult.parameters.alphabets;
        console.log("alphabets",globalParameter.alphabets);
        }

//output of global parameter when I pass "suchi" in the DF console.

    globalparametr  {
      alphabets: 'suchi',
      reqIntent: 'first_name_letters',
      languageCode: 'en',
      'alphabets.original': 'suchi'
    }
alphabets suchi

//output of globalparameter during next time when I pass "itra"
globalparametr before {
  alphabets: 'itra',
  reqIntent: 'first_name_letters',
  languageCode: 'en',
  'alphabets.original': 'itra'
}
alphabets itra

       

Dialogflow: enter image description here

enter image description here

Now,I want to combine "suchitra" and want the bot to display "Thank you suchitra" in the thank you intent.


Solution

  • As confirmed by @lakshmi, to be able to combine the user inputs in an ongoing conversation you can:

    1. Store values of name in a list every time the user provides an input.
    2. Concatenate the values in the list when user is done providing inputs.
    3. Use the concatenated value as response to the user.