1

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? Commented May 3, 2018 at 6:22
  • Yes,it must be changed dynamically. Initially it must be userid, once if the user is authenticated it should display his name or id. Commented May 9, 2018 at 4:30

2 Answers 2

2

Change

user: { id: 'userid' },

To

user: { id: yourUserIdFromAad },

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

Sign up to request clarification or add additional context in comments.

1 Comment

How to pass yourUserIdFromAad to the id
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.