LoginSignup
2
3

More than 1 year has passed since last update.

PowerAutomate: Team 間の投稿を自動転送(判断付きで)

Last updated at Posted at 2022-04-21

背景

複数の Team に所属していると、ある Team から別の Team へ定期的に転送したくなることがあるんです。

例)

  • 濃い情報を定期的に投稿してくれる人がいる。

でも、中には転送したくないものがあるので、完全自動化は厳しい

こんな時に、自身にチャットを飛ばして、判断してから投稿させるっていうフローです。

概要

  1. トリガーで新規投稿検知
  2. 自身にチャットで概要通知しつつ、判断を促す
  3. 投稿、とした場合には、特定のスレッドへ返信

動作例

こんな感じの投稿があって
image.png

概要を見て判断をする
image.png

転送した場合
image.png

全体像

image.png

詳細

トリガー

新しいチャネル メッセージが追加されたとき を使って、対象チャネルを指定する
image.png

判断

image.png

  • 自分のプロファイルを取得する (V2) で自身の情報取得 (判断の促し先)
  • トリガーの投稿内容そのままだと HTML コンテンツだろうから、HTML からテキストへ で Plain Text 取得
  • 判断を促す用のチャットを飛ばす
    • 「転送する」を選択した場合は、id: "Transfer" を返すようにしておくことで、Submit の結果をあとから判断する

image.png

判断促す用の Adaptive Card
{
    "type": "AdaptiveCard",
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.3",
    "body": [
        {
            "type": "TextBlock",
            "text": "@{triggerOutputs()?['body/subject']}",
            "wrap": true,
            "color": "Attention"
        },
        {
            "type": "TextBlock",
            "text": "@{body('Html_to_text')}",
            "wrap": true,
            "color": "Dark",
            "size": "Small",
            "weight": "Lighter"
        },
        {
            "type": "ActionSet",
            "actions": [
                {
                    "type": "Action.Submit",
                    "title": "転送する",
                    "id": "Transfer"
                },
                {
                    "type": "Action.Submit",
                    "title": "やめておく",
                    "id": "Stop"
                },
                {
                    "title": "元投稿へ",
                    "type": "Action.OpenUrl",
                    "url": "@{triggerOutputs()?['body/webUrl']}",
                    "id": "OpenUrl"
                }
            ]
        }
    ],
    "msteams": {
        "width": "full"
    }
}

添付ファイル処理と投稿

投稿判断の処理

image.png

『転送する: Transfer』or 『やめておく: Stop』の判断

結果は、以下のように submitActionId で取得可能

判断結果の取得
@{actions('Post_adaptive_card_and_wait_for_a_response')?['outputs/body'].submitActionId}

添付ファイル処理

image.png

  • 添付ファイルを全部処理
    • ファイル情報を取得。contenturl で指定

    @items('Apply_to_each')['contenturl']

    • 転送元からコピー(Content取得して生成って道もあるが、その場合同一ファイル名があった場合の対処が面倒です)
    • コピーしたファイルのリンク情報を生成

decode しないとパスが取得出来ないことがあるので注意

@decodeUriComponent(items('Apply_to_each')['contenturl'])

ファイルリンクタグ
<a href="@{actions('Copy_file').inputs.parameters.dataset}@{outputs('Copy_file')?['body/Path']}">@{items('Apply_to_each')?['name']}</a><p/>

転送

image.png

HTML コンテント内に改行があると、Bulletins と組み合わさってなんか壊れることがあったので以下で置換して、Compose へ

改行置換
@{replace(triggerOutputs()?['body/body/content'],decodeUriComponent('%0A'),'')}

転送用メッセージを生成して、Compose へ保存

投稿者の情報は、Delve リンクで

転送メッセージ
 posted by <a href="https://jpn.delve.office.com/?u=@{triggerOutputs()?['body/from/user/id']}&v=work"> @{triggerOutputs()?['body/from/user/displayName']}</a>
<h2>@{triggerOutputs()?['body/subject']}</h2>
<blockquote>@{outputs('Compose_ReplaceBreakableKeyphrase')}</blockquote> 

@{variables('Attachments')}

で、最後は返信で単一スレッドへ投稿(転送)

返信する場合、メッセージID が必要になるので、以下を実装しておくと便利です

あとがき

Logic Apps が使えるようにしたいものです・・

keyword

how to transfer teams to teams with decision

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3