Skip to main content

功能

  • 发送消息到钉钉机器人。
  • 支持所有钉钉机器人消息类型。
  • 钉钉机器人支持多种安全设置,建议在设置时选择IP地址。
  • 钉钉机器人开发文档

安装

1. 安装该模块
pip install dingdingrobot

使用

  • 获取钉钉机器人的 access_token

    创建机器人时,会返回一个 webhook 的地址,如 https://oapi.dingtalk.com/robot/send?access_token=053e5481723dbe9b2e7765ece20118fa5963909d50f05ea6ae58214e9,则 access_token 为 053e5481723dbe9b2e7765ece20118fa5963909d50f05ea6ae58214e9

  • 使用

    key = '053e5481723dbe9b2e7765ece20118fa5963909d50f05ea6ae58214e9'
    
    import dingdingrobot
    dtrobot = dingdingrobot.DingdingRobot(key)
    
  • 发送文本消息

    # 签名
    dtrobot.send_text(content, at_mobiles=None)
    
    # content 为要发送的文本内容
    # at_mobiles 需要 @ 人的手机号,可以是列表或字符串。如果要 @所有人,则设置 at_mobiles='all'。
    # @ 多个人时,指定 at_mobiles=['18600000000', '18600000001'] 或 at_mobiles='18600000000,18600000001'
    
  • 发送 markdown 消息

    # 签名
    dtrobot.send_markdown(title, contents, at_mobiles=None)
    # title     指定markdwon消息显示的标题
    # contents  为可迭代对象,如列表、元组等。每一行为一个 markdown 格式的字符串。
    # at_mobiles    需要@人的手机号,参考 send_text 中的 at_mobiles
    # 支持的格式参考:https://ding-doc.dingtalk.com/document#/org-dev-guide/qf2nxq/9e91d73c
    
  • 发送 link 类型

    # 签名
    dtrobot.send_link(title, text, jump_url, picurl=None)
    
    # title     消息标题
    # text      消息内容
    # jump_url  点击消息跳转的url
    # picurl    图片的url
    
  • 发送 actionCard

    # 签名
    dtrobot.send_actioncard(title, text, btn_info, btns=False, btn_orientation=0)
    
    # title     指定 action card的标题
    # text      指定 action card的文本内容
    # btn_info  指定 button 的信息。格式为:[{'btn_title': 'title', 'btn_url': 'button url'}]
    # btns      False整体跳转, True 独立跳转。默认是 False
    # btn_orientation   button的排列方式。0按钮竖直排列,1按钮水平排列
    
  • 发送 feedCard

    # 签名
    dtrobot.send_feedcard(links)
    
    # links     格式为:[{'link_title': 'link title', 'message_url': 'message url', 'pic_url': 'pictur url'}]
    

示例

key = 'you access token'
dtrobot = dingdingrobot.DingdingRobot(key)

# 发送 text 消息
dtrobot.send_text('123'))

# 发送 markdown 消息
dtrobot.send_markdown(title='123', contents=['# hello world', '> 1', '> 2', '> 3', '4'],
                        at_mobiles='18600010001,18655750614,all')

# 发送 link 消息
dtrobot.send_link(title='MAKA做出好设计', text='MAKA做出好设计', jump_url='https://www.maka.im',
                         picurl='https://img1.maka.im/template/T_XM3SO6TE_t1.jpg'))

# 发送 actionCard
dtrobot.send_actioncard(title='MAKA做出好设计', text='MAKA做出好设计',
                               btn_info=[{'btn_title': 'MAKA官网', 'btn_url': 'https://www.maka.im'},
                                         {'btn_title': 'MAKA做出好设计', 'btn_url': 'https://maka.im'}],
                               btns=True), 1)

# 发送 feedCard
dtrobot.send_feedcard(
    [
        {'link_title': 'MAKA做出好设计', 'message_url': 'https://www.maka.im',
         'pic_url': 'https://res.maka.im/platV5Cms/homepage/icon/Group22%402x.png?x-oss-process=image/format,webp'},
        {'link_title': 'link title', 'message_url': 'https://www.maka.im/muban',
         'pic_url': 'https://img1.maka.im/template/T_XM3SO6TE_t1.jpg'}
    ]
)

Metadata

Release files for dingdingrobot 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dingdingrobot 1.0.4
File Size Uploaded Provenance Actions
dingdingrobot-1.0.4.tar.gz 4.4 kB Without provenance Details for dingdingrobot-1.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dingdingrobot 1.0.4
File Interpreter ABI Platform Actions
dingdingrobot-1.0.4-py3-none-any.whl Python 3 none any Details for dingdingrobot-1.0.4-py3-none-any.whl

Total release size: 8.9 kB

Release files / dingdingrobot-1.0.4.tar.gz

Download URL dingdingrobot-1.0.4.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3ee5139346bb18084fadf11b737407856800148b2e7c945ba317f1df58a4a27b
BLAKE2b-256 checksum
How to use checksums
3f416d73bf042b8049d0c2bd847ea77e206f44491e86b3a2dbaab4e9d7ff3555
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.8.2

Release files / dingdingrobot-1.0.4-py3-none-any.whl

Download URL dingdingrobot-1.0.4-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3ef98ecbd0dc8c7895c7d30a3fd7892c2950f047f1a86f8af5cb87bf7e65883b
BLAKE2b-256 checksum
How to use checksums
3155eb540086883eb1fe64402f91e9da920540932212d09ba20857b45a16a957
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.8.2

Security for dingdingrobot 1.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page