1
votes

A bot is being developed using AAD authentication, in which we have chosen directline as our channel. Now, we have tried displaying the username of the authenticated person in the place of userid in the below snippet.

<script>
BotChat.App({
    directLine: { secret: "***********" },
    user: { id: 'userid' },
    bot: { id: 'botid' },
    resize: 'detect'
}, document.getElementById("bot"));
</script>
2
Do you try to dynamically pass userid when you initiate your BotChat? - Fei Han
Yes,it must be changed dynamically. Initially it must be userid, once if the user is authenticated it should display his name or id. - AKHILA REDDY

2 Answers

2
votes

Change

user: { id: 'userid' },

To

user: { id: yourUserIdFromAad },

You can even add user: { id: yourUserIdFromAad, name: yourUserDisplayName },

1
votes

we have tried displaying the username of the authenticated person in the place of userid in the below snippet

I assume that you are a .NET developer and you'd like to dynamically pass user identity to BotChat, you can try the following approach:

  • In ASP.NET MVC application, you can get user information from controller and store it in ViewBag, then you can retrieve the value from ViewBag and dynamically pass it as userid when you initiate your BotChat. The following code snippet is for your reference.

In controller:

public ActionResult Chat()
{
    ViewBag.userinfo = User.Identity.GetUserName();
    return View();
}

In view:

<script>
    $(function () {
        var userid = '@(ViewBag.userinfo)';
        //alert(userid);

        BotChat.App({
            directLine: { secret: "{directline_secret}" },
            user: { id: userid},
            bot: { id: 'fehanbotdg' },
            resize: 'detect'
        }, document.getElementById("bot"));
    })
</script>

Test result:

enter image description here

  • In ASP.NET webform application, you can get user information from code behind and store it in a hiddenfield, then you can get the user information from hiddenfield and use it to initiate your BotChat.