From 5e7a0c5c0a9f22f8cab26eecc173c11c8dd0c53b Mon Sep 17 00:00:00 2001 From: Mariano Belinky Date: Sat, 7 Feb 2026 22:58:08 +0100 Subject: [PATCH] Core: pass plugin command context --- src/auto-reply/reply/commands-plugin.ts | 6 ++++++ src/plugins/commands.ts | 10 ++++++++++ src/plugins/types.ts | 12 +++++++++++- src/telegram/bot-native-commands.ts | 8 ++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/auto-reply/reply/commands-plugin.ts b/src/auto-reply/reply/commands-plugin.ts index 6cfc4f0f1fd..7371b102605 100644 --- a/src/auto-reply/reply/commands-plugin.ts +++ b/src/auto-reply/reply/commands-plugin.ts @@ -35,9 +35,15 @@ export const handlePluginCommand: CommandHandler = async ( args: match.args, senderId: command.senderId, channel: command.channel, + channelId: command.channelId, isAuthorizedSender: command.isAuthorizedSender, commandBody: command.commandBodyNormalized, config: cfg, + from: command.from, + to: command.to, + accountId: params.ctx.AccountId ?? undefined, + messageThreadId: + typeof params.ctx.MessageThreadId === "number" ? params.ctx.MessageThreadId : undefined, }); return { diff --git a/src/plugins/commands.ts b/src/plugins/commands.ts index fa7f328e2e7..ff41b14d6fe 100644 --- a/src/plugins/commands.ts +++ b/src/plugins/commands.ts @@ -229,9 +229,14 @@ export async function executePluginCommand(params: { args?: string; senderId?: string; channel: string; + channelId?: PluginCommandContext["channelId"]; isAuthorizedSender: boolean; commandBody: string; config: OpenClawConfig; + from?: PluginCommandContext["from"]; + to?: PluginCommandContext["to"]; + accountId?: PluginCommandContext["accountId"]; + messageThreadId?: PluginCommandContext["messageThreadId"]; }): Promise { const { command, args, senderId, channel, isAuthorizedSender, commandBody, config } = params; @@ -250,10 +255,15 @@ export async function executePluginCommand(params: { const ctx: PluginCommandContext = { senderId, channel, + channelId: params.channelId, isAuthorizedSender, args: sanitizedArgs, commandBody, config, + from: params.from, + to: params.to, + accountId: params.accountId, + messageThreadId: params.messageThreadId, }; // Lock registry during execution to prevent concurrent modifications diff --git a/src/plugins/types.ts b/src/plugins/types.ts index 4dbab48ff14..6ddcb9eef98 100644 --- a/src/plugins/types.ts +++ b/src/plugins/types.ts @@ -5,7 +5,7 @@ import type { AuthProfileCredential, OAuthCredential } from "../agents/auth-prof import type { AnyAgentTool } from "../agents/tools/common.js"; import type { ReplyPayload } from "../auto-reply/types.js"; import type { ChannelDock } from "../channels/dock.js"; -import type { ChannelPlugin } from "../channels/plugins/types.js"; +import type { ChannelId, ChannelPlugin } from "../channels/plugins/types.js"; import type { createVpsAwareOAuthHandlers } from "../commands/oauth-flow.js"; import type { OpenClawConfig } from "../config/config.js"; import type { ModelProviderConfig } from "../config/types.js"; @@ -140,6 +140,8 @@ export type PluginCommandContext = { senderId?: string; /** The channel/surface (e.g., "telegram", "discord") */ channel: string; + /** Provider channel id (e.g., "telegram") */ + channelId?: ChannelId; /** Whether the sender is on the allowlist */ isAuthorizedSender: boolean; /** Raw command arguments after the command name */ @@ -148,6 +150,14 @@ export type PluginCommandContext = { commandBody: string; /** Current OpenClaw configuration */ config: OpenClawConfig; + /** Raw "From" value (channel-scoped id) */ + from?: string; + /** Raw "To" value (channel-scoped id) */ + to?: string; + /** Account id for multi-account channels */ + accountId?: string; + /** Thread/topic id if available */ + messageThreadId?: number; }; /** diff --git a/src/telegram/bot-native-commands.ts b/src/telegram/bot-native-commands.ts index 8f6c7b2b30c..26eee0e4513 100644 --- a/src/telegram/bot-native-commands.ts +++ b/src/telegram/bot-native-commands.ts @@ -675,6 +675,10 @@ export const registerTelegramNativeCommands = ({ isForum, messageThreadId, }); + const from = isGroup + ? buildTelegramGroupFrom(chatId, threadSpec.id) + : `telegram:${chatId}`; + const to = `telegram:${chatId}`; const result = await executePluginCommand({ command: match.command, @@ -684,6 +688,10 @@ export const registerTelegramNativeCommands = ({ isAuthorizedSender: commandAuthorized, commandBody, config: cfg, + from, + to, + accountId, + messageThreadId: threadSpec.id, }); const tableMode = resolveMarkdownTableMode({ cfg,