Get the user's profile and contextual information


This document provides details about obtaining user information for skills built using the Microsoft Bot Framework.

Cortana can provide the user's profile and contextual information as part of the data that it makes available to your skill. You can use this information to build a custom experience for the user.

User profile information is data that the user provided to Cortana that's stored in Cortana's Notebook. Cortana passes this information to your skill if it's available, and if the user has provided explicit consent to share this information with your skill. Your skill must have a valid reason to use profile information in order to pass certification. See the Skill review guidelines for more details.

User contextual information is information that Cortana has about the user, such as their location.

To receive this information, you must specify the type of user data that you want when you configure your Cortana channel (see the Request user profile data section in the Connect a bot to Cortana) page.

The sample code shows how to access userInfo.Properties in order to retrieve the user's email address (which is profile info) and location (which is contextual info). The examples assume that UserEmail and CurrentLocation were used as the property's friendly names during the channel configuration.

    var userInfo = turnContext.Activity.Entities?.FirstOrDefault(entity => entity.Type.Equals("UserInfo", StringComparison.Ordinal));
    if(userInfo != null)
        var email = userInfo.Properties.Value<string>("UserEmail");

        if (!string.IsNullOrEmpty(email))
            //Do something with the user's email address.

        var currentLocation = userInfo.Properties["CurrentLocation"];

        if (currentLocation != null)
            var hub = currentLocation["Hub"];

            //Access the latitude and longitude values of the user's location.
            var lat = hub.Value<double>("Latitude");
            var lon = hub.Value<double>("Longitude");

            //Do something with the user's location information.