Dink0 commited on
Commit
875edcf
·
verified ·
1 Parent(s): a81d1fc

Add an authenticated fixed-message delivery test and serialize Telegram sends

Browse files
Files changed (2) hide show
  1. README.md +4 -0
  2. receiver.py +13 -0
README.md CHANGED
@@ -66,6 +66,10 @@ authenticated diagnostics use the configured transport.
66
  When the relay is configured, read-only `/diagnostics` and `/status` also accept
67
  `Authorization: Bearer TELEGRAM_RELAY_SECRET`. The existing webhook-secret
68
  routes continue to work. This does not authorize incoming publication webhooks.
 
 
 
 
69
 
70
  See `telegram-relay/README.md` for deployment and secret configuration. Verify
71
  the relay's read-only getMe, getChat and getChatMember checks before rebuilding
 
66
  When the relay is configured, read-only `/diagnostics` and `/status` also accept
67
  `Authorization: Bearer TELEGRAM_RELAY_SECRET`. The existing webhook-secret
68
  routes continue to work. This does not authorize incoming publication webhooks.
69
+ An explicit authenticated POST to `/diagnostics/telegram-test` sends one fixed,
70
+ silent integration-test message to the configured chat. It does not consume AI
71
+ tokens or enqueue a publication. Do not retry it blindly after a network error:
72
+ Telegram may have accepted the message even when its response was lost.
73
 
74
  See `telegram-relay/README.md` for deployment and secret configuration. Verify
75
  the relay's read-only getMe, getChat and getChatMember checks before rebuilding
receiver.py CHANGED
@@ -368,6 +368,7 @@ class Clients:
368
  def __init__(self, config):
369
  self.config, self.last_tg = config, 0.0
370
  self.diagnostics_lock = threading.Lock()
 
371
  self.telegram_health = {"status": "not_checked"}
372
 
373
  def telegram_request(self, method, payload, timeout):
@@ -441,6 +442,10 @@ class Clients:
441
  return answer, result.get("usage", {})
442
 
443
  def telegram(self, method, payload):
 
 
 
 
444
  time.sleep(max(0, 3.2 - (time.monotonic() - self.last_tg)))
445
  self.last_tg = time.monotonic()
446
  data = {"chat_id": self.config.chat_id, **payload}
@@ -620,6 +625,14 @@ def make_server(monitor, host="0.0.0.0", port=7860):
620
  return self.reply(404, {"error": "not_found"})
621
 
622
  def do_POST(self):
 
 
 
 
 
 
 
 
623
  if not self.authorized("/medialogia/"):
624
  return self.reply(404, {"error": "not_found"})
625
  try:
 
368
  def __init__(self, config):
369
  self.config, self.last_tg = config, 0.0
370
  self.diagnostics_lock = threading.Lock()
371
+ self.telegram_lock = threading.Lock()
372
  self.telegram_health = {"status": "not_checked"}
373
 
374
  def telegram_request(self, method, payload, timeout):
 
442
  return answer, result.get("usage", {})
443
 
444
  def telegram(self, method, payload):
445
+ with self.telegram_lock:
446
+ return self.telegram_locked(method, payload)
447
+
448
+ def telegram_locked(self, method, payload):
449
  time.sleep(max(0, 3.2 - (time.monotonic() - self.last_tg)))
450
  self.last_tg = time.monotonic()
451
  data = {"chat_id": self.config.chat_id, **payload}
 
625
  return self.reply(404, {"error": "not_found"})
626
 
627
  def do_POST(self):
628
+ if urlsplit(self.path).path == "/diagnostics/telegram-test" and self.relay_authorized():
629
+ try:
630
+ sent = monitor.clients.telegram("sendMessage", {
631
+ "text": "Проверка интеграции: доставка из Hugging Face в Telegram восстановлена",
632
+ "disable_notification": True})
633
+ return self.reply(200, {"ok": True, "message_id": sent["message_id"]})
634
+ except ServiceError as exc:
635
+ return self.reply(503, {"ok": False, "error": exc.code})
636
  if not self.authorized("/medialogia/"):
637
  return self.reply(404, {"error": "not_found"})
638
  try: