AKHILA REDDY
AKHILA REDDY

Reputation: 21

How to modify user's display name in MS Bot Framework while using directline channel

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>

Upvotes: 1

Views: 431

Answers (2)

Fei Han
Fei Han

Reputation: 27825

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.

Upvotes: 1

Nicolas R
Nicolas R

Reputation: 14619

Change

user: { id: 'userid' },

To

user: { id: yourUserIdFromAad },

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

Upvotes: 2

Related Questions