Update Teams Status Message via Power Automate

!
Warning: This post is over 365 days old. The information may be out of date.

With the project I am currently working on involving international customer subject matter experts, almost all my time working from home it is sometimes hard to switch off and almost feel obliged to respond to Teams messages outside of hours.

Rather than setting reminders in my calendar to meander me to write something and enable it, I turned to automation to help achieve this. Whilst there are options for ‘During quiet time’ within Teams, I felt it didn’t quite give me the flexibility I wanted. So, Power Automate is the tool of choice for this particular instance in my opinion, it’s included in my work subscription meaning it will have access to all the necessary components required to make this solution work without having to authorise 3rd Party connectors or services. By all means this is a simple iteration as a minimal viable product, no doubt this could be taken further to work as required. It was a simple iteration but as it was being documented for this blog, it changed into something a little more in-depth.

As with most popular platforms, information can be exposed and changed via API, the solution relays on making an API call to the Teams presence service to update our status and or message. Using Google-Fu, the endpoints we need are as follows:

Now, armed with these endpoints the process is simple and this is where Power Automate timely comes into play. In this example, we are going to use the ‘Send an HTTP request to SharePoint’ action to do the lifting we require.

The general (yet simple) idea here is that at 17:30 my Teams status, along with the message is updated AND I don’t have to remember to enable it.

Now it includes weekend 👍

A high-level overview of the run of the flow is this:


Teams Status Message Flow - Actions

High-level mermaid diagram of the flow

With the goal set above let’s build the flow, as there are several variables I will follow the high-level diagram and break it up into smaller chunks. In doing so I can call out some key points in the flow which you may wish to edit but these work for me.

Flow Start

To start this flow to complete its actions I want it to run @ 17:30, Monday through Friday. The best way to accomplish this is to have a scheduled flow.

Build a scheduled cloud flow

Variables & Actions

Now there are 18 variables, 4 date actions (two are used in the condition gate and will be detailed later on) and 3 compose actions that build up to the condition. So rather than attempting to screenshot the entire flow see the following table for the run order which is then going to be followed by the details of each action.

  1. daysOfTheWeek
  2. getCurrentDateAndTime
  3. getCurrentDayOfWeek
  4. currentDay
  5. waitTime
  6. weekendWaitTime
  7. getFutureTime
  8. getFutureTimePostWeekend
  9. weekendSeparator
  10. teamsEndpoint
  11. availabilityURI
  12. publishNoteURI
  13. contentType
  14. applicationJSON
  15. availabilityStatus
  16. availabilityStatusWeekend
  17. availabilityWeekendActivity
  18. statusMessage
  19. pinnedNote
  20. weekendStatusBody
  21. weekdayStatusBody
  22. weekendMessageBody
  23. weekdayMessageBody

Variables

variableName variableType variableValue
daysOfTheWeek array [“Monday”,“Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”, “Sunday”,]
waitTime integer 15
weekendWaitTime integer 63
weekendSeparator string Friday
teamsEndpoint string https://presence.teams.microsoft.com
availabilityURI string /v1/me/forceavailability
publishNoteURI string /v1/me/publishnote
contentType string content-type
applicationJSON string application/json
availabilityStatus string Away
availabilityStatusWeekend string Offline
availabilityWeekendActivity string OffWork
statusMessage string Hi! It is currently outside my core operating hours. I will try and respond as quickly as possible.
pinnedNote string <pinnednote><pinnednote>
weekendStatusBody string {“Availability”: “@{variables(‘availabilityStatusWeekend’)}”,“activity”: “@{variables(‘availabilityWeekendActivity’)}”}
weekdayStatusBody string {“Availability”: “@{variables(‘availabilityStatus’)}”}
weekendMessageBody string {“message”: “@{variables(‘statusMessage’)}.@{variables(‘PinnedNote’)}”,“expiry”: “@{body(‘getFutureTimePostWeekend’)}”}
weekdayMessageBody string {“message”: “@{variables(‘statusMessage’)}.@{variables(‘PinnedNote’)}”,“expiry”: “@{body(‘getFutureTime’)}”}

Compose Actions

variableName variableType inputs
getCurrentDateAndTime expression utcNow()
getCurrentDateOfWeek expression dayOfWeek(outputs(‘getCurrentDateAndTime’))
currentDay expression variables(‘daysOfTheWeek’)[sub(outputs(‘getCurrentDayOfWeek’),1)]

Date Actions

variableName actionType inputs timeUnit
getFutureTime Get future time waitTime hour
getFutureTimePostWeekend Get future time weekendWaitTime hour

Now if you are still here you should start with your recurrance action and then have something similar to this.

variables and actions flow

Condition

Once all the variables and actions are set the flow goes into a condition gate, validating the condition that is set before choosing if it is True or False. Here I have decided that I want to check if the day the flow is executing is Friday because the flow performs something different if it is a Friday. Using the output from currentDay (using the dynamic content option) select from the list of operators, in this example one of the equality operators; equals to. To finish the condition add the weekendSeparator variable, this will then complete the logic statement. If the condition is True (meaning that it is Friday) then it will use the If yes condition branch and if not, use the If no condition branch.

flow condition gate

As mentioned earlier in this post 2 date actions will be used in the condition branches. They rely on variables created at the start of the flow and will use those values as dynamic content.

Date Actions

variableName actionType inputs timeUnit
weekendDelay Delay weekendWaitTime hour
weekdayDelay Delay waitTime hour

Actions

For the condition branches we use the same actions but with different configurations. In this section we will set the following:

  • Teams status (weekday and weekend)
  • Teams message (weekday and weekend use the same variable currently)
  • Delay (weekday and weekend wait times)
  • Reset Teams status

With this in mind, there will be four parts to each section; a set status, setting a status message, delay and reset status. The sections will list the variables in use followed by a screenshot, this should be a matter of using the dynamic content options to populate the actions unless otherwise specified.

If yes

Set status

Here we use Send an HTTP request to SharePoint action.

flow SharePoint HTTP request

You will then receive a set of empty boxes within the action to populate, the number next to the box corresponds to the table that follows.

empty HTTP request with numbers

number variable action
1. teamsEndpoint use the custom value option in Site Address dropdown to use the variable
2. n/a change the Method from GET to PUT
3. availabilityURI click into the box and use the dynamic content options to select the variable
4. contentType click into the box and use the dynamic content options to select the variable
5. applicationJSON click into the box and use the dynamic content options to select the variable
6. weekendStatusBody click into the box and use the dynamic content options to select the variable

Set status message

Another Send an HTTP request to SharePoint action is present and using the screenshot above map the numbers to the numbers in the table below.

number variable action
1. teamsEndpoint use the custom value option in Site Address dropdown to use the variable
2. n/a change the Method from GET to PUT
3. availabilityURI click into the box and use the dynamic content options to select the variable
4. contentType click into the box and use the dynamic content options to select the variable
5. applicationJSON click into the box and use the dynamic content options to select the variable
6. weekendMessageBody click into the box and use the dynamic content options to select the variable

Delay

Rather than have the flow run every day and reevaluate, the Delay action is used here for a defined period. The flow runs @ 17:30 Fri and 63 hours later @ 08:30 Mon, the delay moves on to the next step.

wait/delay flow action

Reset status

Now the delay has moved on to this step, we submit another HTTP request but with an empty body to reset the status.

empty HTTP request body

If no

Set status

Here we use Send an HTTP request to SharePoint action again.

flow SharePoint HTTP request

You will then receive a set of empty boxes within the action to populate, the number next to the box corresponds to the table that follows.

empty HTTP request with numbers

number variable action
1. teamsEndpoint use the custom value option in Site Address dropdown to use the variable
2. n/a change the Method from GET to PUT
3. availabilityURI click into the box and use the dynamic content options to select the variable
4. contentType click into the box and use the dynamic content options to select the variable
5. applicationJSON click into the box and use the dynamic content options to select the variable
6. weekdayStatusBody click into the box and use the dynamic content options to select the variable

Set status message

Another Send an HTTP request to SharePoint action is present and using the screenshot above map the numbers to the numbers in the table below.

number variable action
1. teamsEndpoint use the custom value option in Site Address dropdown to use the variable
2. n/a change the Method from GET to PUT
3. availabilityURI click into the box and use the dynamic content options to select the variable
4. contentType click into the box and use the dynamic content options to select the variable
5. applicationJSON click into the box and use the dynamic content options to select the variable
6. weekdayMessageBody click into the box and use the dynamic content options to select the variable

Delay

Rather than have the flow run every day and reevaluate, the Delay action is used here for a defined period. The flow runs @ 17:30 Fri and 15 hours later @ 08:30 the following day the delay moves on to the next step.

wait/delay flow action

Reset status

Now the delay has moved on to this step, we submit another HTTP request but with an empty body to reset the status.

empty HTTP request body

Summary

We have created a flow which uses variables, compose and date actions which on schedule update our Teams status and message. Whilst writing this post it changed several times but I still see there is some room for improvement and to loop in Outlook out-of-office notifications as well as looking at the calendar to make things a little more dynamic.

comments