how to save state in google action and dialog flow
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
add a comment |
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
add a comment |
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
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
node.js dialogflow actions-on-google
edited Nov 13 '18 at 19:25
Micromuncher
asked Nov 13 '18 at 7:56
MicromuncherMicromuncher
475114
475114
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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:

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.
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 likeconv.datain case ofactions-on-googleconversationobject?
– 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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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:

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.
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 likeconv.datain case ofactions-on-googleconversationobject?
– 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
add a comment |
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:

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.
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 likeconv.datain case ofactions-on-googleconversationobject?
– 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
add a comment |
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:

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.
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:

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.
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 likeconv.datain case ofactions-on-googleconversationobject?
– 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
add a comment |
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 likeconv.datain case ofactions-on-googleconversationobject?
– 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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