現在は開発環境です。App がこのサーバーで登録して生成した Webhook を使ってください。
Python
標準ライブラリだけで、追加の依存関係なし。
BREEZE_SERVER に https://push.breezelabs.dev を設定し、キーを環境シークレット BREEZE_WEBHOOK_KEY に保存してください。
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')
ネットワークのタイムアウトや切断についても、再試行するかどうかは呼び出し側で判断します。それだけで通知が送信されていないと断定することはできません。