feat(telegram): support business chat automation - #35342
Conversation
…s-chat-automation # Conflicts: # gateway/run.py
7a4ef8b to
ad81301
Compare
|
Resolved the merge conflicts by merging current On overlap with #26654 / #29727: agreed this is in the same Telegram Business area, but this PR is scoped around the Chat Automation reply path:
#29727 looks focused on passive inbox persistence/diagnostics, while #26654 covers delegated inbox invocation/safe-mode behavior. If maintainers prefer consolidation, this PR can either be rebased on the chosen base PR or narrowed to the reply-routing/autoresponder pieces. |
teknium1
left a comment
There was a problem hiding this comment.
Thanks for the detailed Business routing work. The capability is still absent on current main, but this patch needs a plugin-era, security-conscious rework before it can be salvaged.
Problems
- The main implementation target,
gateway/platforms/telegram.py, was moved by5600105478ffde29d7566b45421b100eaa29c4eftoplugins/platforms/telegram/adapter.py; this branch is currentlyCONFLICTING/DIRTY. gateway/platforms/telegram.py:6000substitutes the Business owner intosource.user_id. Gateway authorization reads that field (gateway/authz_mixin.py:317,:455-459), so an external contact would receive the owner's full agent path rather than restricted handling.gateway/platforms/telegram.py:2026adds the connection ID only to text sends; media paths such assend_voice(:3793-3801) andsend_media_group(:3958-3965) omit it.gateway/session.py:396hardcodes Anton, Russian responses, and a fixed message into every Business session.
Suggested changes
- Port the capability to
plugins/platforms/telegram/adapter.py(or the standalone-plugin handler path proposed in #59159), preserving current intake behavior atplugins/platforms/telegram/adapter.py:7517. - Keep external contacts untrusted, add explicit restricted execution, centralize Business metadata propagation across all outbound paths, and make autoresponder policy user-configured.
Automated hermes-sweeper review.
| str(user.id) | ||
| if user | ||
| else (str(chat.id) if chat_type in {"dm", "channel"} else None) | ||
| str(business_owner_id) |
There was a problem hiding this comment.
This maps an untrusted external contact to the owner's source.user_id, which is the identity consumed by gateway authorization. That grants the contact the owner's full agent/tool path rather than a restricted Business-contact path; keep caller identity separate from verified connection ownership.
| parse_mode=ParseMode.MARKDOWN_V2, | ||
| reply_to_message_id=reply_to_id, | ||
| **thread_kwargs, | ||
| **business_kwargs, |
There was a problem hiding this comment.
This only propagates business_connection_id for text sends. The same metadata must be applied to the adapter's native voice, media-group, photo, document, video, image, animation, and streaming-edit paths, otherwise those replies take a different route.
| if getattr(context.source, "telegram_business_connection_id", None): | ||
| lines.append("") | ||
| lines.append( | ||
| "**Telegram Business / Chat Automation instructions:** You are Anton's autoresponder. " |
There was a problem hiding this comment.
This is product-user-specific behavior embedded in a generic session prompt. Move the responder identity, language, and escalation text into opt-in user configuration or a skill so Telegram Business support is reusable.
Summary
business_connection_idin session/source metadata and outbound send/chat-action callsTest Plan
python -m py_compile gateway/platforms/base.py gateway/platforms/telegram.py gateway/run.py gateway/session.py tests/gateway/test_telegram_thread_fallback.pypytest -q tests/gateway/test_telegram_thread_fallback.pypytest -q tests/gateway/test_telegram_send_path_health.py tests/gateway/test_telegram_reply_mode.py tests/gateway/test_telegram_noise_filter.py