admin-notify: WhatsApp-Benachrichtigungen an Daniel bei neuer Einsendung + Veröffentlichung
This commit is contained in:
@@ -49,6 +49,7 @@ PHONE_NUMBER_ID = os.environ.get("META_PHONE_NUMBER_ID", "1152708791258718")
|
|||||||
PORT = int(os.environ.get("PORT", "5002"))
|
PORT = int(os.environ.get("PORT", "5002"))
|
||||||
TELEGRAM_TOKEN = os.environ.get("TELEGRAM_TOKEN", "")
|
TELEGRAM_TOKEN = os.environ.get("TELEGRAM_TOKEN", "")
|
||||||
TELEGRAM_API = f"https://api.telegram.org/bot{TELEGRAM_TOKEN}" if TELEGRAM_TOKEN else ""
|
TELEGRAM_API = f"https://api.telegram.org/bot{TELEGRAM_TOKEN}" if TELEGRAM_TOKEN else ""
|
||||||
|
ADMIN_PHONE = os.environ.get("ADMIN_PHONE", "4915227909535")
|
||||||
|
|
||||||
VERIFICATION_REQUIRED = os.environ.get("VERIFICATION_REQUIRED", "").lower() in ("1", "true", "yes")
|
VERIFICATION_REQUIRED = os.environ.get("VERIFICATION_REQUIRED", "").lower() in ("1", "true", "yes")
|
||||||
# Test system: verification is OFF by default (set VERIFICATION_REQUIRED=1 in .env to enable)
|
# Test system: verification is OFF by default (set VERIFICATION_REQUIRED=1 in .env to enable)
|
||||||
@@ -490,6 +491,15 @@ def triage_submission(db, submission_id: int) -> dict:
|
|||||||
|
|
||||||
print(f"[triage] #{submission_id} tier={tier} reasons={reasons} display_len={len(display_text)}", file=sys.stderr)
|
print(f"[triage] #{submission_id} tier={tier} reasons={reasons} display_len={len(display_text)}", file=sys.stderr)
|
||||||
|
|
||||||
|
# ── Admin-Benachrichtigung bei Veröffentlichung (Tier 1) ─────────
|
||||||
|
if tier == 1:
|
||||||
|
sender = row["sender_name"] or row["sender_id"]
|
||||||
|
preview = (display_text or content)[:80]
|
||||||
|
notify_admin(
|
||||||
|
f"✅ Veröffentlicht: {sender}\n"
|
||||||
|
f"→ https://chat.datenhimmel.work/admin/{submission_id}"
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"tier": tier,
|
"tier": tier,
|
||||||
"reasons": reasons,
|
"reasons": reasons,
|
||||||
@@ -616,6 +626,17 @@ def send_whatsapp_message(to: str, text: str) -> dict:
|
|||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
|
def notify_admin(text: str):
|
||||||
|
"""Admin-Benachrichtigung per WhatsApp an Daniel senden (non-blocking)."""
|
||||||
|
if not META_TOKEN or not ADMIN_PHONE:
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
send_whatsapp_message(ADMIN_PHONE, text)
|
||||||
|
print(f"[admin-notify] Gesendet: {text[:80]}", file=sys.stderr)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[admin-notify] Fehler: {e}", file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
def generate_thorsten_tts(text: str) -> str | None:
|
def generate_thorsten_tts(text: str) -> str | None:
|
||||||
"""Generate German TTS using Piper Thorsten voice. Returns path to OGG file or None."""
|
"""Generate German TTS using Piper Thorsten voice. Returns path to OGG file or None."""
|
||||||
import subprocess
|
import subprocess
|
||||||
@@ -1152,6 +1173,17 @@ def whatsapp_webhook():
|
|||||||
if cat == "ausverkauft" and spiel_titel:
|
if cat == "ausverkauft" and spiel_titel:
|
||||||
mark_ausverkauft_in_neuheiten(db, spiel_titel)
|
mark_ausverkauft_in_neuheiten(db, spiel_titel)
|
||||||
|
|
||||||
|
# ── Admin-Benachrichtigung: Neue Einsendung ──────────
|
||||||
|
sub_id = recent["id"] if thread_found else db.execute(
|
||||||
|
"SELECT last_insert_rowid()"
|
||||||
|
).fetchone()[0]
|
||||||
|
content_preview = content.replace("\n", " ")[:80]
|
||||||
|
type_emoji = {"text": "💬", "image": "🖼️", "audio": "🎤", "video": "🎬"}.get(msg_type, "📎")
|
||||||
|
notify_admin(
|
||||||
|
f"{type_emoji} {sender_name}: {content_preview}\n"
|
||||||
|
f"→ https://chat.datenhimmel.work/admin/{sub_id}"
|
||||||
|
)
|
||||||
|
|
||||||
# Auto-reply: only on NEW threads, not appends
|
# Auto-reply: only on NEW threads, not appends
|
||||||
if not thread_found and META_TOKEN:
|
if not thread_found and META_TOKEN:
|
||||||
try:
|
try:
|
||||||
@@ -2043,6 +2075,16 @@ def submission_update_summary(sub_id: int):
|
|||||||
"UPDATE submissions SET status='published', published_at=CURRENT_TIMESTAMP WHERE id=?",
|
"UPDATE submissions SET status='published', published_at=CURRENT_TIMESTAMP WHERE id=?",
|
||||||
(sub_id,),
|
(sub_id,),
|
||||||
)
|
)
|
||||||
|
# Admin-Benachrichtigung
|
||||||
|
row = db.execute(
|
||||||
|
"SELECT sender_name, sender_id FROM submissions WHERE id=?", (sub_id,)
|
||||||
|
).fetchone()
|
||||||
|
if row:
|
||||||
|
sender = row["sender_name"] or row["sender_id"]
|
||||||
|
notify_admin(
|
||||||
|
f"📢 Manuell veröffentlicht: {sender}\n"
|
||||||
|
f"→ https://chat.datenhimmel.work/admin/{sub_id}"
|
||||||
|
)
|
||||||
elif action == "done":
|
elif action == "done":
|
||||||
db.execute("UPDATE submissions SET status='done' WHERE id=?", (sub_id,))
|
db.execute("UPDATE submissions SET status='done' WHERE id=?", (sub_id,))
|
||||||
elif action == "save":
|
elif action == "save":
|
||||||
|
|||||||
Reference in New Issue
Block a user