In Bot Framework, what Unique ID should I use to save session?

Viewed 821

I am using bot framework and I am saving the session.messageAddress so I can send the user a msg later. I want to track each unique user I get. In case if they send me another msg again I will know I have already received a msg from them earlier. What unique ID should I use to identify the user?

I was thinking of using session.message.address.conversation.id, is this correct?

1 Answers

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

Every bot and user has an account within each channel. The account contains an identifier (id) and other informative bot non-structural data, like an optional name. Example: "from": { "id": "john.doe@contoso.com", "name": "John Doe" }

You should use session.message.user.id to identify the user. Using the conversation id won’t work because the user can start a new conversation with the bot by simply reloading the web chat page and a new conversation id will be generated.

Edit

I mistakenly wrote session.from.id to identify the user. The correct way to do it is session.message.user.id!

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

Say that the user John Doe is chatting to the bot through Skype then message.user.id = "john.doe@contoso.com" and message.user.name = "John Doe". And there you have it! your unique user id!

The session object will look like this:

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