Benachrichtigungen: Web Push und E-Mail als Kanaele der Automatiken
Neuer BenachrichtigungTransport hinter der Aktor-URL "Benachrichtigung": push schickt an alle angemeldeten Geraete (homeMesh.push_abos), mail ueber den SMTP-Zugang aus der config.ini. Ein Abo, das der Push-Dienst mit 404 oder 410 ablehnt, wird geloescht statt weiter angeschrieben. Daneben hoert der Runner auf benachrichtigung/# - darueber schickt die Probe aus den Einstellungen, ohne dass die Weboberflaeche verschluesseln muesste. Zugestellt wird im Haupttakt, nicht im MQTT-Faden. pywebpush, py_vapid und http_ece liegen wie die uebrigen Fremdpakete im Ordner, nicht in site-packages; transports.py haengt ihn an den Suchpfad. Das Schluesselpaar erzeugt vapid_erzeugen.py und bleibt ausserhalb des Git. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
from pywebpush import webpush
|
||||
import json
|
||||
import logging
|
||||
import datetime
|
||||
|
||||
|
||||
def send_push_notification(subscription, payload):
|
||||
|
||||
try:
|
||||
|
||||
# subscriptionData = json.loads(subscription)
|
||||
|
||||
# logger.error(subscriptionData)
|
||||
|
||||
webpush(
|
||||
subscription_info={
|
||||
"endpoint": subscription["endpoint"],
|
||||
"keys": subscription["keys"],
|
||||
},
|
||||
data=json.dumps(payload),
|
||||
vapid_claims={
|
||||
"aud": "https://eshopper.africa",
|
||||
"exp": int((datetime.datetime.now().timestamp())) + 86400,
|
||||
"sub": "mailto:events@eshopper.africa",
|
||||
},
|
||||
vapid_private_key="UCUKEHn7Jd33QZx5lJFKBY4plOxGsJ6xJSOzE14jQlo",
|
||||
)
|
||||
|
||||
# subscription_info = { 'endpoint': subscription['endpoint'], 'keys': subscription['keys'] },
|
||||
|
||||
# data = json.loads(payload),
|
||||
|
||||
# headers = {}
|
||||
|
||||
# ttl = 0
|
||||
|
||||
# gcm_key = ''
|
||||
|
||||
# content_encoding="aes128gcm"
|
||||
|
||||
# reg_id=""
|
||||
|
||||
# WebPusher = webpush(subscription_info)
|
||||
|
||||
# WebPusher(subscription_info).send(data, headers, ttl, gcm_key, reg_id, content_encoding, timeout=None)
|
||||
|
||||
except Exception as inst:
|
||||
print(f" webpush Notification Error : {inst}")
|
||||
|
||||
|
||||
send_push_notification({"endpoint": "https://example.com", "keys": {}}, "laaaa")
|
||||
Reference in New Issue
Block a user