התכונה 'פעולות שיחה' הוצאה משימוש ב-13 ביוני 2023.
כאן תוכלו לקרוא מידע נוסף על ההוצאה משימוש של 'פעולות שיחה'.
אחסון ביקור
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
אפשר לשמור ערכי פרמטרים של משתמש ספציפי בשיחה
אחסון סשן. לאחר מכן הפעולה תוכל להשתמש בערכים המאוחסנים האלה מאוחר יותר בהנחיות
ותנאים נוספים, וקוד ה-webhook יכול לגשת לערכים באחסון הסשנים
את השיחה, כשצריך.
במהלך שיחה, נתונים שנאספים באמצעות סוגים נשמרים במהלך הסשן
אחסון. אפשר גם להשתמש בקריאות לפעולה מאתר אחר (webhook) כדי לבצע אינטראקציה עם הנתונים באחסון הסשנים.
בשיחות webhook, המצב של אחסון הסשנים מועבר באמצעות app.handle()
ושמור באובייקט session
.
התוקף של הנתונים שמאוחסנים בנפח האחסון של הסשן יפוג בסיום השיחה.
קריאה וכתיבה של נתונים באחסון הסשנים
כדי לעדכן או להגדיר ערך חדש באחסון לסשנים, מקצים את הערך
השדה params
באובייקט session
בקריאת תגובה לפעולה מאתר אחר (webhook). הדוגמה הבאה
מגדירה את "exampleColor" ל"אדום" באחסון לסשן:
Node.js
// Assign color to session storage
app.handle('storeColor', conv => {
let color = 'red';
conv.session.params.exampleColor = color;
});
JSON
{
"responseJson": {
"session": {
"id": "12345678901234567890",
"params": {
"exampleColor": "red"
}
},
"prompt": {
"override": false
}
}
}
כדי לגשת לנתונים שמאוחסנים באחסון לסשנים, יש להקצות אותם למשתנה ב-webhook
שיחה. הדוגמה הבאה מאחזרת ערך מ-'exampleColor' סשן
אחסון:
Node.js
// Retrieve color from session storage
app.handle('getStoredColor', conv => {
let color = conv.session.params.exampleColor;
});
JSON
{
"responseJson": {
"session": {
"id": "12345678901234567890",
"params": {
"exampleColor": "red"
}
},
"prompt": {
"override": false
}
}
}
כדי למחוק ערך שנשמר בעבר, צריך להגדיר את הערך כ-null
בשיחת תגובה לפעולה מאתר אחר (webhook).
הדוגמה הבאה מנקה את הערך של 'exampleColor' באחסון לסשן:
Node.js
// Clear color from session storage
app.handle('clearStoredColor', conv => {
conv.session.params.exampleColor = null;
});
JSON
{
"responseJson": {
"session": {
"id": "12345678901234567890",
"params": {}
},
"prompt": {
"override": false
}
}
}
הפניה לערכים מאוחסנים בהנחיות
אתם יכולים להפנות לערכים שמאוחסנים באחסון הסשן בהודעה. כדי להפנות אל
צריך להשתמש בתחביר $session.params.PARAMETER_NAME
, כאשר
PARAMETER_NAME
הוא השם שניתן ב-webhook כשהפרמטר
הוגדרה.
לדוגמה, בעבר אחסנתם ערך צבע באחסון הסשן
הפרמטר exampleColor
. כדי לגשת לערך הזה בהנחיה, אתם מפנים אל
ערך באמצעות $session.params.exampleColor
:
JSON
{
"candidates": [{
"first_simple": {
"variants": [{
"speech": "Your favorite color is $session.params.exampleColor."
}]
}
}]
}
הפניה לערכים מאוחסנים בתוך תנאים
אפשר גם להפנות לערכים שמאוחסנים באחסון של סשנים בתנאים. שפת תרגום
בהפניה לערך, משתמשים בפונקציה session.params.PARAMETER_NAME
תחביר, כאשר PARAMETER_NAME
הוא השם שניתן ב-webhook כאשר
הפרמטר הוגדר.
לדוגמה, בעבר אחסנתם ערך צבע באחסון הסשן
הפרמטר exampleColor
, וצריך להתאים אותו לערך "red" תוך שימוש
תנאי. בתנאי שלכם, אתם מפנים לערך המאוחסן באמצעות
session.params.exampleColor
ביטוי התנאי ייראה כך:
תחביר של תנאים
session.params.exampleColor == "red"
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-26 (שעון UTC).
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-07-26 (שעון UTC)."],[[["\u003cp\u003eYou can utilize session storage to save user-specific parameter values during a conversation, enabling your Action to reuse them in prompts and conditions, and your webhook code to access them when needed.\u003c/p\u003e\n"],["\u003cp\u003eSession storage automatically stores data gathered using types during a conversation, and you can interact with this data via webhook calls using the \u003ccode\u003esession\u003c/code\u003e object.\u003c/p\u003e\n"],["\u003cp\u003eTo modify or add values in session storage, assign them to the \u003ccode\u003eparams\u003c/code\u003e field of the \u003ccode\u003esession\u003c/code\u003e object within a webhook call; to retrieve them, assign them to a variable within a webhook call.\u003c/p\u003e\n"],["\u003cp\u003eStored values in session storage can be referenced in prompts using the \u003ccode\u003e$session.params.<PARAMETER_NAME>\u003c/code\u003e syntax and in conditions using the \u003ccode\u003esession.params.<PARAMETER_NAME>\u003c/code\u003e syntax.\u003c/p\u003e\n"],["\u003cp\u003eData stored in session storage is ephemeral and automatically deleted when the conversation concludes.\u003c/p\u003e\n"]]],[],null,["You can store parameter values for a specific user within a conversation in\nsession storage. Your Action can then use those stored values later in prompts\nand conditions, and your webhook code can access values in session storage for\nthe conversation when necessary.\n\nDuring a conversation, any data collected using [types](/assistant/conversational/types) is stored in session\nstorage. You can also interact with data in session storage using webhook calls.\nFor webhook calls, the state of session storage is passed in an `app.handle()`\nrequest and is stored in the [`session`](/assistant/conversational/reference/rest/v1/TopLevel/fulfill#Session) object.\n\nData stored in session storage expires when a conversation ends.\n\nRead and write data to session storage\n\nTo update or set a new value in session storage, assign the value to the\n`params` field of the `session` object in a webhook call. The following example\nsets \"exampleColor\" to \"red\" in session storage: \n\nNode.js \n\n```javascript\n// Assign color to session storage\napp.handle('storeColor', conv =\u003e {\n let color = 'red';\n conv.session.params.exampleColor = color;\n});\n \n```\n\nJSON \n\n```text\n{\n \"responseJson\": {\n \"session\": {\n \"id\": \"12345678901234567890\",\n \"params\": {\n \"exampleColor\": \"red\"\n }\n },\n \"prompt\": {\n \"override\": false\n }\n }\n}\n \n```\n\nTo access data stored in session storage, assign it to a variable in a webhook\ncall. The following example retrieves a value from \"exampleColor\" in session\nstorage: \n\nNode.js \n\n```javascript\n// Retrieve color from session storage\napp.handle('getStoredColor', conv =\u003e {\n let color = conv.session.params.exampleColor;\n});\n \n```\n\nJSON \n\n```text\n{\n \"responseJson\": {\n \"session\": {\n \"id\": \"12345678901234567890\",\n \"params\": {\n \"exampleColor\": \"red\"\n }\n },\n \"prompt\": {\n \"override\": false\n }\n }\n}\n \n```\n\nTo clear a previously saved value, set the value to `null` in a webhook call.\nThe following example clears the value of \"exampleColor\" in session storage: \n\nNode.js \n\n```javascript\n// Clear color from session storage\napp.handle('clearStoredColor', conv =\u003e {\n conv.session.params.exampleColor = null;\n});\n \n```\n\nJSON \n\n```text\n{\n \"responseJson\": {\n \"session\": {\n \"id\": \"12345678901234567890\",\n \"params\": {}\n },\n \"prompt\": {\n \"override\": false\n }\n }\n}\n \n```\n\nReference stored values within prompts\n\nYou can reference values stored in session storage in a [prompt](/assistant/conversational/prompts). To reference the\nvalue, use `$session.params.`\u003cvar translate=\"no\"\u003ePARAMETER_NAME\u003c/var\u003e syntax, where\n\u003cvar translate=\"no\"\u003ePARAMETER_NAME\u003c/var\u003e is the name given in the webhook when the parameter\nwas set.\n\nFor example, you previously stored a color value in session storage as the\nparameter `exampleColor`. To access that value in a prompt, you reference that\nvalue using `$session.params.exampleColor`: \n\nJSON \n\n```gdscript\n{\n \"candidates\": [{\n \"first_simple\": {\n \"variants\": [{\n \"speech\": \"Your favorite color is $session.params.exampleColor.\"\n }]\n }\n }]\n}\n \n```\n\nReference stored values within conditions\n\nYou can also reference values stored in session storage in [conditions](/assistant/conversational/conditions). To\nreference the value, use the `session.params.`\u003cvar translate=\"no\"\u003ePARAMETER_NAME\u003c/var\u003e\nsyntax, where \u003cvar translate=\"no\"\u003ePARAMETER_NAME\u003c/var\u003e is the name given in the webhook when\nthe parameter was set.\n\nFor example, you previously stored a color value in session storage as the\nparameter `exampleColor`, and you want to match it with the value \"red\" in a\ncondition. In your condition, you reference the stored value using\n`session.params.exampleColor`. Your condition expression then looks like this: \n\nCondition syntax \n\n```text\nsession.params.exampleColor == \"red\"\n \n```"]]