[英]Google Actions sdk - Unable to persist app.data beyond Q/A sessions
I have a simple game where I am passing values between Q/A sessions between the user and GA. 我有一个简单的游戏,我在用户和GA之间的Q / A会话之间传递值。 However, I have noticed that the app.state is not maintaining values to the next session.
但是,我注意到app.state不会维护下一个会话的值。
It's basically asking True/False type questions and passing those to check and validate for those. 它基本上是在询问对/错类型的问题,并将这些问题传递给检查和验证。
Sample Code 样例代码
exports.myQNAFunction = functions.https.onRequest((request, response) => {
// get an instance of the Google Actions SDK
const app = new ActionsSdkApp({request: request, response: response});
app.data = {answer: ''}
// Function to handle the built in intents
function handleBuiltInIntent (app) {
// Get dialog state to know where we are in the conversation
var dialogState = app.getDialogState();
// get our custom parameter
var stage = dialogState.stage;
console.info('handleBuiltInIntent: ' + stage);
console.info('app.data.answer: ' + app.data.answer);
// Check where we are in the conversation
if(stage === 1) {
console.info("block stage 1 ")
let rawInput = app.getRawInput();
if(rawInput === 'ok' || rawInput === 'yes' || rawInput === 'sure') {
// user wants to know more
app.tell('Ok then, here are the instructions!');
} else if(rawInput === 'no') {
dialogState.stage = 2;
let question = getNextQuestion();
let answer = qna_object_dict[question];
app.data.answer = answer
app.ask(question, dialogState);
} else {
// we finish the dialog
app.tell('Ok then, goodbye!');
}
} else if(stage === 2) {
console.info("block stage 2 ")
let rawInput = app.getRawInput();
if (rawInput === app.data.answer) {
console.info(app.data.answer)
dialogState.stage = 2;
let question = getNextQuestion();
let answer = qna_object_dict[question];
app.data.answer = answer
app.ask(question, dialogState);
} else {
app.tell('Wong Answer, goodbye!');
}
} else {
// Build a prompt
console.info("block stage 0 ")
let welcome_string = welcomePrompt()
let inputPrompt = app.buildInputPrompt(false,
welcome_string);
dialogState.stage = 1;
app.ask(inputPrompt, dialogState);
}
}
});
app.data
is meant to be session-specific data, to maintain state between different steps of a single conversation. app.data
是特定于会话的数据,用于维护单个对话的不同步骤之间的状态。
If you want data to persist for a given user between sessions/conversations, you can use the app.userStorage
. 如果您希望数据在会话/会话之间持久存在,可以使用
app.userStorage
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.