资讯动态

IronClaw Telegram 扩展的 remove_reaction 能力:全量清除语义与结果契约解析

发布时间:2026/9/24 17:18:45 来源:尧图企业网站定制
人工智能AI 应用交互助手AI Agent【免费下载链接】ironclawIronClaw is an Agent OS focused on privacy, security and extensibility项目地址https://gitcode.com/gh_mirrors/iro/ironclaw点击查看免费下载本文围绕 IronClaw 开源仓库中 Telegram 扩展包ironclaw_telegram_extension的remove_reaction能力提示文档展开深入讲解该操作一次清除链接账号在消息上的全部表情反应、而非移除单个 emoji的核心语义并结合源码剖析其结果契约、输入模式、权限声明与证据回路实现。读完本文你将掌握telegram.remove_reaction的正确调用方式、它为何在结果中省略emoji字段以及如何在 Agent 工作流中避免因误用而做出失真的操作声明。一、能力提示文档remove_reaction 的语义定位在 IronClaw 的 Telegram 扩展包中remove_reaction是链接账号linked account侧的 15 个工具之一。其能力提示文档位于 crates/extensions/packages/telegram/prompts/telegram/remove_reaction.md全文核心传达两条信息操作语义是全量清除Telegram 会清除链接账号在某条消息上的所有表情反应reactions它无法做到移除指定的某个 emoji 而保留其他 emoji。结果契约是省略 emoji正因为上述语义操作结果即使输入时提供了emoji参数也不会在返回中回显emoji字段以免声称完成了某次并不存在的精确移除。此外文档还明确了能力调用的边界约束host 根据 capability id 选择该操作模型只需提供输入模式input schema所描述的参数不得附带 action 字段。这条提示文档与相邻的 add_reaction.md 形成对照——add_reaction强调emoji 是 Unicode 字符本身如而非:shortname:且每个会话只允许特定 reaction 集合集合外的 emoji 会被拒绝。两者共同定义了 Telegram reaction 相关操作在 IronClaw 中的完整行为边界。二、为什么是全量清除Telegram 底层原语的约束从源码看remove_reaction的实现位于 crates/extensions/packages/telegram/src/linked/ops/writes.rs/// remove_reaction — clears **all** of the linked accounts reactions on the /// message, and says so by omitting emoji. /// /// Telegrams removal primitive is set this accounts reactions to the empty /// set; it cannot remove one named emoji while leaving others. Read-modify- /// write could narrow that, but it would cost an extra flood-prone read and /// still race a concurrent reaction. The honest alternative is the one taken /// here: clear everything and do not echo an emoji the operation did not /// selectively remove. Echoing the requested emoji back would report a /// precision this call does not have. pub(crate) async fn remove_reaction( session: PooledSession, input: Value, ) - ResultValue, ToolError { let (conversation, message_id) message_ref_arg(input)?; let peer conversation.peer_ref(); let client session.connection().client(); vendor_call(session, OpFamily::Write, || { client.send_reactions(peer, message_id, InputReactions::remove()) }) .await?; Ok(mapping::ref_only_result(conversation, message_id)) }关键点在于底层调用client.send_reactions(peer, message_id, InputReactions::remove())——这里使用的是 grammers 客户端的InputReactions::remove()其语义是把该账号在消息上的 reaction 集合置为空集。这是 Telegram 提供的原生原语没有删除单个 emoji的对应调用。源码注释还解释了为什么不采用读-改-写read-modify-write方案来实现单 emoji 移除一次额外的读操作会消耗本已容易触发频率限制flood-prone的网络额度即使在读取后修改仍然会与并发产生的 reaction 产生竞态race无法保证精确性。因此工程上选择了诚实的全量清除既然无法精确移除就不声称精确移除。这也正是该能力提示文档第一条信息的来源。三、结果契约为什么返回中必须省略 emojiremove_reaction的结果由mapping::ref_only_result构造见 crates/extensions/packages/telegram/src/linked/mapping.rs/// Builds the output for a write whose only evidence is the ref the caller /// already held — edit_message and remove_reaction. /// /// Telegrams edit and reaction-clear return no new identity, so re-stating the /// callers ref is the honest maximum: it says *which* message the call acted /// on without claiming a fact the vendor did not supply. pub(crate) fn ref_only_result(conversation: ConversationRef, message_id: i32) - Value { json!({ message_ref: message_ref(conversation, message_id) }) }该函数仅回显调用方已经持有的message_ref消息引用不包含emoji字段。其设计哲学与add_reaction_result形成鲜明对比——add_reaction是唯一允许回显 emoji 的 reaction 操作因为只有它真正针对单个 emoji 生效/// Builds the add_reaction output. The echoed emoji is the models own /// input, not vendor text, and add_reaction is the only reaction op that may /// echo one: remove_reaction clears every reaction this account left, so /// naming one would report a precision the call does not have (§6.3).这段话直接呼应了能力提示文档的第二条信息结果省略emoji即便输入时提供了它。3.1 结果契约的测试验证这条契约并非只是注释约定而是被自动化测试强制约束的。在 crates/extensions/packages/telegram/src/linked/conformance.rs 的证据回路测试中// remove_reaction clears every reaction this account left, so it omits // emoji rather than echoing a precision it does not have (§6.3). let removed mapping::ref_only_result(conversation, 9_001); assert_canonical_output(StandardMessagingOp::RemoveReaction, removed); assert!(removed.get(emoji).is_none(), {removed});assert!(removed.get(emoji).is_none())明确断言remove_reaction的输出中不允许存在emoji字段。这是对提示文档语义的代码级固化——任何未来改动如果试图在结果中回显 emoji都会破坏这条测试。3.2 证据回路evidence loop同一测试文件还展示了 IronClaw 的证据回路设计send_message产出的message_ref可作为后续edit_message、delete_message、add_reaction、remove_reaction的输入证据而每个写操作都要返回自己的证据。remove_reaction返回的message_ref正是它作用于哪条消息的诚实声明——它不声称任何厂商未提供的额外事实如删除了某个具体表情。四、调用方式capability id 路由与输入参数约束能力提示文档明确指出host 根据 capability id 选择该操作模型只提供输入模式描述的参数不要附带 action 字段。4.1 capability id 与路由在 crates/extensions/packages/telegram/manifest.toml 中该工具的声明如下[[tools]] standard_op remove_reaction origin_gate_matrix { loop_run gated_unless_granted, product forbidden, automation forbidden } id telegram.remove_reaction description Telegram notes: Telegram can only clear ALL of the linked accounts reactions on a message, not one named emoji, so the result omits emoji even when one was supplied. effects [use_secret, external_write] default_permission ask visibility model prompt_doc_ref prompts/telegram/remove_reaction.md [[tools.credentials]] handle telegram_linked_session vendor telegram audience { scheme https, host linked-device.telegram.invalid } injection { type header, name x-ironclaw-telegram-linked-session-never-injected }运行期路由在 crates/extensions/packages/telegram/src/linked/tools.rs 中实现bound_op将形如telegram.remove_reaction的 capability id 去掉前缀telegram.后映射到标准操作StandardMessagingOp::RemoveReaction再经由run分发到ops::writes::remove_reaction见同文件 L139-L165。4.2 输入参数只有 message_ref没有 action结合 writes.rs 的实现remove_reaction实际消费的输入参数是参数类型说明message_ref对象目标消息的引用由message_ref_arg(input)解析通常来自send_message等操作返回的证据即使调用方模型在输入中附加了emoji字段实现也不会读取它——实现只调用message_ref_arg解析message_ref随后直接执行全量清除。而不要包含 action 字段的约束源于 IronClaw 的标准消息能力模型操作身份由 capability id如telegram.remove_reaction决定输入只需承载参数数据字段级路由信息是冗余且不允许的。4.3 与 add_reaction 的输入对比add_reaction的输入则必须包含emojiUnicode 字符本身其实现使用InputReactions::emoticon(emoji)构造单表情 reaction。两个操作在emoji参数上的一个必填、一个可忽略正是它们语义差异的直接体现。此外Telegram 每个会话只允许特定 reaction 集合集合外的 emoji 会被拒绝——该错误在 mapping.rs 的错误映射中被归类为REACTION_INVALID PermissionDenied权限拒绝模型收到此错误时应改用会话允许的 emoji 重试。五、权限、安全与运行约束作为写操作remove_reaction被 manifest 声明为origin_gate_matrixloop_run gated_unless_grantedAgent 循环中默认受门控除非已授权、product forbidden、automation forbidden——即该操作禁止在 product产品化流程与 automation自动化流程中使用只能在 Agent 循环中经授权后执行effects[use_secret, external_write]——会使用凭据链接会话并对 Telegram 外部系统产生写入default_permission ask默认每次执行都需用户确认visibility model对模型可见凭据要求telegram_linked_sessionvendor 为telegram且注入类型是永不注入的占位 headerx-ironclaw-telegram-linked-session-never-injected——真正的 MTProto 会话凭据由 host 持有扩展包本身永远看不到原始令牌字节详见 crates/extensions/packages/telegram/README.md。这一套声明的背后是writes.rs文件头部的代码级义务writes.rs本文件内任何操作不得重复调用厂商接口也不得报告其并未获得的结果。remove_reaction省略emoji正是这条义务的具体落地——厂商没有提供已删除某 emoji的事实代码就不允许伪造该事实。六、模型使用最佳实践综合能力提示文档与源码Agent模型在调用telegram.remove_reaction时应遵循以下规则调用前明确目标确认意图是清空该账号在消息上的全部 reaction。若意图是移除单个 emoji应意识到 Telegram 原语不支持可改用add_reaction的语义重新添加期望保留的 reaction或直接告知用户平台限制构造输入仅提供message_ref从send_message、get_message等操作的结果证据中获得不要添加 action 字段也不要依赖emoji参数产生任何效果解读结果返回仅含message_ref不含emoji。这是正常契约不是数据丢失——不要自行推断某个具体 emoji 被删除更不要在面向用户的表述中声称精确移除错误处理若目标消息不存在message_ref_arg解析或厂商调用会返回messaging.unknown_message类错误权限类问题如会话被撤销会返回 re-auth 相关错误应按 mapping.rs 的错误分类引导用户重新链接设备。七、小结从提示文档到证据契约remove_reaction的能力提示文档虽短却浓缩了 IronClaw 扩展体系的三条核心工程原则语义诚实Telegram 只提供置空集合原语扩展包就如实声明清除全部并通过省略emoji拒绝声称不存在的精确度证据可验证每个写操作返回可被后续操作消费的证据message_ref且结果必须通过 conformance.rs 的规范化输出断言权限显式化写操作默认ask确认、禁止 product/automation 场景、凭据由 host 托管模型只负责按 schema 提供参数。理解这份提示文档是正确使用 Telegram 链接账号 reaction 能力、避免在 Agent 工作流中产生失真操作声明的前提。赞分享人工智能AI 应用交互助手AI Agent【免费下载链接】ironclawIronClaw is an Agent OS focused on privacy, security and extensibility项目地址https://gitcode.com/gh_mirrors/iro/ironclaw点击查看免费下载相关推荐Cherry Studio gh-pr-review 代码评审清单A/B/C 三级检查体系与项目规则落地Cherry Studio gh pr review 代码评审清单A/B/C 三级检查体系与项目规则落地 本文以 Cherry Studio 仓库中的自动化代人工智能AI 应用交互助手AI AgentIronClaw 标准消息删除操作 delete_message 契约解析message_ref 溯源、错误语义与 Slack/Telegram 实现对照IronClaw 标准消息删除操作 delete_message 契约解析message_ref 溯源、错误语义与 Slack/Telegram 实现对照 导人工智能AI 应用交互助手AI Agent如何在 Flipper Zero 上创建并运行第一个 JavaScript 应用qFlipper 传输与 CLI 执行如何在 Flipper Zero 上创建并运行第一个 JavaScript 应用qFlipper 传输与 CLI 执行 这篇文档解决一个具体任务在 Fli人工智能AI 应用交互助手AI Agent上一篇技术栈识别指南awesome-copilot 中 acquire-codebase-knowledge 的 Stack Detection 参考手册下一篇OneKGPd 命令参考与实战指南在 scientific-agent-skills 中基于 1000 Genomes Project 做个体级变异查询创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价