Skip to content

Conversation

@Seayon
Copy link
Contributor

@Seayon Seayon commented Sep 13, 2025

Motivation

大模型响应较慢,除了使用流式回复让用户更有把控感以外,我有个想法,就是 astrbot 接收到请求,在处理前,先用表情回应一下(我在自己的飞书机器人里面这么做的),该 pr 为了实现这个功能

Modifications

为 飞书和 telegram,添加了钩子去触发响应,按照飞书和 telegram 官方的 api 文档,对消息进行了设置。

同时,不是所有的平台都支持这种设置,本次新增了 “平台特异配置” 这种配置方式,方便为不同的消息平台,维护独有的特有的配置。

Check

  • 😊 我的 Commit Message 符合良好的规范
  • 👀 我的更改经过良好的测试
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。
  • 😮 我的更改没有引入恶意代码

一些测试响应的截图

image image image

Sourcery 总结

在处理用户消息之前,启用发送预定义的表情符号反应,以在支持的平台上表示确认。

新功能:

  • 在默认设置中为 Lark 和 Telegram 添加 platform_specific.pre_ack_emoji 配置组
  • 为 Telegram 和 Lark 事件类实现 react 方法,通过平台 API 应用消息反应
  • 集成一个预处理钩子,当消息被接收并指向机器人时,发送一个随机配置的表情符号反应
Original summary in English

Summary by Sourcery

Enable sending predefined emoji reactions before processing user messages to indicate acknowledgement on supported platforms

New Features:

  • Add platform_specific.pre_ack_emoji configuration group for lark and telegram in default settings
  • Implement react methods for Telegram and Lark event classes to apply message reactions via platform APIs
  • Integrate a preprocessing hook that sends a random configured emoji reaction when a message is received and addressed to the bot

支持在收到命令时自动添加表情回应,提升用户交互体验
新增平台特异配置项,允许自定义启用状态和表情列表
@auto-assign auto-assign bot requested review from Raven95676 and Soulter September 13, 2025 09:27
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你好 - 我已审阅了你的更改 - 以下是一些反馈:

  • 避免在预处理钩子中硬编码支持的平台,考虑从 platform_specific 配置的键中派生列表,以便新平台能够自动识别。
  • pre_ack_emoji 配置中暴露 Telegram 的 is_big 标志,以便用户可以选择普通或大型的反应动画。
  • platform_specific_group 键用于存储模式元数据而非运行时设置——将其重命名为 platform_specific_schema 等名称可以使其意图更清晰。
Prompt for AI Agents
请处理此代码审查中的评论:
## Overall Comments
- 避免在预处理钩子中硬编码支持的平台,考虑从 `platform_specific` 配置的键中派生列表,以便新平台能够自动识别。
-`pre_ack_emoji` 配置中暴露 Telegram 的 `is_big` 标志,以便用户可以选择普通或大型的反应动画。
- `platform_specific_group` 键用于存储模式元数据而非运行时设置——将其重命名为 `platform_specific_schema` 等名称可以使其意图更清晰。

## Individual Comments

### 评论 1
<location> `astrbot/core/platform/sources/lark/lark_event.py:110` </location>
<code_context>
         )
         self._has_send_oper = True

+    async def react(self, emoji: str):
+        """对消息添加表情回应。默认实现为发送一条包含该表情的消息。"""
+        await self.send(MessageChain([Plain(emoji)]))
</code_context>

<issue_to_address>
考虑在 Lark 反应 API 调用期间处理异常。

目前,只检查了不成功的响应。考虑使用 try-except 块来捕获和记录意外错误,例如网络故障。
</issue_to_address>

### 评论 2
<location> `astrbot/core/platform/astr_message_event.py:415` </location>
<code_context>
         )
         self._has_send_oper = True

+    async def react(self, emoji: str):
+        """对消息添加表情回应。默认实现为发送一条包含该表情的消息。"""
+        await self.send(MessageChain([Plain(emoji)]))
+
     async def get_group(self, group_id: str = None, **kwargs) -> Optional[Group]:
</code_context>

<issue_to_address>
默认的 'react' 实现可能不适用于所有平台。

请在文档中说明可能需要平台特定的覆盖来实现正确的反应支持,因为发送表情符号消息可能与原生反应行为不匹配。
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
    async def react(self, emoji: str):
        """对消息添加表情回应。默认实现为发送一条包含该表情的消息。"""
        await self.send(MessageChain([Plain(emoji)]))
=======
    async def react(self, emoji: str):
        """
        对消息添加表情回应。

        默认实现为发送一条包含该表情的消息。
        注意:此实现并不一定符合所有平台的原生“表情回应”行为。
        如需支持平台原生的消息反应功能,请在对应平台的子类中重写本方法。
        """
        await self.send(MessageChain([Plain(emoji)]))
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
请帮助我变得更有用!请对每条评论点击 👍 或 👎,我将根据反馈改进你的评论。
Original comment in English

Hey there - I've reviewed your changes - here's some feedback:

  • Instead of hardcoding supported platforms in the preprocess hook, consider deriving the list from the keys of your platform_specific config so new platforms get auto-recognized.
  • Expose the Telegram is_big flag in the pre_ack_emoji config so users can choose between normal or large reaction animations.
  • The platform_specific_group key holds schema metadata rather than runtime settings—renaming it to something like platform_specific_schema could make its intent clearer.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Instead of hardcoding supported platforms in the preprocess hook, consider deriving the list from the keys of your platform_specific config so new platforms get auto-recognized.
- Expose the Telegram `is_big` flag in the pre_ack_emoji config so users can choose between normal or large reaction animations.
- The `platform_specific_group` key holds schema metadata rather than runtime settings—renaming it to something like `platform_specific_schema` could make its intent clearer.

## Individual Comments

### Comment 1
<location> `astrbot/core/platform/sources/lark/lark_event.py:110` </location>
<code_context>
         )
         self._has_send_oper = True

+    async def react(self, emoji: str):
+        """对消息添加表情回应。默认实现为发送一条包含该表情的消息。"""
+        await self.send(MessageChain([Plain(emoji)]))
</code_context>

<issue_to_address>
Consider handling exceptions during the Lark reaction API call.

Currently, only unsuccessful responses are checked. Consider using a try-except block to catch and log unexpected errors, such as network failures.
</issue_to_address>

### Comment 2
<location> `astrbot/core/platform/astr_message_event.py:415` </location>
<code_context>
         )
         self._has_send_oper = True

+    async def react(self, emoji: str):
+        """对消息添加表情回应。默认实现为发送一条包含该表情的消息。"""
+        await self.send(MessageChain([Plain(emoji)]))
+
     async def get_group(self, group_id: str = None, **kwargs) -> Optional[Group]:
</code_context>

<issue_to_address>
The default 'react' implementation may not be suitable for all platforms.

Please clarify in the documentation that platform-specific overrides may be needed for proper reaction support, as sending an emoji message may not match native reaction behavior.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
    async def react(self, emoji: str):
        """对消息添加表情回应。默认实现为发送一条包含该表情的消息。"""
        await self.send(MessageChain([Plain(emoji)]))
=======
    async def react(self, emoji: str):
        """
        对消息添加表情回应。

        默认实现为发送一条包含该表情的消息。
        注意:此实现并不一定符合所有平台的原生“表情回应”行为。
        如需支持平台原生的消息反应功能,请在对应平台的子类中重写本方法。
        """
        await self.send(MessageChain([Plain(emoji)]))
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Soulter Soulter changed the title Feature/pre reaction emoji for message feat: 支持在 Telegram 和飞书下请求 LLM 前预表态功能 Sep 30, 2025
@Soulter
Copy link
Member

Soulter commented Sep 30, 2025

lgtm, 感觉之后如果可以让 llm 来选择表态某个 emoji 也挺有意思的

@Soulter Soulter merged commit a8437d9 into AstrBotDevs:master Sep 30, 2025
5 checks passed
@Seayon
Copy link
Contributor Author

Seayon commented Sep 30, 2025

Member

正有此意,我来研究一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants