代码之家  ›  专栏  ›  技术社区  ›  Bill Software Engineer

在Bot框架中,我应该使用什么唯一的ID来保存会话?

  •  2
  • Bill Software Engineer  · 技术社区  · 6 年前

    我想用session.message.address地址.会话id,对吗?

    1 回复  |  直到 6 年前
        1
  •  3
  •   Javier Capello    6 年前

    参考 https://docs.microsoft.com/en-us/azure/bot-service/bot-service-resources-identifiers-guide?view=azure-bot-service-3.0

    每个机器人和用户在每个通道中都有一个帐户。帐户包含标识符(id)和其他非结构化数据,如可选名称。 示例:“from”:{“id”:无名氏@新的名称“,”name“:”无名氏“}

    你应该使用 session.message.user.id 以识别用户。使用会话id是行不通的,因为用户只需重新加载web聊天页面就可以开始与bot的新会话,并生成一个新的会话id。

    编辑

    我写错了会话.from.id以识别用户。正确的方法是 session.message.user用户.id号

    Note that the message object that comes within the session looks like this

    假设用户johndoe正在通过Skype与bot聊天 message.user.id = "john.doe@contoso.com" message.user.name = "John Doe" . 就在这里!您的唯一用户id!

    会话对象如下所示:

    "session": 
    {
        /*...*/
        "message": 
        {
            /*...*/
            "user":
            {
                "id": "john.doe@contoso.com",
                "name": "John Doe"
            }
        }
    }