You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在新版Dialogflow V2 API中使用userStorage?

Dialogflow API V2: Working with User Storage (Compared to V1)

First, let's recap the simple approach you already know from V1 since that's your baseline:

  • Setting a stored value: app.userStorage.favoriteColor = 'blue';
  • Retrieving it later: let myFavoriteColor = app.userStorage.favoriteColor;

Now for V2, the logic is almost identical—you just use the conv object instead of app. Here's how to replicate that functionality step by step:

Storing Data in V2

In your intent handler, use conv.user.storage to save custom values. For example, storing a favorite color would look like this:

app.intent('set_favorite_color', (conv) => {
  // Assume we've pulled the color from user input here
  const userColor = 'blue';
  conv.user.storage.favoriteColor = userColor;
  conv.close(`Got it! I'll remember your favorite color is ${userColor}.`);
});

Retrieving Stored Data in V2

In any subsequent session or intent, you can fetch that saved value using the same conv.user.storage object:

app.intent('get_favorite_color', (conv) => {
  const savedColor = conv.user.storage.favoriteColor;
  if (savedColor) {
    conv.close(`Your favorite color is ${savedColor}, right?`);
  } else {
    conv.ask(`I don't remember your favorite color yet—what is it?`);
  }
});

Quick Key Notes

  • Just like V1, conv.user.storage persists across sessions for the same user, so your data stays intact between interactions.
  • The structure is nearly a 1:1 swap—V1 uses app.userStorage, V2 uses conv.user.storage (notice the extra dot between user and storage).
  • That weather report example you saw with conv.user.storage.zip follows this exact pattern—you can store any custom property you need here, not just zip codes or colors.

内容的提问来源于stack exchange,提问作者Geoff

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:14:47