Power Appsの使い方

Power AppsとPower Automateの使い方やできることがわかるブログを目指しています。

Power Apps から直接 Teams ユーザーにチャットを送れるか?

Power Apps x Teams 連携として、ユーザーに対して Power Apps から直接チャットを送る方法について考えてみます。

 

コネクタのリファレンスを確認

リファレンスを確認すると、[ PostMessageToConversation ]で実装できそうです。

 

チャットでメッセージを送信する

https://docs.microsoft.com/en-us/connectors/teams/#post-message-in-a-chat-or-channel

 

Post message in a chat or channel 
Operation ID: PostMessageToConversation 
This operation posts a message to a chat or a channel. 
Parameters 
Name 
Post as 
Post in 
Post message request 
poster 
location 
body 
Requi red 
True 
True 
True 
Type 
string 
string 
dynamic 
Description 
Select an option 
Select an option 
The post message request

 

Type : dynamic の箇所が怪しい雰囲気を感じますね。

 

Power Apps で実装してみる

Power Apps で確認してみると、3つ必要な引数が2つまでしか指定できません。

PostMessageToConversetion(poster, location) location: 
v Microsoft Teams . PostMessageToConversationk"F10w bot"

 

Type : dynamic の部分が指定できない状態です。

 

Power Apps は動的スキーマに対応していない

Docs を探してみると、動的スキーマには対応していないという記述がありました。

 

Overview of canvas-app connectors for Power Apps - Actions

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/connections-list#actions

O Note 
Power Apps doesn't work with dynamic schema. The phrase dynamic schema refers to the possibility that the same action may 
return a different table with different columns. Conditions that may cause the columns in the tables to differ include the action 
input parameters, the user or role that's executing the action, and the group in which the user is working, among others. For 
example, SQL Server stored procedures may return different columns if run with different inputs. For actions with dynamic 
schema, the connector documentation shows The outputs of this operation are dynamic. as the return value. In contrast, Power 
Automate works with dynamic schema and might provide a work-around for your scenario.

 

このように、Power Apps は動的スキーマに対応していません。

同様に引数によって動的に続く引数が変わるようなアクションは実行できないようです。

 

結論

Power Apps 単体ではユーザーにチャットを送信することは(標準機能では)できない。

 

代案

Power Automate を利用すると、フローボットとしてユーザーにチャットを送信できます。ボットとしてでよければ、こちらで代用しましょう。

 

場合によっては Graph API を利用

どうしてもやりたい場合は、Microsoft Graph API の利用を検討します。

 

チャットでメッセージを送信する

https://docs.microsoft.com/ja-jp/graph/api/chat-post-messages?view=graph-rest-1.0&tabs=http

 

ただ、少々手間が掛かりそうです。

無理にチャット機能を実装するより、別のアプローチを検討すべきかもしれません。

機能が無いということは、そういった使い方を想定していない、もしくはして欲しくない可能性があります。それに反するとドツボにはまる可能性が高いので、個人的にはあまりお薦めはできません。

 

まとめ

残念ながら Power Apps 単体でユーザーに対して Teams チャットを送信することは難しそうです。

私であれば Power Automate を利用した形で妥協すると思います。

Graph API は要件にもよりますが、なるべく使わない方向で検討する気がしますね。

 

PR

アプリ作成支援や導入支援サービスを提供しています。

Power Apps / Power Automate 技術支援サービス | ZEE CitizenDevSupport

https://powerapps.zee-citizendevsupport.com/

Power Apps や Power Automate に関する仕事のご依頼は下記ページからお問い合わせください。
ZEE CitizenDevSupport