gpt4 book ai didi

javascript - Google Actions sdk - 无法在问答 session 之外保留 app.data

转载 作者:行者123 更新时间:2023-12-01 02:19:23 25 4
gpt4 key购买 nike

我有一个简单的游戏,我在用户和 GA 之间的 Q/A session 之间传递值。但是,我注意到 app.state 不会将值保留到下一个 session 。

它基本上是询问对/错类型的问题并通过这些问题来检查和验证这些问题。

示例代码

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是特定于 session 的数据,用于维护单个对话的不同步骤之间的状态。

如果您希望给定用户在 session /对话之间保留数据,您可以使用 app.userStorage .

关于javascript - Google Actions sdk - 无法在问答 session 之外保留 app.data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49325418/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com