跳转到内容

旧版 UDP

仍为现有集成支持 UDP。新集成建议使用 WebSocket。

向 127.0.0.1:42069 发送每个数据报一个 UTF-8 JSON 对象,不要加 WebSocket 信封。

import json
import socket
message = {
"messageType": 1,
"title": "Hello from UDP",
"content": "An existing integration can still send notifications.",
"sourceApp": "YourApp",
"timeout": 5.0,
}
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as connection:
connection.sendto(
json.dumps(message).encode("utf-8"),
("127.0.0.1", 42069),
)

UDP 发送不会确认 Astral Overlay 已接收或显示通知。若没有显示,请检查 Notification API 设置以及其他应用是否占用了端口。

请参阅共用的消息字段参考。