I want to send a message to a specific channel in Teams

Hello.

I would like to send a message from UiPath to a specific Teams channel, ideally with an attachment.

If using Automation Cloud, I can roughly picture creating a connector via Integration Service and accessing it. But if Orchestrator is on-premises or not being used, could you point me in the right direction on how to implement this?

Note: Due to environment restrictions, sending email is not permitted, so sending an email to the channel’s email address is not an option.

I would appreciate any advice. Thank you in advance.

Hi @rfu

You can try below.
Please note it’s generated by LLM. I have not done this before but solution seems doable so would suggest to give it a try.

If you are not interested in trying this option, then another alternative is to send teams message using power automate and integrate power automate workflow with UiPath. By using http request, call power automate workflow which will send the teams message to the channel.

:wrench: Prerequisites

  1. Access to Azure Portal (to register your app)
  2. UiPath Studio (Desktop version)
  3. HTTP Request activity from UiPath.WebAPI.Activities package

:hammer_and_wrench: Step-by-Step Guide

:small_blue_diamond: 1. Register an App in Azure AD

  1. Go to https://portal.azure.com
  2. Navigate to Azure Active Directory > App Registrations
  3. Click New registration
  • Name: UiPathGraphAPI
  • Redirect URI: http://localhost (you can leave it if not used)
  1. Save the Application (client) ID and Directory (tenant) ID

:small_blue_diamond: 2. API Permissions

  1. Go to API permissions
  2. Click Add a permission > Microsoft Graph > Application permissions
  3. Add:
  • ChannelMessage.Send
  • Group.Read.All
  1. Click Grant admin consent

:small_blue_diamond: 3. Create Client Secret

  1. Go to Certificates & Secrets
  2. Click New Client Secret
  3. Save the secret value (not just the ID)

:small_blue_diamond: 4. Get Access Token in UiPath

Use HTTP Request activity to get the token.

  • Endpoint:

bash

Copy code

POST https://login.microsoftonline.com/<TENANT_ID>/oauth2/v2.0/token
  • Headers:

bash

Copy code

Content-Type: application/x-www-form-urlencoded
  • Body (x-www-form-urlencoded):

ini

Copy code

client_id=<YOUR_CLIENT_ID>&
scope=https://graph.microsoft.com/.default&
client_secret=<YOUR_CLIENT_SECRET>&
grant_type=client_credentials
  • Parse the response JSON to extract the access_token.

:small_blue_diamond: 5. Send Message to Teams Channel

Use another HTTP Request activity:

  • Endpoint:

bash

Copy code

POST https://graph.microsoft.com/v1.0/teams/<TEAM_ID>/channels/<CHANNEL_ID>/messages
  • Headers:

pgsql

Copy code

Authorization: Bearer <access_token>
Content-Type: application/json
  • Body (JSON):

json

Copy code

{
  "body": {
    "content": "Hello from UiPath on-prem bot!"
  }
}

:puzzle_piece: How to Get TEAM_ID and CHANNEL_ID

You can call this endpoint to list your Teams:

sql

Copy code

GET https://graph.microsoft.com/v1.0/groups?$filter=resourceProvisioningOptions/Any(x:x eq 'Team')

And then this to get channels in a team:

bash

Copy code

GET https://graph.microsoft.com/v1.0/teams/{team-id}/channels

:test_tube: Testing

Once both requests work, wrap them in a UiPath workflow:

  • First HTTP call → Get token
  • Second HTTP call → Send message

Hope this helps.

Regards
Sonali

Thanks for your response, and sorry for replying in Japanese.

Register an external application for UiPath integration through the Azure portal, and obtain the application ID and tenant ID.

Then, use those to send an HTTP request for authentication and send a message—is that the general idea?
(I imagine there’s probably a step before this to get the ID of the target channel.)
This part could probably be replaced with MicrosoftTeams.Activities.

I’ve never managed Teams, so I’m not familiar with how the Azure portal works, but I’ll try asking the administrator for now.

Hello

For now, I think you could try the following. (I don’t think this is via IntegrationService.)

Thank you for your reply.
Yes, assuming we use this activity, I’d like to register the external app you suggested above and test the connection.