简体   繁体   English

Google Actions sdk-无法在Q / A会话后保留app.data

[英]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.

相关问题 AngularJS和C#应用程序:如何遍历app.data文件夹并从中选择元素以在我的HTML页面中使用 - AngularJS and C# app: How to iterate through and select elements from app.data folder for use in my HTML page 对Google Assistant使用Actions SDK - Use Actions SDK for Google Assistant 如何使用Google Actions SDK遍历JS对象数组并在Google Assistant应用中显示列表选择器 - How to iterate over array of js objects and display List Selector in google assistant app using google actions sdk 无法从$ q获取数据到范围 - unable to get data from $q into scope 如何在 Firefox 和 Google Chrome 的 localStorage 中保存数据? - How to persist data in localStorage in Firefox and Google Chrome? sessionStorage数据不会在使用ngStorage的AngularJS应用程序中保留 - sessionStorage data not persist in AngularJS app with ngStorage 在Windows 8应用程序中本地保留数据的最佳方法 - Best Method to persist data locally in Windows 8 app 无法在Chrome App中加载AWS开发工具包 - Unable to load AWS SDK in Chrome App 如何持续跨课程切换课程? - How to persist class toggling across sessions? 跨会话坚持使用ACE编辑器UndoManager - Persist the ACE editor UndoManager across sessions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM