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:
- 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.
useridwhen you initiate your BotChat?