Print custom username in Azure chatbot.

preeti bhati 1 Reputation point
2021-07-23T05:48:30.93+00:00

Hi Team ,
I am using the following code to print the custom username and ID.

ID is coming with the help of following code but name is not coming.

                var ID = turnContext.Activity.From.Id;
                var userName = turnContext.Activity.From.Name;
                await turnContext.SendActivityAsync(MessageFactory.Text($"Hello and welcome- {userName}.{role}"), cancellationToken);
                await turnContext.SendActivityAsync(MessageFactory.Text($"This Is your ID -{ID}"), cancellationToken);

can you please tel me is there any configuration for username in Azure portal side.

Thanks & Regards,
Preeti Bhati

Azure AI Bot Service
Azure AI Bot Service
An Azure service that provides an integrated environment for bot development.
837 questions
{count} votes

1 answer

Sort by: Most helpful
  1. GiftA-MSFT 11,166 Reputation points
    2021-07-28T21:23:15.92+00:00

    Hi, thanks for reaching out. Here's an example of how to print username (BotBuilder Sample).

    // the channel should sends the user name in the 'From' object
    var userName = turnContext.Activity.From.Name;
    await turnContext.SendActivityAsync("You are seeing this message because this was your first message ever to this bot.", cancellationToken: cancellationToken);
    await turnContext.SendActivityAsync($"It is a good practice to welcome the user and provide personal greeting. For example, welcome {userName}.", cancellationToken: cancellationToken);
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.