zoukankan      html  css  js  c++  java
  • Linux 发送https POST请求sample ===Slack 频道中发送消息通知

    jasqia@jasqia0121mac ~ % 

    curl -i -k -H "Content-type: application/json" -X POST -d '{
    "blocks":[
    {
    "type":"section",
    "text":{
    "type":"mrkdwn",
    "text":"*Welcome to the imagination world*"
    }
    },
    {
    "type":"section",
    "block_id":"section567",
    "text":{
    "type":"mrkdwn",
    "text":"http://www.google.com "
    },
    "accessory":{
    "type":"image",
    "image_url":"https://files.slack.com/files-pri/T28JEQ9RV-F024A8BTXE3/icon.jpeg",
    "alt_text":"Say Hi"
    }
    }
    ]
    }' https://hooks.slack.com/services/T28JEQ9RV/B024MUM8URK/ccc
    

      

    and if you use Python language, it is quit easy

    import json
    import requests
    
    
    def alert2Slack(webhook, message):
        headers = {
            "Content-Type": "application/json",
            "charset": "utf-8"
        }
    
        url = webhook
        value = message
    
        response = requests.request("POST", url, data=json.dumps(value, ensure_ascii=False).encode('utf-8'),
                                    headers=headers)
        return response
    
    
    if __name__ == "__main__":
        webhook = "https://hooks.slack.com/services/xxxx"
    
        message = {
            "blocks": [
                {
                    "type": "section",
                    "text": {
                        "type": "mrkdwn",
                        "text": "*Welcome to the imagination world*"
                    }
                },
                {
                    "type": "section",
                    "block_id": "section567",
                    "text": {
                        "type": "mrkdwn",
                        "text": "
     *The event Time is:*  " + "
     *The issue website is:* xxx" +
                                "
     @jasmine.qian" + "
     *The log information is as the following:* http://www.google.com "
    
                    },
                    "accessory": {
                        "type": "image",
                        "image_url": "https://files.slack.com/files-pri/T28JEQ9RV-F024A8BTXE3/icon.jpeg",
                        "alt_text": "Say Hi"
                    }
                }
            ]
        }
    
        alert2Slack(webhook, message)
    

      

    ------------------------- A little Progress a day makes you a big success... ----------------------------
  • 相关阅读:
    土木工程材料0732
    07 具有无关项的逻辑函数及其化简
    06 逻辑函数化简法
    AD中板子挖孔开槽
    电容式触摸按键原理
    LTspice
    三相电
    7、简单电阻容元件模型的创建
    cadence17.4在笔记本下设置菜单显示不全的解决办法
    36. 二叉搜索树与双向链表
  • 原文地址:https://www.cnblogs.com/qianjinyan/p/14927532.html
Copyright © 2011-2022 走看看