【Teams】Incoming Webhookでメンションを付けて個人宛に通知する
やりたいこと
Incoming Webhookを用いてTeamsに投稿を行う際、メッセージの中にメンションを含めて特定の個人に通知したい。
前提
function createPostContent(memberName) { return { type: "message", attachments: [ { contentType: "application/vnd.microsoft.card.adaptive", content: { type: "AdaptiveCard", body: [ { type: "TextBlock", text: `Hello ${memberName}.`, }, ], $schema: "http://adaptivecards.io/schemas/adaptive-card.json", version: "1.0", }, }, ], };}
今回は例として、上記のようなシンプルなメッセージを送信する場合を想定する。
そもそものIncoming Webhookを利用してのTeamsへの投稿方法に関しては下記の記事にまとめている。
GASとTeamsを連携しWebhookでチャネルに自動通知を行う
解決法
function createPostContent(memberName) {function createPostContent(memberName, memberEmail) { return { type: "message", attachments: [ { contentType: "application/vnd.microsoft.card.adaptive", content: { type: "AdaptiveCard", body: [ { type: "TextBlock", text: `Hello ${memberName}.`, text: `Hello <at>${memberName}</at>.`, }, ], $schema: "http://adaptivecards.io/schemas/adaptive-card.json", version: "1.0", msteams: { entities: [ { type: "mention", text: `<at>${memberName}</at>`, mentioned: { id: memberEmail, name: `${memberName}`, }, }, ], }, }, }, ], };}
メンバー名とメールアドレス(Teamsアカウントのもの)を紐付け、<at>
でメンバー名を埋め込むことで実現できる。