MCPcopy Create free account
hub / github.com/Roy3838/Observer / _keep_typing

Function _keep_typing

api/remote.py:402–425  ·  view source on GitHub ↗

Show "typing…" on each busy session's phone/chat, at most every TYPING_EVERY seconds.

(sessions: dict[Channel, str])

Source from the content-addressed store, hash-verified

400
401
402async def _keep_typing(sessions: dict[Channel, str]) -> None:
403 """Show "typing…" on each busy session's phone/chat, at most every TYPING_EVERY seconds."""
404 r = await get_redis()
405 for channel, code in sessions.items():
406 if not await r.exists(_busy_key(code, channel)):
407 continue
408 # Twilio's indicator answers an inbound message: the phone's latest one.
409 msg_id = await r.get(_last_msg_key(code, channel)) if channel == "whatsapp" else None
410 if channel == "whatsapp" and not msg_id:
411 continue
412 if not await r.set(_typed_key(code, channel), "1", nx=True, ex=TYPING_EVERY[channel]):
413 continue
414 address = await bound_address(code, channel)
415 if not address:
416 continue
417 try:
418 if channel == "whatsapp":
419 from messaging import send_whatsapp_typing
420 await send_whatsapp_typing(msg_id)
421 else:
422 from tools_router import send_telegram_typing
423 await send_telegram_typing(address)
424 except Exception as e:
425 logger.info(f"Typing indicator failed on {channel}: {e}")
426
427
428# --- Shared route bodies ---

Callers 1

_pollFunction · 0.85

Calls 8

get_redisFunction · 0.90
send_whatsapp_typingFunction · 0.90
send_telegram_typingFunction · 0.90
_busy_keyFunction · 0.85
_last_msg_keyFunction · 0.85
_typed_keyFunction · 0.85
bound_addressFunction · 0.85
infoMethod · 0.80

Tested by

no test coverage detected