Skip to main content

Notifications

Getting User Details To Use In Power Virtual Agents In Teams

Jcook Profile Picture Jcook 7,765

 

 

 

Things to Know

This examples is based on building a Virtual Agent in Microsoft Teams.
We will be using the ‘Only for teams’ Authentication on the bot.

 

 

Summary

By default PVA in Teams has some valuable variables handy, like â€˜bot.UserDisplayName‘. This is awesome, but what if we want more information about the logged in user?

This post will show both scenarios, on using the 'bot.UserDisplayName' variable as well as getting all the user details that are stored in Office365 like:
– Email Address
– First Name
– Last Name
– Job Title
– Etc.

We can also use this in the Greetings Topic to address the user by their first name, rather than their display name. (Keep in mind this might affect performance by a couple seconds)

 

 

Bot Setup

Once you have your Bot created, make sure the Authentication is set to ‘Only for teams’. To check click
Manage > Security, Authentication

image-1

 

For this example we will be using the ‘Only for Teams’ option. This will work for ‘Manual’ as well, but will require additional steps to setup a App Registration in Azure.

Select ‘Only for Teams’

 

image-2

 

 

 

Customize Greeting Scenario 1 (DisplayName)

After enabling the Authentication, you will now have access to Two variables,
bot.UserDisplayName
bot.UserId

Now lets customize our greeting.

Navigate to ‘Topics’ and select the ‘Greeting’ Topic', this is under ‘System Topics’. Click on the Authoring Canvas button.

image-3

 

Inside the message under the Trigger, you can customize the greeting message to include the variable 'bot.UserDisplayName'

image-7

 

Testing this, the Bot now knows my Display Name. This variable can be used in any topic. Which gives the Bot more of a human type feel.

image-8

 

To get all the user details from Office365, scenario 2 will cover this

 

 

 

Customize Greeting Scenario 2 (Office365)

Navigate to ‘Topics’ and select the ‘Greeting’ Topic', this is under ‘System Topics’. Click on the Authoring Canvas button.

Under the ‘Trigger Phrases’ and select ‘Call an action’. We will now build a new Flow to get the user details we want.

image-4

 

Select Create a flow

image-5

 

You will now be navigated to a new screen where you will build your Flow.
Select the Basic PVA Flow Template

image-6

 

 

First give the Flow a meaningful name. Mine is:
Power Virtual Agents – Get User Info

Add a Text Input to pass in the Display Name variable

image-9

 

Next add a ‘Search for users‘ action from office365 connector, and pass in the PVA dynamic value from the trigger

image-10

 

Now we have all the user details. The results are returned as an Array. To get around this.
We can add a ‘Get user profile‘ action and pass in the first User Principal Name(UPN)

 

We have to use the first() expression, so we don’t get put into an Apply to each loop, my expression:

first(outputs('Search_for_users_(V2)')?['body/value'])?['UserPrincipalName']

image-11

 

Lastly in the Return values to PVA action, add all the values you want from ‘Get user profile‘ dynamic content

image-12

 

Click Save, and close on top right of the screen. Back at the PVA Canvas screen, add your Flow

image-13

 

Pass in the bot.UserDisplayName variable

image-14

 

Now we can customize our greeting to only address the user by first name

image-15

 

As a test I created a Topic called User Details which showcases all the output values that I passed in to PVA from Power Automate

image-19

image-20

 

 

Conclusion

Getting user details from Office365 opens the door to so many use cases which involves people data.

This can be a great way to give your bot more personality. Do keep in mind that this may affect performance.

 

Cross Posted from:

https://flowaltdelete.ca/2020/11/06/getting-user-details-to-use-in-power-virtual-agents-teams/

 

Comments

*This post is locked for comments