python 结合钉钉机器人发送钉钉消息

1.发送文本消息:

def send_action_card(self, title, text):

    post_data = {
        "msgtype": "markdown",
        "markdown": {"title": title,
                     "text": text,
                     },
    }

    response = requests.post(
        ding_url,
        headers=headers,
        json=post_data,
        verify=True)
    return response

2.发送带有按钮的:

  post_data =

{
    "actionCard": {
        "title": "日报名字",
        "text": "##   ![screenshot](%s)" % url,
        "hideAvatar": "0",
        "btnOrientation": "0",
        "btns": [
      
            {
                "title": "按钮的名字",
                "actionURL": "dingtalk://dingtalkclient/page/link?url=%s" % parse.quote(url)
            }

        ]
    },
    "msgtype": "actionCard"
}
response = requests.post( ding_url, headers=headers, json=post_data, verify=True) return response

   

你可能感兴趣的:(python 结合钉钉机器人发送钉钉消息)