Pre-release
This release is a pre-release and may not be stable for production use.
prefect-dingtalk-notification
一个用于 Prefect 的钉钉自定义机器人通知 Block
安装
uv add prefect-dingtalk-notification
使用
添加自定义机器人
添加自定义机器人
注: 选择 自定义 (通过Webhook接入自定义服务) 机器人
使用 DingTalkCustomRobotGroupWebhookNotification
直接发送通知
import asyncio
import json
from prefect_dingtalk_notification import DingTalkCustomRobotGroupWebhookNotification
async def main() -> None:
notification = DingTalkCustomRobotGroupWebhookNotification(
access_token="<access-token>",
secret="<secret>", # 可选, 基于你的机器人设置
)
await notification.notify(
body=json.dumps(
{
"msgtype": "text",
"text": {"content": "Prefect notification test"},
},
ensure_ascii=False,
),
)
if __name__ == "__main__":
asyncio.run(main())
保存为 Block 使用
from prefect_dingtalk_notification import DingTalkCustomRobotGroupWebhookNotification
notification_block = DingTalkCustomRobotGroupWebhookNotification(
access_token="<access-token>",
secret="<secret>",
)
block_document_id = notification_block.save("dingtalk-demo")
加载 Block
from prefect_dingtalk_notification import DingTalkCustomRobotGroupWebhookNotification
notification_block = DingTalkCustomRobotGroupWebhookNotification.load(
"dingtalk-production"
)
在 Automation 中发送通知
Prefect Automation 的 SendNotification action 接受 Block document ID。下面的示例会在收到指定事件时调用本项目的 Block:
from prefect.automations import Automation, EventTrigger, SendNotification
from prefect.events import emit_event
from prefect_dingtalk_notification import DingTalkCustomRobotGroupWebhookNotification
notification = DingTalkCustomRobotGroupWebhookNotification(
access_token="<access-token>",
secret="<secret>",
)
block_id = notification.save("dingtalk-demo")
event_name = "example.build.finished"
automation = Automation(
name="notify-dingtalk-on-build",
trigger=EventTrigger(
expect={event_name},
match={"environment": "ci"},
),
actions=[
SendNotification(
block_document_id=block_id,
subject="Build notification",
body=('{"msgtype":"text","text":{"content":"Prefect CI build finished"}}'),
)
],
).create()
emit_event(
event=event_name,
resource={
"prefect.resource.id": "example.build.123",
"environment": "ci",
},
)
Metadata
Release files for prefect-dingtalk-notification 0.1.0.dev0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| prefect_dingtalk_notification-0.1.0.dev0.tar.gz | 4.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| prefect_dingtalk_notification-0.1.0.dev0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.5 kB
Release files / prefect_dingtalk_notification-0.1.0.dev0.tar.gz
| Download URL | prefect_dingtalk_notification-0.1.0.dev0.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2667cc0398752ee0da85eba212096fc2894a431b5647bf1d1db9400a2249ae72
|
|
BLAKE2b-256 checksum How to use checksums |
6fc4219ebaf0c7e4197fc817d401e79d0686f503f2ea7f1549a76d498e356b71
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.15 {"installer":{"name":"uv","version":"0.12.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / prefect_dingtalk_notification-0.1.0.dev0-py3-none-any.whl
| Download URL | prefect_dingtalk_notification-0.1.0.dev0-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0cd24b81848c67ce39831487791eee657bcedcc159ddc4d401988a015361efae
|
|
BLAKE2b-256 checksum How to use checksums |
50cfcf4ba0737e993c5ab4ef2ca8b784983449a0c1579262f74af75fe5438365
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.15 {"installer":{"name":"uv","version":"0.12.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|