0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

lambda

Posted at
# メンションするユーザーリスト
mention_users = [
    {"name": "Li Hao", "id": "hao14.li.bp@jp.nttdata.com"},
    {"name": "John Doe", "id": "john.doe@example.com"},
    {"name": "Jane Smith", "id": "jane.smith@example.com"}
]

# 各ユーザーの<at>メンションテキストを生成
mention_texts = [f"<at>{user['name']}</at>" for user in mention_users]

# Teams用のメンションエンティティを作成
entities = [
    {
        "type": "mention",
        "text": f"<at>{user['name']}</at>",
        "mentioned": {
            "id": user["id"],
            "name": user["name"]
        }
    }
    for user in mention_users
]

# 最終的なAdaptive Cardを作成
card = {
    "type": "message",
    "attachments": [
        {
            "contentType": "application/vnd.microsoft.card.adaptive",
            "contentUrl": None,
            "content": {
                # Adaptive Cardのスキーマ
                "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
                "type": "AdaptiveCard",
                "version": "1.4",
                # Teamsメンションエンティティの定義
                "msteams": {
                    "entities": entities
                },
                "body": [
                    # タイトル部分
                    {
                        "type": "TextBlock",
                        "text": "🚨 アラーム通知",
                        "size": "Large",  # フォントサイズを大きく
                        "weight": "Bolder",  # 太字
                        "color": "Attention",  # 強調色
                        "wrap": True
                    },
                    # メンション部分
                    {
                        "type": "TextBlock",
                        "text": " ".join(mention_texts),  # 全ユーザーのメンションを1行で結合
                        "size": "Small",  # フォントサイズを小さく
                        "weight": "Lighter",  # 軽いスタイル
                        "color": "Default",
                        "wrap": True  # 自動改行を有効化
                    },
                    # 本文の説明部分
                    {
                        "type": "TextBlock",
                        "text": "以下のアラート詳細を確認してください:",
                        "size": "Default",
                        "wrap": True
                    }
                ]
            }
        }
    ]
}
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?