浏览文档 +

Python

只用标准库,无需额外依赖。

先把服务器地址 https://push.breezelabs.dev 设为 BREEZE_SERVER,把你的 key 保存为环境 secret BREEZE_WEBHOOK_KEY。

python
import json
import os
from urllib.request import Request, urlopen
from urllib.error import HTTPError

server = os.environ['BREEZE_SERVER'].rstrip('/')
key = os.environ['BREEZE_WEBHOOK_KEY']
payload = json.dumps({'title': '任务完成', 'message': '处理完成', 'thread_id': 'jobs'}).encode('utf-8')
request = Request(server + '/v1/send', data=payload, method='POST', headers={
    'Authorization': 'Bearer ' + key,
    'Content-Type': 'application/json',
})
try:
    with urlopen(request, timeout=20) as response:
        status, result = response.status, json.load(response)
except HTTPError as error:
    status, result = error.code, json.load(error)
print({'status': status, 'request_id': result.get('request_id'), 'data': result.get('data')})
if status != 200:
    raise RuntimeError('Inspect the Breeze result before retrying')

网络超时或断连也应交给调用方判断,不能据此断定通知未发送。

查看发送结果与重试建议