【问题标题】:Bot Framework save user data in the database by UserIDBot Framework 通过 UserID 将用户数据保存在数据库中
【发布时间】:2019-03-22 10:10:39
【问题描述】:

我想保存用户在我的数据库中输入的数据。

我需要一个对于与同一用户的所有对话而不是单个对话都是唯一的 ID。

根据documentation,我需要使用Channel Account数据中的From.ID字段。

但是当我使用 Bot Framework Emulator 并点击 Restart with same User ID 时,用户的 ID 发生了变化,剩下的是机器人 ID。

我应该使用哪个字段来识别不同呼叫中的用户(当然是在同一个频道中)?


在这个例子中,我看到机器人发送的 Recipient.id 标识符没有改变。

这是用户的唯一标识符吗?为什么和From.ID不一样?

对话 1:

来自机器人的消息:

{
  "channelId": "emulator",
  "conversation": {
    "id": "202d2d60-4c7f-11e9-b1fa-8b3537dcca45|livechat"
  },
  "from": {
    "id": "2",
    "name": "Bot",
    "role": "bot"
  },
  "id": "208f2380-4c7f-11e9-98ea-9595460a8f6e",
  "inputHint": "acceptingInput",
  "localTimestamp": "2019-03-22T10:47:30+02:00",
  "locale": "",
  "recipient": {
    "id": "d4d1b5a6-1797-4d2a-b78e-257de71d3a69",
    "role": "user"
  },
  "replyToId": "20559cf0-4c7f-11e9-98ea-9595460a8f6e",
  "serviceUrl": "http://localhost:53634",
  "showInInspector": true,
  "text": "conversationUpdate event detected",
  "timestamp": "2019-03-22T08:47:30.232Z",
  "type": "message"
}

来自用户的消息:

{
  "channelData": {
    "clientActivityID": "15532445742330.iqwrgb646rq",
    "state": "sent"
  },
  "channelId": "emulator",
  "conversation": {
    "id": "202d2d60-4c7f-11e9-b1fa-8b3537dcca45|livechat"
  },
  "entities": [
    {
      "requiresBotState": true,
      "supportsListening": true,
      "supportsTts": true,
      "type": "ClientCapabilities"
    }
  ],
  "from": {
    "id": "r_wg30czmqjt",
    "name": "User",
    "role": "user"
  },
  "id": "6a791af0-4c7f-11e9-98ea-9595460a8f6e",
  "localTimestamp": "2019-03-22T10:49:34+02:00",
  "locale": "",
  "recipient": {
    "id": "2",
    "name": "Bot",
    "role": "bot"
  },
  "serviceUrl": "http://localhost:53634",
  "showInInspector": true,
  "text": "hi",
  "textFormat": "plain",
  "timestamp": "2019-03-22T08:49:34.239Z",
  "type": "message"
}

对话 2(使用相同的用户 ID 重新启动之后):

来自机器人的消息:

{
  "channelId": "emulator",
  "conversation": {
    "id": "a10fba20-4c83-11e9-b1fa-8b3537dcca45|livechat"
  },
  "from": {
    "id": "2",
    "name": "Bot",
    "role": "bot"
  },
  "id": "a15611f0-4c83-11e9-98ea-9595460a8f6e",
  "inputHint": "acceptingInput",
  "localTimestamp": "2019-03-22T11:19:44+02:00",
  "locale": "",
  "recipient": {
    "id": "d4d1b5a6-1797-4d2a-b78e-257de71d3a69",
    "role": "user"
  },
  "replyToId": "a116e610-4c83-11e9-98ea-9595460a8f6e",
  "serviceUrl": "http://localhost:53634",
  "showInInspector": true,
  "text": "conversationUpdate event detected",
  "timestamp": "2019-03-22T09:19:44.271Z",
  "type": "message"
}

来自用户的消息:

{
  "channelData": {
    "clientActivityID": "15532464069120.36lccv6nsg3",
    "state": "sent"
  },
  "channelId": "emulator",
  "conversation": {
    "id": "a10fba20-4c83-11e9-b1fa-8b3537dcca45|livechat"
  },
  "entities": [
    {
      "requiresBotState": true,
      "supportsListening": true,
      "supportsTts": true,
      "type": "ClientCapabilities"
    }
  ],
  "from": {
    "id": "r_xl9pb24o5o",
    "name": "User",
    "role": "user"
  },
  "id": "aed62f90-4c83-11e9-98ea-9595460a8f6e",
  "localTimestamp": "2019-03-22T11:20:06+02:00",
  "locale": "",
  "recipient": {
    "id": "2",
    "name": "Bot",
    "role": "bot"
  },
  "serviceUrl": "http://localhost:53634",
  "showInInspector": true,
  "text": "hi",
  "textFormat": "plain",
  "timestamp": "2019-03-22T09:20:06.921Z",
  "type": "message"
}

【问题讨论】:

    标签: botframework


    【解决方案1】:

    这是模拟器中的一个错误,已通过https://github.com/Microsoft/BotFramework-Emulator/pull/1348 修复

    请确保您的版本 >= 4.3.3:

    此外,如果消息来自模拟器,则 Recipient.Id 是机器人 ID。

    【讨论】:

      【解决方案2】:

      由于机器人不会跟踪或识别用户,这部分取决于您。

      您需要:

      1. 创建捕获用户身份验证的“反向通道”。让机器人访问正在交互或进行对话的用户的用户 ID/用户名。
      2. 当用户登录并验证应用程序时,您识别用户 - 检索它。
      3. 当用户与机器人交互时,您会获得对话 ID - 您已经拥有此 ID。
      4. 将它们捆绑在一个 JSON 对象中,然后存储回云存储、应用存储或 SQL 数据库。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-02-02
        • 2014-02-17
        • 2021-03-08
        • 2017-09-01
        • 2023-04-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多