2

类似于DialogFlow V2 用户 ID?我正在使用来自 conv.user.id (dialogflow v2) 的用户 ID 来(匿名)确定我的 Dialogflow 应用程序中的用户。但是,我收到日志消息:

 conv.user.id is *DEPRECATED*: Use conv.user.storage to store data instead 

这是否意味着我(很快)将无法再访问用户 ID?我知道我可以将数据存储在 conv.user.storage 中,但我需要 id - 而不是存储。

任何人都想过如何对此进行故障保护?

// 代码片段:

app.intent('Default Welcome Intent', conv => {
  var userID = conv.user.id;
  // do something
});
4

1 回答 1

6

匿名用户身份已被弃用,将从 2019 年 6 月 1 日(一年后)开始正式删除。所以你的代码片段将开始失败。

修复取决于您使用 id 的确切方式和原因,但对于最基本的需求,您可以执行以下操作:

  1. 检查您是否在 userStore 中存储了一个 id。如果您有 - 使用此 ID。

  2. 如果您还没有,请生成一个 id(生成 UUID 是一种很好的方法),将其用作您的 id,并将其存储在 userStore 中以供将来参考。

执行此操作的代码可能如下所示:

if ('userId' in conv.user.storage) {
  userId = conv.user.storage.userId;
} else {
  // generateUUID is your function to generate ids.
  userId = generateUUID();
  conv.user.storage.userId = userId
}

或者,您可能希望只计划为助手使用 Google 登录,这将为您获取 Google 用户 ID。

编辑: 应引用条件中的 userId。

于 2018-06-01T11:48:33.650 回答