Teamsの特定チャネルにメッセージを送信したい

こんにちは。

いま、UiPathからTeamsの特定チャネルに対して、
(可能ならば添付ファイルを付けつつ)メッセージを送信したいと思っています。

AutomationCloudを利用している場合はIntegrationService経由で
コネクターを作ってそれにアクセスして・・というのがなんとなくイメージできたのですが、
Orchestratorがオンプレ、ないし利用していない場合は
どのように実装していけばよいか、とっかかりをご教示いただけませんでしょうか。

※なお、環境上の制約でメール送信が許可されていないため
チャネルのメールアドレスに向けてメールを送る・・という方法は使えません。

皆様のお知恵をお借りできればと。よろしくお願いいたします。

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

1 Like

Thanks for your response, and sorry for my reply is in Japanese.

AzureポータルからUiPath連携用の外部アプリケーションを登録し、
アプリケーションIDとテナントIDを取得。

その後それを用いてHTTP要求を投げて認証→メッセージを送信するイメージでしょうか。
(おそらくこの前に対象チャネルのIDを取得する作業があると思いますが)
この部分はきっとMicrosoftTeams.Activitiesで代用できそうですね。

Teamsを管理したことがないので、Azureポータルの操作感がピンとこないのですが、
ひとまず管理者に問い合わせてみようと思います。

こんにちは

取り急ぎ以下試してみてはと思います。(こちらはIntegrationService経由ではないと思います)

1 Like

返信ありがとうございます。
そうですね、こちらのアクティビティを利用する前提で、
上記で提案頂いている外部アプリの登録を行い、疎通を確認してみたいと思います。