feat(tg): typing-индикатор (sendChatAction) перед ответом мин-уровня — в TG видно «печатает…»
This commit is contained in:
parent
cf42dc3f2d
commit
47f9139948
1 changed files with 10 additions and 1 deletions
|
|
@ -70,13 +70,22 @@ def receive_message(update: dict):
|
||||||
|
|
||||||
|
|
||||||
def send_reply(msg_id: str, text: str):
|
def send_reply(msg_id: str, text: str):
|
||||||
"""Ответ на входящее: Telegram-отправка + событие ReplySent (закрывает входящее)."""
|
"""Ответ на входящее: Telegram-отправка + событие ReplySent (закрывает входящее).
|
||||||
|
|
||||||
|
Перед отправкой шлём sendChatAction typing — в TG видно «печатает…».
|
||||||
|
sendChatAction живёт ~5с и НЕ обновляется сам — этого достаточно для
|
||||||
|
минутного пульса (типичный лаг ответа < 5с после начала отправки).
|
||||||
|
"""
|
||||||
model = es.run_projections()
|
model = es.run_projections()
|
||||||
m = (model.get("inbox") or {}).get(msg_id)
|
m = (model.get("inbox") or {}).get(msg_id)
|
||||||
if m is None:
|
if m is None:
|
||||||
raise ValueError(f"входящее {msg_id} не найдено")
|
raise ValueError(f"входящее {msg_id} не найдено")
|
||||||
if m.get("replied"):
|
if m.get("replied"):
|
||||||
raise ValueError(f"на {msg_id} уже отвечено")
|
raise ValueError(f"на {msg_id} уже отвечено")
|
||||||
|
try: # индикатор — best effort: недоступность TG-метода не мешает ответу
|
||||||
|
_api("sendChatAction", {"chat_id": m["chat_id"], "action": "typing"}, timeout=10)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
r = send_message(m["chat_id"], text, reply_to=None)
|
r = send_message(m["chat_id"], text, reply_to=None)
|
||||||
es.append_event("inbox", msg_id, "ReplySent", {
|
es.append_event("inbox", msg_id, "ReplySent", {
|
||||||
"to_chat": m["chat_id"], "text": text[:2000], "tg_ok": bool(r.get("ok")),
|
"to_chat": m["chat_id"], "text": text[:2000], "tg_ok": bool(r.get("ok")),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue