oclaw/interfaces/gateway/server_methods/telegram_send_normalize.py
oliver 420abac9f1 refactor: root-package imports (svc/runtime/interfaces) and fix PYTHONPATH
- Rename platform/ to svc/ to avoid shadowing stdlib platform.
- Replace from oclaw.* with from svc/runtime/interfaces; update -m CLI paths.
- tests/conftest: prepend repo root to sys.path (no parent-folder package name).
- CI: paths and offline_eval script under repo root.
- Ops scripts: PYTHONPATH must be repo root for python -m runtime.* (fixes gateway/WhatsApp sidecar startup).
- Fix default oclaw.json path in tabular/file attachment limits; stabilize attachment test config.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-13 14:51:17 +08:00

41 lines
1.4 KiB
Python

from __future__ import annotations
from typing import Any
from runtime.extensions.telegram import (
normalize_telegram_messaging_target,
parse_telegram_reply_to_message_id,
parse_telegram_target,
parse_telegram_thread_id,
)
def normalize_transport_target_for_channel(
*,
channel: str,
to: str,
params: dict[str, Any],
) -> tuple[str, dict[str, Any]]:
"""Normalize channel transport target payload for outbound paths."""
extra: dict[str, Any] = {}
if channel != "telegram":
return to, extra
normalized_target = normalize_telegram_messaging_target(to)
parsed_target = parse_telegram_target(normalized_target or to)
normalized_to = normalized_target or f"telegram:{parsed_target.chat_id}".lower()
reply_to_id = parse_telegram_reply_to_message_id(params.get("replyToId"))
thread_id = parse_telegram_thread_id(
params.get("threadId") if params.get("threadId") is not None else parsed_target.message_thread_id
)
extra = {
"target": {
"chatId": parsed_target.chat_id,
"chatType": parsed_target.chat_type,
**({"messageThreadId": parsed_target.message_thread_id} if parsed_target.message_thread_id is not None else {}),
},
**({"threadId": thread_id} if thread_id is not None else {}),
**({"replyToMessageId": reply_to_id} if reply_to_id is not None else {}),
}
return normalized_to, extra