From 884c30b546ea39d7e6b7075bc691035fba43132a Mon Sep 17 00:00:00 2001 From: BadStorm Developer Date: Sat, 5 Sep 2026 16:58:03 +0200 Subject: [PATCH] feat(talkbot): add webhook payload debug logging --- containers/talkbot/server.py | 44 +++++++++++++++++++++------- containers/talkbot/talkbot.container | 1 + 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/containers/talkbot/server.py b/containers/talkbot/server.py index 08e4b79..a96115e 100644 --- a/containers/talkbot/server.py +++ b/containers/talkbot/server.py @@ -32,6 +32,10 @@ LLAMACPP_ENABLE_THINKING = ( os.environ.get("LLAMACPP_ENABLE_THINKING", "false").lower() in {"1", "true", "yes", "on"} ) +LOG_WEBHOOK_PAYLOAD = ( + os.environ.get("LOG_WEBHOOK_PAYLOAD", "false").lower() + in {"1", "true", "yes", "on"} +) QWEN_TTS_URL = os.environ.get("QWEN_TTS_URL", "http://qwen-tts:8000").rstrip("/") QWEN_TTS_TIMEOUT = int(os.environ.get("QWEN_TTS_TIMEOUT") or "1800") @@ -1209,6 +1213,7 @@ def process_event(job: dict) -> None: sender_display_name = job["sender_display_name"] file_param = job.get("file_param") message_text = job.get("message_text", "") + preserve_original = job.get("preserve_original", False) try: recipients = get_target_user_ids( @@ -1290,19 +1295,25 @@ def process_event(job: dict) -> None: if not translations: return - deleted = delete_message( - token, - message_id, - ) - - if not deleted: - log.warning( - "Original message %s was not deleted. " - "Generated translations will not be posted " - "to avoid confusing duplicates.", + if preserve_original: + log.info( + "Preserving original message %s because it has a non-audio attachment", message_id, ) - return + else: + deleted = delete_message( + token, + message_id, + ) + + if not deleted: + log.warning( + "Original message %s was not deleted. " + "Generated translations will not be posted " + "to avoid confusing duplicates.", + message_id, + ) + return for recipient, target_language, translated in translations: post_manager_message( @@ -1460,6 +1471,13 @@ async def webhook( } ) + if LOG_WEBHOOK_PAYLOAD: + log.warning( + "Webhook payload for message %s: %s", + message_id, + json.dumps(payload, ensure_ascii=False, sort_keys=True), + ) + sender_user_id = actor_user_id(actor) sender_display_name = ( actor.get("name") @@ -1510,6 +1528,8 @@ async def webhook( parameters, ) + preserve_original = False + if file_param and not is_audio_file(file_param): log.info( "Ignoring unsupported attachment in message %s: name=%s mimetype=%s", @@ -1520,6 +1540,7 @@ async def webhook( # If the message also contains text, process the text and ignore the # unrelated attachment. Otherwise there is nothing for this bot to do. + preserve_original = bool(message_text) file_param = None if not file_param and not message_text: @@ -1543,6 +1564,7 @@ async def webhook( "sender_display_name": sender_display_name, "file_param": file_param, "message_text": message_text, + "preserve_original": preserve_original, } ) diff --git a/containers/talkbot/talkbot.container b/containers/talkbot/talkbot.container index 38e1a65..a887e40 100644 --- a/containers/talkbot/talkbot.container +++ b/containers/talkbot/talkbot.container @@ -37,6 +37,7 @@ Environment=LLAMACPP_URL=http://llamacpp:8090 #Environment=LLAMACPP_MODEL= Environment=LLAMACPP_MAX_TOKENS=8192 Environment=LLAMACPP_ENABLE_THINKING=false +#Environment=LOG_WEBHOOK_PAYLOAD=false Environment=QWEN_TTS_URL=http://qwen-tts:8000 # --- Behaviour ---