openclaw/src/channels/plugins/actions/telegram.ts
A. Duk 284b54af42
feat: Add support for Telegram quote (partial message replies) (#2900)
* feat: Add support for Telegram quote (partial message replies)

- Enhanced describeReplyTarget() to detect and extract quoted text from msg.quote
- Updated reply formatting to distinguish between full message replies and quotes
- Added isQuote flag to replyTarget object for proper identification
- Quote replies show as [Quoting user] "quoted text" [/Quoting]
- Regular replies unchanged: [Replying to user] full message [/Replying]

Resolves need for partial message reply support in Telegram Bot API.
Backward compatible with existing reply functionality.

* updating references

* Mac: finish Moltbot rename

* Mac: finish Moltbot rename (paths)

* fix(macOS): rename Clawdbot directories to Moltbot for naming consistency

Directory renames:
- apps/macos/Sources/Clawdbot → Moltbot
- apps/macos/Sources/ClawdbotDiscovery → MoltbotDiscovery
- apps/macos/Sources/ClawdbotIPC → MoltbotIPC
- apps/macos/Sources/ClawdbotMacCLI → MoltbotMacCLI
- apps/macos/Sources/ClawdbotProtocol → MoltbotProtocol
- apps/macos/Tests/ClawdbotIPCTests → MoltbotIPCTests
- apps/shared/ClawdbotKit → MoltbotKit
- apps/shared/MoltbotKit/Sources/Clawdbot* → Moltbot*
- apps/shared/MoltbotKit/Tests/ClawdbotKitTests → MoltbotKitTests

Resource renames:
- Clawdbot.icns → Moltbot.icns

Code fixes:
- Update Package.swift paths to reference Moltbot* directories
- Fix clawdbot* → moltbot* symbol references in Swift code:
  - clawdbotManagedPaths → moltbotManagedPaths
  - clawdbotExecutable → moltbotExecutable
  - clawdbotCommand → moltbotCommand
  - clawdbotNodeCommand → moltbotNodeCommand
  - clawdbotOAuthDirEnv → moltbotOAuthDirEnv
  - clawdbotSelectSettingsTab → moltbotSelectSettingsTab

* fix: update remaining ClawdbotKit path references to MoltbotKit

- scripts/bundle-a2ui.sh: A2UI_APP_DIR path
- package.json: format:swift and protocol:check paths
- scripts/protocol-gen-swift.ts: output paths
- .github/dependabot.yml: directory path and comment
- .gitignore: build cache paths
- .swiftformat: exclusion paths
- .swiftlint.yml: exclusion path
- apps/android/app/build.gradle.kts: assets.srcDir path
- apps/ios/project.yml: package path
- apps/ios/README.md: documentation reference
- docs/concepts/typebox.md: documentation reference
- apps/shared/MoltbotKit/Package.swift: fix argument order

* chore: update Package.resolved after dependency resolution

* fix: add MACOS_APP_SOURCES_DIR constant and update test to use new path

The cron-protocol-conformance test was using LEGACY_MACOS_APP_SOURCES_DIR
which points to the old Clawdbot path. Added a new MACOS_APP_SOURCES_DIR
constant for the current Moltbot path and updated the test to use it.

* fix: finish Moltbot macOS rename (#2844) (thanks @fal3)

* Extensions: use workspace moltbot in memory-core

* fix(security): recognize Venice-style claude-opus-45 as top-tier model

The security audit was incorrectly flagging venice/claude-opus-45 as
'Below Claude 4.5' because the regex expected -4-5 (with dash) but
Venice uses -45 (without dash between 4 and 5).

Updated isClaude45OrHigher() regex to match both formats.
Added test case to prevent regression.

* Branding: update bot.molt bundle IDs + launchd labels

* Branding: remove legacy android packages

* fix: wire telegram quote support (#2900)

Co-authored-by: aduk059 <aduk059@users.noreply.github.com>

* fix: support Telegram quote replies (#2900) (thanks @aduk059)

---------

Co-authored-by: Gustavo Madeira Santana <gumadeiras@users.noreply.github.com>
Co-authored-by: Shadow <shadow@clawd.bot>
Co-authored-by: Alex Fallah <alexfallah7@gmail.com>
Co-authored-by: Josh Palmer <joshp123@users.noreply.github.com>
Co-authored-by: jonisjongithub <jonisjongithub@users.noreply.github.com>
Co-authored-by: Gustavo Madeira Santana <gumadeiras@gmail.com>
Co-authored-by: aduk059 <aduk059@users.noreply.github.com>
2026-01-27 15:59:24 -05:00

189 lines
6.4 KiB
TypeScript

import {
createActionGate,
readNumberParam,
readStringArrayParam,
readStringOrNumberParam,
readStringParam,
} from "../../../agents/tools/common.js";
import { handleTelegramAction } from "../../../agents/tools/telegram-actions.js";
import { listEnabledTelegramAccounts } from "../../../telegram/accounts.js";
import { isTelegramInlineButtonsEnabled } from "../../../telegram/inline-buttons.js";
import type { ChannelMessageActionAdapter, ChannelMessageActionName } from "../types.js";
const providerId = "telegram";
function readTelegramSendParams(params: Record<string, unknown>) {
const to = readStringParam(params, "to", { required: true });
const mediaUrl = readStringParam(params, "media", { trim: false });
const message = readStringParam(params, "message", { required: !mediaUrl, allowEmpty: true });
const caption = readStringParam(params, "caption", { allowEmpty: true });
const content = message || caption || "";
const replyTo = readStringParam(params, "replyTo");
const threadId = readStringParam(params, "threadId");
const buttons = params.buttons;
const asVoice = typeof params.asVoice === "boolean" ? params.asVoice : undefined;
const silent = typeof params.silent === "boolean" ? params.silent : undefined;
const quoteText = readStringParam(params, "quoteText");
return {
to,
content,
mediaUrl: mediaUrl ?? undefined,
replyToMessageId: replyTo ?? undefined,
messageThreadId: threadId ?? undefined,
buttons,
asVoice,
silent,
quoteText: quoteText ?? undefined,
};
}
export const telegramMessageActions: ChannelMessageActionAdapter = {
listActions: ({ cfg }) => {
const accounts = listEnabledTelegramAccounts(cfg).filter(
(account) => account.tokenSource !== "none",
);
if (accounts.length === 0) return [];
const gate = createActionGate(cfg.channels?.telegram?.actions);
const actions = new Set<ChannelMessageActionName>(["send"]);
if (gate("reactions")) actions.add("react");
if (gate("deleteMessage")) actions.add("delete");
if (gate("editMessage")) actions.add("edit");
if (gate("sticker", false)) {
actions.add("sticker");
actions.add("sticker-search");
}
return Array.from(actions);
},
supportsButtons: ({ cfg }) => {
const accounts = listEnabledTelegramAccounts(cfg).filter(
(account) => account.tokenSource !== "none",
);
if (accounts.length === 0) return false;
return accounts.some((account) =>
isTelegramInlineButtonsEnabled({ cfg, accountId: account.accountId }),
);
},
extractToolSend: ({ args }) => {
const action = typeof args.action === "string" ? args.action.trim() : "";
if (action !== "sendMessage") return null;
const to = typeof args.to === "string" ? args.to : undefined;
if (!to) return null;
const accountId = typeof args.accountId === "string" ? args.accountId.trim() : undefined;
return { to, accountId };
},
handleAction: async ({ action, params, cfg, accountId }) => {
if (action === "send") {
const sendParams = readTelegramSendParams(params);
return await handleTelegramAction(
{
action: "sendMessage",
...sendParams,
accountId: accountId ?? undefined,
},
cfg,
);
}
if (action === "react") {
const messageId = readStringParam(params, "messageId", {
required: true,
});
const emoji = readStringParam(params, "emoji", { allowEmpty: true });
const remove = typeof params.remove === "boolean" ? params.remove : undefined;
return await handleTelegramAction(
{
action: "react",
chatId:
readStringParam(params, "chatId") ?? readStringParam(params, "to", { required: true }),
messageId,
emoji,
remove,
accountId: accountId ?? undefined,
},
cfg,
);
}
if (action === "delete") {
const chatId =
readStringOrNumberParam(params, "chatId") ??
readStringOrNumberParam(params, "channelId") ??
readStringParam(params, "to", { required: true });
const messageId = readNumberParam(params, "messageId", {
required: true,
integer: true,
});
return await handleTelegramAction(
{
action: "deleteMessage",
chatId,
messageId,
accountId: accountId ?? undefined,
},
cfg,
);
}
if (action === "edit") {
const chatId =
readStringOrNumberParam(params, "chatId") ??
readStringOrNumberParam(params, "channelId") ??
readStringParam(params, "to", { required: true });
const messageId = readNumberParam(params, "messageId", {
required: true,
integer: true,
});
const message = readStringParam(params, "message", { required: true, allowEmpty: false });
const buttons = params.buttons;
return await handleTelegramAction(
{
action: "editMessage",
chatId,
messageId,
content: message,
buttons,
accountId: accountId ?? undefined,
},
cfg,
);
}
if (action === "sticker") {
const to =
readStringParam(params, "to") ?? readStringParam(params, "target", { required: true });
// Accept stickerId (array from shared schema) and use first element as fileId
const stickerIds = readStringArrayParam(params, "stickerId");
const fileId = stickerIds?.[0] ?? readStringParam(params, "fileId", { required: true });
const replyToMessageId = readNumberParam(params, "replyTo", { integer: true });
const messageThreadId = readNumberParam(params, "threadId", { integer: true });
return await handleTelegramAction(
{
action: "sendSticker",
to,
fileId,
replyToMessageId: replyToMessageId ?? undefined,
messageThreadId: messageThreadId ?? undefined,
accountId: accountId ?? undefined,
},
cfg,
);
}
if (action === "sticker-search") {
const query = readStringParam(params, "query", { required: true });
const limit = readNumberParam(params, "limit", { integer: true });
return await handleTelegramAction(
{
action: "searchSticker",
query,
limit: limit ?? undefined,
accountId: accountId ?? undefined,
},
cfg,
);
}
throw new Error(`Action ${action} is not supported for provider ${providerId}.`);
},
};