how to save state in google action and dialog flow










0















I am very confused by google documentation on dialogflow and actions for google. It looks like I need to mix and match between the two in order to implement some behaviors, like saving state between turns of a conversation. For example, I have a dialog flow intent handler that looks like this



function showCard(agent) {
let conv = agent.conv();
if(!conv) console.log('There is no conv!'); // only assistant will have a conversation
let n = 0;
if(conv)

// do some magic to generate a Card and simple response into _speakText

agent.add( _speakText );

if( conv )
if( !conv.user.storage ) conv.user.storage = ;
conv.data.cardNumber = n;
conv.user.storage.cardNumber = n;
console.log(`set cardNumber to $n`);



It looks like neither conversation or user data ever gets persisted. So how do I save state through the dialogflow API? What am I missing?



Is my confusion in that dialogflow examples demonstrate a different handler for requests/responses over actions on google? (Should I yank out everything related to dialogflow agents?)



--- edit ---



 const WebhookClient = require('dialogflow-fulfillment');
...
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient( request, response );


OR



 const dialogflow = require('actions-on-google');
...
const app = dialogflow();
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);









share|improve this question




























    0















    I am very confused by google documentation on dialogflow and actions for google. It looks like I need to mix and match between the two in order to implement some behaviors, like saving state between turns of a conversation. For example, I have a dialog flow intent handler that looks like this



    function showCard(agent) {
    let conv = agent.conv();
    if(!conv) console.log('There is no conv!'); // only assistant will have a conversation
    let n = 0;
    if(conv)

    // do some magic to generate a Card and simple response into _speakText

    agent.add( _speakText );

    if( conv )
    if( !conv.user.storage ) conv.user.storage = ;
    conv.data.cardNumber = n;
    conv.user.storage.cardNumber = n;
    console.log(`set cardNumber to $n`);



    It looks like neither conversation or user data ever gets persisted. So how do I save state through the dialogflow API? What am I missing?



    Is my confusion in that dialogflow examples demonstrate a different handler for requests/responses over actions on google? (Should I yank out everything related to dialogflow agents?)



    --- edit ---



     const WebhookClient = require('dialogflow-fulfillment');
    ...
    exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
    const agent = new WebhookClient( request, response );


    OR



     const dialogflow = require('actions-on-google');
    ...
    const app = dialogflow();
    exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);









    share|improve this question


























      0












      0








      0








      I am very confused by google documentation on dialogflow and actions for google. It looks like I need to mix and match between the two in order to implement some behaviors, like saving state between turns of a conversation. For example, I have a dialog flow intent handler that looks like this



      function showCard(agent) {
      let conv = agent.conv();
      if(!conv) console.log('There is no conv!'); // only assistant will have a conversation
      let n = 0;
      if(conv)

      // do some magic to generate a Card and simple response into _speakText

      agent.add( _speakText );

      if( conv )
      if( !conv.user.storage ) conv.user.storage = ;
      conv.data.cardNumber = n;
      conv.user.storage.cardNumber = n;
      console.log(`set cardNumber to $n`);



      It looks like neither conversation or user data ever gets persisted. So how do I save state through the dialogflow API? What am I missing?



      Is my confusion in that dialogflow examples demonstrate a different handler for requests/responses over actions on google? (Should I yank out everything related to dialogflow agents?)



      --- edit ---



       const WebhookClient = require('dialogflow-fulfillment');
      ...
      exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
      const agent = new WebhookClient( request, response );


      OR



       const dialogflow = require('actions-on-google');
      ...
      const app = dialogflow();
      exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);









      share|improve this question
















      I am very confused by google documentation on dialogflow and actions for google. It looks like I need to mix and match between the two in order to implement some behaviors, like saving state between turns of a conversation. For example, I have a dialog flow intent handler that looks like this



      function showCard(agent) {
      let conv = agent.conv();
      if(!conv) console.log('There is no conv!'); // only assistant will have a conversation
      let n = 0;
      if(conv)

      // do some magic to generate a Card and simple response into _speakText

      agent.add( _speakText );

      if( conv )
      if( !conv.user.storage ) conv.user.storage = ;
      conv.data.cardNumber = n;
      conv.user.storage.cardNumber = n;
      console.log(`set cardNumber to $n`);



      It looks like neither conversation or user data ever gets persisted. So how do I save state through the dialogflow API? What am I missing?



      Is my confusion in that dialogflow examples demonstrate a different handler for requests/responses over actions on google? (Should I yank out everything related to dialogflow agents?)



      --- edit ---



       const WebhookClient = require('dialogflow-fulfillment');
      ...
      exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
      const agent = new WebhookClient( request, response );


      OR



       const dialogflow = require('actions-on-google');
      ...
      const app = dialogflow();
      exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);






      node.js dialogflow actions-on-google






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 '18 at 19:25







      Micromuncher

















      asked Nov 13 '18 at 7:56









      MicromuncherMicromuncher

      475114




      475114






















          1 Answer
          1






          active

          oldest

          votes


















          1














          You can save the data in the session with the conversationToken. You can access to conversationToken through the conversational interface “conv.data” and then type the names of the parameters that you want to store. For example:



          Example to use conversationToken



          Through it you can save the data that you require to be kept in the same session of your Action. This also applies when you send a conversation from one device to another (newSurface). But if you close your action, the session data will be lost.






          share|improve this answer























          • I thought I did this in my pattern, but it is not persisted. I've added an example of how I set up the request handler. Dialogflow uses a webhook client (in the agent). Your example looks tuned to using a dialogflow object (in app). Can you mix patterns? agents.add vs conv.ask ?

            – Micromuncher
            Nov 13 '18 at 19:28











          • But your indicated pattern looks like you're using the previous version of the Google Assistant SDK. Regardless of the pattern, Google Assistant split the app object into a global app instance (that represents the Action itself) and a per conversation conv instance. I recommend you to separate these instances in order to have a specific context for Intent and thus save the data you need from the conv interface.

            – Carlo Renzo
            Nov 13 '18 at 22:38











          • Clearing out the V1 / Dialogflow SDK calls fixed the issue. It looks like the Dialogflow doc and the boilerplate webhook need to all be updated to V2. Thanks a ton for your help.

            – Micromuncher
            Nov 14 '18 at 14:44











          • And this parameter we are saving in contexts will be lost after the lifespan of context, right? How can we save data throughout one conversation, just like conv.data in case of actions-on-google conversation object?

            – AkshayM
            Dec 14 '18 at 17:57











          • In that case you have two options, if you want to manage data outside of the conversation you have the "userStorage" to which you can access like this: conv.user.storage, with it you can save data inside the device even when your conversation is finished until it is invoked again. On the other hand, if you want to keep information between users and synchronized, I recommend you to use firebasestore to have something more structured.

            – Carlo Renzo
            Dec 14 '18 at 18:02










          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%2f53276281%2fhow-to-save-state-in-google-action-and-dialog-flow%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









          1














          You can save the data in the session with the conversationToken. You can access to conversationToken through the conversational interface “conv.data” and then type the names of the parameters that you want to store. For example:



          Example to use conversationToken



          Through it you can save the data that you require to be kept in the same session of your Action. This also applies when you send a conversation from one device to another (newSurface). But if you close your action, the session data will be lost.






          share|improve this answer























          • I thought I did this in my pattern, but it is not persisted. I've added an example of how I set up the request handler. Dialogflow uses a webhook client (in the agent). Your example looks tuned to using a dialogflow object (in app). Can you mix patterns? agents.add vs conv.ask ?

            – Micromuncher
            Nov 13 '18 at 19:28











          • But your indicated pattern looks like you're using the previous version of the Google Assistant SDK. Regardless of the pattern, Google Assistant split the app object into a global app instance (that represents the Action itself) and a per conversation conv instance. I recommend you to separate these instances in order to have a specific context for Intent and thus save the data you need from the conv interface.

            – Carlo Renzo
            Nov 13 '18 at 22:38











          • Clearing out the V1 / Dialogflow SDK calls fixed the issue. It looks like the Dialogflow doc and the boilerplate webhook need to all be updated to V2. Thanks a ton for your help.

            – Micromuncher
            Nov 14 '18 at 14:44











          • And this parameter we are saving in contexts will be lost after the lifespan of context, right? How can we save data throughout one conversation, just like conv.data in case of actions-on-google conversation object?

            – AkshayM
            Dec 14 '18 at 17:57











          • In that case you have two options, if you want to manage data outside of the conversation you have the "userStorage" to which you can access like this: conv.user.storage, with it you can save data inside the device even when your conversation is finished until it is invoked again. On the other hand, if you want to keep information between users and synchronized, I recommend you to use firebasestore to have something more structured.

            – Carlo Renzo
            Dec 14 '18 at 18:02















          1














          You can save the data in the session with the conversationToken. You can access to conversationToken through the conversational interface “conv.data” and then type the names of the parameters that you want to store. For example:



          Example to use conversationToken



          Through it you can save the data that you require to be kept in the same session of your Action. This also applies when you send a conversation from one device to another (newSurface). But if you close your action, the session data will be lost.






          share|improve this answer























          • I thought I did this in my pattern, but it is not persisted. I've added an example of how I set up the request handler. Dialogflow uses a webhook client (in the agent). Your example looks tuned to using a dialogflow object (in app). Can you mix patterns? agents.add vs conv.ask ?

            – Micromuncher
            Nov 13 '18 at 19:28











          • But your indicated pattern looks like you're using the previous version of the Google Assistant SDK. Regardless of the pattern, Google Assistant split the app object into a global app instance (that represents the Action itself) and a per conversation conv instance. I recommend you to separate these instances in order to have a specific context for Intent and thus save the data you need from the conv interface.

            – Carlo Renzo
            Nov 13 '18 at 22:38











          • Clearing out the V1 / Dialogflow SDK calls fixed the issue. It looks like the Dialogflow doc and the boilerplate webhook need to all be updated to V2. Thanks a ton for your help.

            – Micromuncher
            Nov 14 '18 at 14:44











          • And this parameter we are saving in contexts will be lost after the lifespan of context, right? How can we save data throughout one conversation, just like conv.data in case of actions-on-google conversation object?

            – AkshayM
            Dec 14 '18 at 17:57











          • In that case you have two options, if you want to manage data outside of the conversation you have the "userStorage" to which you can access like this: conv.user.storage, with it you can save data inside the device even when your conversation is finished until it is invoked again. On the other hand, if you want to keep information between users and synchronized, I recommend you to use firebasestore to have something more structured.

            – Carlo Renzo
            Dec 14 '18 at 18:02













          1












          1








          1







          You can save the data in the session with the conversationToken. You can access to conversationToken through the conversational interface “conv.data” and then type the names of the parameters that you want to store. For example:



          Example to use conversationToken



          Through it you can save the data that you require to be kept in the same session of your Action. This also applies when you send a conversation from one device to another (newSurface). But if you close your action, the session data will be lost.






          share|improve this answer













          You can save the data in the session with the conversationToken. You can access to conversationToken through the conversational interface “conv.data” and then type the names of the parameters that you want to store. For example:



          Example to use conversationToken



          Through it you can save the data that you require to be kept in the same session of your Action. This also applies when you send a conversation from one device to another (newSurface). But if you close your action, the session data will be lost.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 17:11









          Carlo RenzoCarlo Renzo

          1039




          1039












          • I thought I did this in my pattern, but it is not persisted. I've added an example of how I set up the request handler. Dialogflow uses a webhook client (in the agent). Your example looks tuned to using a dialogflow object (in app). Can you mix patterns? agents.add vs conv.ask ?

            – Micromuncher
            Nov 13 '18 at 19:28











          • But your indicated pattern looks like you're using the previous version of the Google Assistant SDK. Regardless of the pattern, Google Assistant split the app object into a global app instance (that represents the Action itself) and a per conversation conv instance. I recommend you to separate these instances in order to have a specific context for Intent and thus save the data you need from the conv interface.

            – Carlo Renzo
            Nov 13 '18 at 22:38











          • Clearing out the V1 / Dialogflow SDK calls fixed the issue. It looks like the Dialogflow doc and the boilerplate webhook need to all be updated to V2. Thanks a ton for your help.

            – Micromuncher
            Nov 14 '18 at 14:44











          • And this parameter we are saving in contexts will be lost after the lifespan of context, right? How can we save data throughout one conversation, just like conv.data in case of actions-on-google conversation object?

            – AkshayM
            Dec 14 '18 at 17:57











          • In that case you have two options, if you want to manage data outside of the conversation you have the "userStorage" to which you can access like this: conv.user.storage, with it you can save data inside the device even when your conversation is finished until it is invoked again. On the other hand, if you want to keep information between users and synchronized, I recommend you to use firebasestore to have something more structured.

            – Carlo Renzo
            Dec 14 '18 at 18:02

















          • I thought I did this in my pattern, but it is not persisted. I've added an example of how I set up the request handler. Dialogflow uses a webhook client (in the agent). Your example looks tuned to using a dialogflow object (in app). Can you mix patterns? agents.add vs conv.ask ?

            – Micromuncher
            Nov 13 '18 at 19:28











          • But your indicated pattern looks like you're using the previous version of the Google Assistant SDK. Regardless of the pattern, Google Assistant split the app object into a global app instance (that represents the Action itself) and a per conversation conv instance. I recommend you to separate these instances in order to have a specific context for Intent and thus save the data you need from the conv interface.

            – Carlo Renzo
            Nov 13 '18 at 22:38











          • Clearing out the V1 / Dialogflow SDK calls fixed the issue. It looks like the Dialogflow doc and the boilerplate webhook need to all be updated to V2. Thanks a ton for your help.

            – Micromuncher
            Nov 14 '18 at 14:44











          • And this parameter we are saving in contexts will be lost after the lifespan of context, right? How can we save data throughout one conversation, just like conv.data in case of actions-on-google conversation object?

            – AkshayM
            Dec 14 '18 at 17:57











          • In that case you have two options, if you want to manage data outside of the conversation you have the "userStorage" to which you can access like this: conv.user.storage, with it you can save data inside the device even when your conversation is finished until it is invoked again. On the other hand, if you want to keep information between users and synchronized, I recommend you to use firebasestore to have something more structured.

            – Carlo Renzo
            Dec 14 '18 at 18:02
















          I thought I did this in my pattern, but it is not persisted. I've added an example of how I set up the request handler. Dialogflow uses a webhook client (in the agent). Your example looks tuned to using a dialogflow object (in app). Can you mix patterns? agents.add vs conv.ask ?

          – Micromuncher
          Nov 13 '18 at 19:28





          I thought I did this in my pattern, but it is not persisted. I've added an example of how I set up the request handler. Dialogflow uses a webhook client (in the agent). Your example looks tuned to using a dialogflow object (in app). Can you mix patterns? agents.add vs conv.ask ?

          – Micromuncher
          Nov 13 '18 at 19:28













          But your indicated pattern looks like you're using the previous version of the Google Assistant SDK. Regardless of the pattern, Google Assistant split the app object into a global app instance (that represents the Action itself) and a per conversation conv instance. I recommend you to separate these instances in order to have a specific context for Intent and thus save the data you need from the conv interface.

          – Carlo Renzo
          Nov 13 '18 at 22:38





          But your indicated pattern looks like you're using the previous version of the Google Assistant SDK. Regardless of the pattern, Google Assistant split the app object into a global app instance (that represents the Action itself) and a per conversation conv instance. I recommend you to separate these instances in order to have a specific context for Intent and thus save the data you need from the conv interface.

          – Carlo Renzo
          Nov 13 '18 at 22:38













          Clearing out the V1 / Dialogflow SDK calls fixed the issue. It looks like the Dialogflow doc and the boilerplate webhook need to all be updated to V2. Thanks a ton for your help.

          – Micromuncher
          Nov 14 '18 at 14:44





          Clearing out the V1 / Dialogflow SDK calls fixed the issue. It looks like the Dialogflow doc and the boilerplate webhook need to all be updated to V2. Thanks a ton for your help.

          – Micromuncher
          Nov 14 '18 at 14:44













          And this parameter we are saving in contexts will be lost after the lifespan of context, right? How can we save data throughout one conversation, just like conv.data in case of actions-on-google conversation object?

          – AkshayM
          Dec 14 '18 at 17:57





          And this parameter we are saving in contexts will be lost after the lifespan of context, right? How can we save data throughout one conversation, just like conv.data in case of actions-on-google conversation object?

          – AkshayM
          Dec 14 '18 at 17:57













          In that case you have two options, if you want to manage data outside of the conversation you have the "userStorage" to which you can access like this: conv.user.storage, with it you can save data inside the device even when your conversation is finished until it is invoked again. On the other hand, if you want to keep information between users and synchronized, I recommend you to use firebasestore to have something more structured.

          – Carlo Renzo
          Dec 14 '18 at 18:02





          In that case you have two options, if you want to manage data outside of the conversation you have the "userStorage" to which you can access like this: conv.user.storage, with it you can save data inside the device even when your conversation is finished until it is invoked again. On the other hand, if you want to keep information between users and synchronized, I recommend you to use firebasestore to have something more structured.

          – Carlo Renzo
          Dec 14 '18 at 18:02

















          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%2f53276281%2fhow-to-save-state-in-google-action-and-dialog-flow%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

          27

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          Category:Rhetoric