Example of using the Microsoft Teams package
- Updated: 2025/09/11
Example of using the Microsoft Teams package
In this example, you will build an automation to send a P1 incident alert to a specific Microsoft Teams channel, notifies the on-call support engineer directly via chat, and logs the channel conversation for incident records.
Procedure
- Create an automation.
- On the left panel, click Automation.
A list of available bots and forms is displayed.
- Click Create a bot.
- Enter the bot name: MSTeams_demo.
- Click Create and Edit.
- On the left panel, click Automation.
- Connect to Microsoft Teams to establish a session to authenticate and execute
all subsequent Teams actions.
- Double-click or drag the action.
- In the OAuth2 Connection field, enter MSTeam.
- In the Username field, enter office365_dev@automationanywhere.store
- Select the Default Local Session.
- Retrieve team ID of the specific team.
- Double-click or drag the action.
- In the Session name field, use the same session that you used to connect to Microsoft Teams, that is, Default.
- In the Team Name field, enter Support
Ops.Note: The Support Ops team must exist in the Microsoft Teams app.
- In the Assign team ID to variable field, enter $TeamID$
- Retrieve the unique channel ID of a specific channel within the Support Ops team.
- Double-click or drag the action.
- In the Session name field, use the same session that you used to connect to Microsoft Teams, that is, Default.
- In the Team ID field enter $TeamID$.
- In the Channel name field enter Incident
Management.Note: This channel must exist in the Microsoft Teams app.
- In the Assign channel ID to variable field, enter create a new variable named $ChannelID$.
- Post the alert to the Incident management channel.Note: The assumption here is that the external app is triggering this automation to send the alert message to the Incident Management channel.
- Double-click or drag the action.
- In the Team ID field enter $TeamID$
- In the Channel ID field, enter $ChannelID$
- In the Message field enter the following message:
Incident ID: INC-2025-08-13-045
Severity: P1 – Business Critical
Detected At: 13-Aug-2025 02:48 PM IST
Description: Order Processing API is returning 500 errors. All new orders are failing to process.
Impact: E-commerce customers unable to complete transactions.
Next Steps: On-call engineer to investigate API logs and DB health immediately.
- In the Assign message ID to variable field, create a new variable named, $MessageId$ to store the ID of the alert message.
- Retrieve Support Engineer user details.
- Double-click or drag the action.
- In the Session name field, select the same session that you used to connect to Microsoft Teams, that is, Default.
- In the Username field, create a new variable to store the email address of the user to retrieve their details. Variable created: $email$ (e.g., tony.dean@office.store)
- In the Assign user details to variable field, select the Dictionary option. Enter $user_dict$ to store the user details.
- Notify the Engineer via direct chat.
- Double-click or drag the action.
- In the Session name field, select the same session that you used to connect to Microsoft Teams, that is, Default.
- In the field, specify $user_dict{email}$
- In the Message field, enter the following
message:
Hi $user_dict{displayName}$,
A P1 critical incident has been detected: Order Processing API Failure. Incident ID: INC-2025-08-13-045 Detected: 13-Aug-2025 02:48 PM IST Impact: All new orders are failing.
Please join the Incident Bridge immediately: Teams Meeting Link Ticket: ServiceNow Link
Automated alert from A360 MS Teams Bot.
- In the Assign message ID to variable field, create a new variable named $user_msgid$.
- Confirm that the message is sent to the Engineer.
- Double-click or drag the action.
- In the Enter the message to display field, enter Message sent to Support Engineer.
- Retrieve and log Channel chat history.
- Double-click or drag the Loop action.
- From the Loop iterator drop-down field, select the iterator.
- In the Session name field, use the same session that you used to connect to Microsoft Teams, that is, Default.
- In the Team ID field enter $TeamID$
- In the Channel ID field, enter $ChannelID$
- In the Start date field, create a new variable named $start_dt$ with the value 8/13/2025 03:00 PM IST (UTC+5.30) Calcutta Asia
- In the End date field, create a new variable named $end_dt$ with the value 8/14/2025 12:00 AM IST (UTC+5.30) Calcutta Asia
- In the Assign message details to variable field, create a variable named $ChannelMessageDetails$ to store the channel messages.
- Extract message details within the Loop action.Note: Only group messages are retrieved and not individual threads.Double-click or drag the action for each key to retrieve its value from $ChannelMessageDetails$:$ChannelMessageDetails$:
Key Variable $ChannelMessageDetails (msg_id)$ $msg_id$ $ChannelMessageDetails (msg)$ $msg$ $ChannelMessageDetails (sentByUserID)$ $sentByUserID$ $ChannelMessageDetails (sentByUsername)$ $sentByUsername$ $ChannelMessageDetails (createdDateTime)$ $createdDateTime$ $ChannelMessageDetails (modifiedDateTime)$ $modifiedDateTime$ $msg_id$
$msg$
$sentByUserID$
$sentByUsername$
$createdDateTime$
$modifiedDateTime$
- Log the channel message details to the incident log file within the loop action.
- Double-click or drag the action.
- In the Output file path field, enter C:\output\Incident Log File.txt
- From the When logging option, select Append to existing log file.
- Select the Custom selection option to identify
the variables to log. Select the following variable:
- $createdDateTime$
- $modifiedDateTime$
- $msg$
- $msg_id$
- $sentByUserID$
- $sentByUserName$
- Disconnect from Microsoft Teams.
- Double-click or drag the action.
- In the Session name field, select the same session that you used to connect to Microsoft Teams, that is, Default.
- Use the action to open the Incident log file. The below information will
be shown in the .txt file.
Key Value msg_id e.g., 1692210012345 msg Critical Incident Alert – Action Required
Incident ID: INC-2025-08-13-045
Severity: P1 – Business Critical
Detected At: 13-Aug-2025 02:48 PM IST
Description: Order Processing API is returning 500 errors. All new orders are
failing to process.
Impact: E-commerce customers unable to complete transactions.
Next Steps: On-call engineer to investigate API logs and DB health
immediately.
sentbyuserid e.g., a-user-guid createddatetime 2025-08-13T14:50:12Z modifieddatetime 2025-08-13T14:50:12Z sentbyusername for eg, tony.dean@office.store