Post A Message To Teams Chat
It’s long past time I had a new blog post. I’ve been focused so much lately on speaking opportunities and mentoring efforts that I haven’t posted much to my blog. So, here’s a new one I found useful a while back.
Scenario
In our scenario, we have a support email that gets emails when someone fills out a form on a website. The problem is that not much notice gets paid to the inbox and messages could go ignored for hours, or even days. We want to raise awareness of issues sooner so that appropriate actions can be taken. In this case, when we get an email, we’ll post a message into our Teams chat.
Our Flow
Let’s start by creating a new automated flow:
For our trigger, we’ll set it to “When a new email arrives (V3)”. You can add filters to your email so that it only triggers when an email meets certain conditions. In this case, since I use this email for other uses, we’ll add a subject line filter that looks for specific wording before triggering our flow:
But you can also filter on just about anything associated with an email.
Next up, we’ll want to add an action to respond to our trigger. In this case, we want to post a message into a Microsoft Teams chat channel. So, click the Add Action button and search for Teams. Specifically, under there, we want the “Post message in a chat or channel” action.
As with any connector, if you don’t already have a connection to an external resource, you’ll need to tell Power Automate you login credentials to establish the connection.
Once you’re connected, you’ll need to set a few parameters to tell Teams where you want to post to and what you want to post. The first parameter is “Post as”. There are a couple of options here, but you can tell it to post as a bot, as a virtual agent, or as a specific user. If you select “Flow bot” the new message will be posted as if it came from your user, but it will add “via Workflows” to the sender, so you can easily tell it was automated.
After you select the personality, it will ask you what type of destination you want to post to. Do you want to post it to a Teams Channel chat group, or as a direct message to a specific user or group chat. In this case, I’m going to select Channel.
Having selected that I want to post to a channel, it will then ask me to select the Team and Channel to post to.
And finally, you’ll need to tell it what to post on the Channel. In this case, I’m going to add the from address, subject line, and body of the email message. I’ll add these using the selector in the editor the same as we would any output value from a previous flow step.
Our flow will now have two steps: A trigger and an action.
That’s all we need for our flow, so we’ll go ahead and test it. Put our flow in test mode and send an email. After a few moments, a chat message will now appear in our Teams channel.
Next Steps
That’s it for our base flow, but there are all kinds of things we could add to our flow. For instance, we could run a sentiment analysis on the body of the email and get a sense of the urgency of the issue. Then we might send it to different chat channels depending on urgency or topic. We might also use ChatGPT or something similar to summarize the email for us and use that in the message instead. Or, in addition to the Teams message, we could have our Flow automatically create a new issue in DevOps or JIRA for us and report the issue ID in the Teams message with a link to it so someone can immediately start triaging the issue. There’s no limit on what we could do to enhance this base flow and use it to increase our developer productivity.