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

  1. Create an automation.
    1. On the left panel, click Automation.

      A list of available bots and forms is displayed.

    2. Click Create a bot.
    3. Enter the bot name: MSTeams_demo.
    4. Click Create and Edit.
  2. Connect to Microsoft Teams to establish a session to authenticate and execute all subsequent Teams actions.
    1. Double-click or drag the Microsoft Teams > Connect action.
    2. In the OAuth2 Connection field, enter MSTeam.
    3. In the Username field, enter office365_dev@automationanywhere.store
    4. Select the Default Local Session.
  3. Retrieve team ID of the specific team.
    1. Double-click or drag the Microsoft Teams > Get team by name action.
    2. In the Session name field, use the same session that you used to connect to Microsoft Teams, that is, Default.
    3. In the Team Name field, enter Support Ops.
      Note: The Support Ops team must exist in the Microsoft Teams app.
    4. In the Assign team ID to variable field, enter $TeamID$
  4. Retrieve the unique channel ID of a specific channel within the Support Ops team.
    1. Double-click or drag the Microsoft Teams > Get channel by name action.
    2. In the Session name field, use the same session that you used to connect to Microsoft Teams, that is, Default.
    3. In the Team ID field enter $TeamID$.
    4. In the Channel name field enter Incident Management.
      Note: This channel must exist in the Microsoft Teams app.
    5. In the Assign channel ID to variable field, enter create a new variable named $ChannelID$.
  5. 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.
    1. Double-click or drag the Microsoft Teams > Send channel message action.
    2. In the Team ID field enter $TeamID$
    3. In the Channel ID field, enter $ChannelID$
    4. 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.

    5. In the Assign message ID to variable field, create a new variable named, $MessageId$ to store the ID of the alert message.
  6. Retrieve Support Engineer user details.
    1. Double-click or drag the Microsoft Teams > Get user details action.
    2. In the Session name field, select the same session that you used to connect to Microsoft Teams, that is, Default.
    3. 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)
    4. In the Assign user details to variable field, select the Dictionary option. Enter $user_dict$ to store the user details.
  7. Notify the Engineer via direct chat.
    1. Double-click or drag the Microsoft Teams > Send chat message action.
    2. In the Session name field, select the same session that you used to connect to Microsoft Teams, that is, Default.
    3. In the Send message to > Email field, specify $user_dict{email}$
    4. 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.

    5. In the Assign message ID to variable field, create a new variable named $user_msgid$.
  8. Confirm that the message is sent to the Engineer.
    1. Double-click or drag the Microsoft Teams > Message box action.
    2. In the Enter the message to display field, enter Message sent to Support Engineer.
  9. Retrieve and log Channel chat history.
    1. Double-click or drag the Loop action.
    2. From the Loop iterator drop-down field, select the Microsoft Teams > For each message in a channel iterator.
    3. In the Session name field, use the same session that you used to connect to Microsoft Teams, that is, Default.
    4. In the Team ID field enter $TeamID$
    5. In the Channel ID field, enter $ChannelID$
    6. 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
    7. 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
    8. In the Assign message details to variable field, create a variable named $ChannelMessageDetails$ to store the channel messages.
  10. Extract message details within the Loop action.
    Note: Only group messages are retrieved and not individual threads.

    Double-click or drag the Dictionary > Get action for each key to retrieve its value from $ChannelMessageDetails$:
    Key Variable
    $ChannelMessageDetails (msg_id)$ $msg_id$
    $ChannelMessageDetails (msg)$ $msg$
    $ChannelMessageDetails (sentByUserID)$ $sentByUserID$
    $ChannelMessageDetails (sentByUsername)$ $sentByUsername$
    $ChannelMessageDetails (createdDateTime)$ $createdDateTime$
    $ChannelMessageDetails (modifiedDateTime)$ $modifiedDateTime$
    $ChannelMessageDetails$:

    $msg_id$

    $msg$

    $sentByUserID$

    $sentByUsername$

    $createdDateTime$

    $modifiedDateTime$

  11. Log the channel message details to the incident log file within the loop action.
    • Double-click or drag the Logging > Log variables to file 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$
  12. Disconnect from Microsoft Teams.
    1. Double-click or drag the Microsoft Teams > Disconnect action.
    2. In the Session name field, select the same session that you used to connect to Microsoft Teams, that is, Default.
  13. Use the File > Open 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