Power Virtual Agents bot setting the Out Of Office
It is always interesting to hit the wall with limitations when you are
working with Power Automate. Some limits are due to licensing but some
are due to other good reasons. I was running a PoC where a person
interacting with a Power Virtual Agent bot required to do actions on
behalf of that person. And after digging some information out (Thank
you @Tomasz for helping there! ) it
was clear that I had reached the wall when I was trying to make my
little bot to set up Out of Office for the interacting user. Using the
Office 365 Set Automatic Replies action always works on
the connection user only. And since you can not act on behalf of
that user it required to go beyond the wall and say “there is no spoon”.
And I found it there wasn’t a spoon- just the miracle world of Graph
API.
- Azure Logic Apps that uses **Graph API **to set the Out of Office / Automatic replies to a specific user.
- Setting up a Azure API Management service so that Azure Logic App can be called from the Cloud Flow running inside Power Virtual Agent – and still keep on using standard licensing (no need to go to premium)
First it was necessary to create the** Azure App Registration** (applicationid, secret) with suitable set of API permissions. After that it was all about figuring out the Graph API call & JSON to set the Automatic Reply / Out of Office. Read the documentation (& about permissions) from Docs here.
Next I built a Azure Logic Apps that uses HTTP Request
trigger (get) to retrieve user email and number of away days in
parameters.
After those steps I have user email and number of days that needs to be
set Out of Office. I returned the HTTP-request and prepared variables
with Application ID, TenantID and App Secret information to be able to
call Graph API with application permissions.
The Graph API call URL and example JSON I used to test this are:
https://graph.microsoft.com/v1.0/users/useremail/mailboxsettings
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Me/mailboxSettings",
"automaticRepliesSetting": {
"externalAudience": "all",
"externalReplyMessage": "I am away from the office. ",
"internalReplyMessage": "I am away from the office. ",
"status": "Scheduled",
"scheduledStartDateTime": {
"dateTime": "2021-04-17T18:00:00.0000000",
"timeZone": "UTC"
},
"scheduledEndDateTime": {
"dateTime": "2021-04-18T18:00:00.0000000",
"timeZone": "UTC"
}
}
}
Then it was just the case of patching the information
Another alternative would have been to put the “set these to Out of
Office” information to a SharePoint List (for example) and use a Azure
Logic Apps trigger to read that list and make those API Calls. That
would have some delay, but since Out of Office is rarely requiring an
instant response it would be a better one for the real world scenario in
this case. However if you are already using Azure API management then
using it for this as well is a good idea. But setting it up solely for a
single purpose does not get a good ROI for most cases.
After setting the API up into the Azure you can export it directly to
the Dataverse for Teams environment – so it is there for the bot to use
without any Premium licensing.
When adding an action to your Cloud Flow in the Dataverse for Teams
environment where your bot runs you can find the custom action in the
menu.
And when running this one from the PVA of the acting user I can see the
results via Teams easily