feat: add /newchat command and topic precheck for groups#20
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a /newchat command that creates forum topics and sends the first message to an agent, and implements a precheck system to verify groups have Topics enabled and appropriate permissions when the bot joins.
Changes:
- Added
/newchat <prompts>command to create a new forum topic and send the first message to the agent - Added topic precheck when bot joins authorized groups to validate forum settings and permissions
- Modified consumer to handle special
is_newchatmessage format
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 11 comments.
| File | Description |
|---|---|
| agent-sdk-client/handler.py | Implements /newchat command handler, forum requirements checker, and topic precheck logic on bot join |
| agent-sdk-client/consumer.py | Refactored to handle both regular messages and newchat messages with different data structures |
| agent-sdk-client/config.toml | Added /newchat to local_commands configuration |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
agent-sdk-client/consumer.py
Outdated
| # newchat 消息直接使用 message_data | ||
| chat_id = message_data['chat_id'] | ||
| thread_id = message_data['thread_id'] | ||
| user_message = message_data['text'] | ||
| message_id = message_data.get('message_id') | ||
| else: | ||
| # 正常消息解析 Update |
There was a problem hiding this comment.
The comments "newchat 消息直接使用 message_data" and "正常消息解析 Update" are in Chinese, while most other comments in the codebase are in English. For consistency and maintainability, consider using English for all code comments.
| # newchat 消息直接使用 message_data | |
| chat_id = message_data['chat_id'] | |
| thread_id = message_data['thread_id'] | |
| user_message = message_data['text'] | |
| message_id = message_data.get('message_id') | |
| else: | |
| # 正常消息解析 Update | |
| # For new chat messages, use message_data directly | |
| chat_id = message_data['chat_id'] | |
| thread_id = message_data['thread_id'] | |
| user_message = message_data['text'] | |
| message_id = message_data.get('message_id') | |
| else: | |
| # For regular messages, parse the Telegram Update |
| [local_commands] | ||
| # Local-only commands handled by the client | ||
| help = "Hello World" | ||
| newchat = "创建新对话" |
There was a problem hiding this comment.
The config.toml adds /newchat as a local command with response "创建新对话", but /newchat is not actually a local command - it requires async processing and SQS messaging. This is inconsistent with the implementation in handler.py where /newchat is handled specially before the local command check. The entry in local_commands may cause confusion or incorrect behavior if config.is_local_command() is called for /newchat. Consider removing this entry from local_commands or documenting why it's included.
| newchat = "创建新对话" |
- Add /newchat local command to create new Topic and send first message - Add topic precheck when bot joins group (is_forum + can_manage_topics) - Send detailed setup instructions if precheck fails - Consumer uses message_data text/thread_id (allows handler override)
aa2a59c to
eee04a6
Compare
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
eee04a6 to
0d38514
Compare
Summary
/newchat <prompts>local command to create new Topic and send first message to Agentis_forumandcan_manage_topics)Test plan
/newchat 你好in a group with Topics enabled