Search code examples
botframeworkbotsaccess-token

Identify first sign in with Authentication using AD for Microsoft Bot Framework


I would like to give a login successful message to the user when he sign in for the first time. So i need to identify weather the user have used sign card shown to sign in(user have interacted) or system automatically taken the token itself without user intervention. It will be nice we show a successful message user interaction was there. How i can identify weather there was a user interaction or not?


Solution

  • The answer I found is to find the Activity Type if its event type user have interacted else it’s an automatic signin. You can reverify the connection just established by checking the value of key connectionName in Activity.Value. The following code will help you.

    string output = JsonConvert.SerializeObject(stepContext.Context.Activity.Value, Formatting.Indented);
    if (stepContext.Context.Activity.Type is "event")
    {
          var conName = JsonConvert.DeserializeObject<JObject>(output)["connectionName"].ToString();
          if (conName ==<Your Connection Name>)
          {
          await stepContext.Context.SendActivityAsync(MessageFactory.Text($"You have successfully Signed In"), cancellationToken);
          await stepContext.Context.SendActivityAsync(MessageFactory.Text($"How can I help you?"), cancellationToken);
         }
     }