feat(telegram): add deleteMessage action

Add ability to delete messages in Telegram chats via the message tool.

Changes:
- Add deleteMessageTelegram function in send.ts
- Add deleteMessage action handler in telegram-actions.ts
- Add delete action support in telegram message plugin adapter
- Add deleteMessage to TelegramActionConfig type
- Update message tool description to mention delete action

Usage:
- Via message tool: action="delete", chatId, messageId
- Can be disabled via channels.telegram.actions.deleteMessage=false

Limitations (Telegram API):
- Bot can delete its own messages in any chat
- Bot can delete others' messages only if admin with "Delete Messages"
- Messages older than 48h in groups may fail to delete
This commit is contained in:
sleontenko
2026-01-14 22:20:17 +02:00
committed by Peter Steinberger
parent 9b7df414e6
commit 83a25d26fc
5 changed files with 86 additions and 2 deletions

View File

@@ -148,7 +148,7 @@ export function createMessageTool(options?: MessageToolOptions): AnyAgentTool {
label: "Message",
name: "message",
description:
"Send messages and channel actions (polls, reactions, pins, threads, etc.) via configured channel plugins.",
"Send, delete, and manage messages via channel plugins. Supports actions: send, delete, react, poll, pin, threads, and more.",
parameters: schema,
execute: async (_toolCallId, args) => {
const params = args as Record<string, unknown>;

View File

@@ -1,7 +1,11 @@
import type { AgentToolResult } from "@mariozechner/pi-agent-core";
import { resolveChannelCapabilities } from "../../config/channel-capabilities.js";
import type { ClawdbotConfig } from "../../config/config.js";
import { reactMessageTelegram, sendMessageTelegram } from "../../telegram/send.js";
import {
deleteMessageTelegram,
reactMessageTelegram,
sendMessageTelegram,
} from "../../telegram/send.js";
import { resolveTelegramToken } from "../../telegram/token.js";
import {
createActionGate,
@@ -149,5 +153,29 @@ export async function handleTelegramAction(
});
}
if (action === "deleteMessage") {
if (!isActionEnabled("deleteMessage")) {
throw new Error("Telegram deleteMessage is disabled.");
}
const chatId = readStringOrNumberParam(params, "chatId", {
required: true,
});
const messageId = readNumberParam(params, "messageId", {
required: true,
integer: true,
});
const token = resolveTelegramToken(cfg, { accountId }).token;
if (!token) {
throw new Error(
"Telegram bot token missing. Set TELEGRAM_BOT_TOKEN or channels.telegram.botToken.",
);
}
await deleteMessageTelegram(chatId ?? "", messageId ?? 0, {
token,
accountId: accountId ?? undefined,
});
return jsonResult({ ok: true, deleted: true });
}
throw new Error(`Unsupported Telegram action: ${action}`);
}