【Teams】自动发送消息【原创】

由于我们公司统一使用Teams作为通讯工具,所以告警消息需要考虑Teams。一旦线上出现问题,需要调接口来发送Teams消息

注意:
该方法只能发送到对应的团队频道,而不能实现发送到个人或者是聊天群

参考文档:
https://docs.microsoft.com/zh-cn/outlook/actionable-messages/send-via-connectors

步骤:

1. 增加连接器

在对应的团队频道,右击选择连接器
在这里插入图片描述

选择Incoming Webhook连接器,点击添加
在这里插入图片描述

2. 配置连接器

添加之后,进行配置
在这里插入图片描述

输入名称和上传好图像之后,点击创建,会生成一个URL

3. 调API进行发送

上面创建好了之后,会生成URL,复制这个URL到postman,选择POST方式,Headers为:Content-Type:application/json
Body为:

{
    "@type": "MessageCard",
    "@context": "https://schema.org/extensions",
    "summary": "This is the summary property",
    "themeColor": "0075FF",
    "sections": [
        {
            "heroImage": {
                "image": "https://messagecardplayground.azurewebsites.net/assets/FlowLogo.png"
            }
        },
        {
            "startGroup": true,
            "title": "**告警消息**",
            "facts": [
                {
                    "name": "IP地址:",
                    "value": "192.168.1.1"
                },
                {
                    "name": "时间:",
                    "value": "2019.07.13 15:58:31"
                },
                {
                    "name": "报错信息:",
                    "value": "Uncaught Error Class Memcached not found in Memcachedchen.class.php:20"
                },
                {
                    "name": "链接:",
                    "value": "[查看更多报错信息](https://www.baidu.com)"
                }
            ]
        },
        {
            "potentialAction": [
                {
                    "@type": "ActionCard",
                    "name": "点击处理",
                    "inputs": [
                        {
                            "@type": "TextInput",
                            "id": "comment",
                            "isMultiline": true,
                            "title": "备注"
                        }
                    ],
                    "actions": [
                        {
                            "@type": "HttpPOST",
                            "name": "保存",
                            "target": "http://..."
                        }
                    ]
                },
                {
                    "@type": "ActionCard",
                    "name": "取消",
                    "inputs": [
                        {
                            "@type": "TextInput",
                            "id": "comment",
                            "isMultiline": true,
                            "title": "取消原因"
                        }
                    ],
                    "actions": [
                        {
                            "@type": "HttpPOST",
                            "name": "保存",
                            "target": "http://..."
                        }
                    ]
                }
            ]
        },
        {
            "startGroup": true,
            "activitySubtitle": "Grant approvals directly from your mobile device with the Microsoft Flow app. [Learn more](https://learnmode)\n\nThis message was created by an automated workflow in Microsoft Flow. Do not reply."
        }
    ]
}

点击send之后,会在团队频道里面收到一条消息:
在这里插入图片描述

点击处理按钮或者是取消按钮,会进行原因和备注的编写,并且调用指定的链接:
在这里插入图片描述

另外,消息格式有很多,具体可以参考:
https://messagecardplayground.azurewebsites.net/

发布了64 篇原创文章 · 获赞 47 · 访问量 19万+

猜你喜欢

转载自blog.csdn.net/jiandanokok/article/details/96556440
今日推荐