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:
committed by
Peter Steinberger
parent
9b7df414e6
commit
83a25d26fc
@@ -35,6 +35,7 @@ export const telegramMessageActions: ChannelMessageActionAdapter = {
|
||||
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");
|
||||
return Array.from(actions);
|
||||
},
|
||||
supportsButtons: ({ cfg }) => hasTelegramInlineButtons(cfg),
|
||||
@@ -92,6 +93,22 @@ export const telegramMessageActions: ChannelMessageActionAdapter = {
|
||||
);
|
||||
}
|
||||
|
||||
if (action === "delete") {
|
||||
const chatId = readStringParam(params, "chatId", { required: true });
|
||||
const messageId = readStringParam(params, "messageId", {
|
||||
required: true,
|
||||
});
|
||||
return await handleTelegramAction(
|
||||
{
|
||||
action: "deleteMessage",
|
||||
chatId,
|
||||
messageId: Number(messageId),
|
||||
accountId: accountId ?? undefined,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
}
|
||||
|
||||
throw new Error(`Action ${action} is not supported for provider ${providerId}.`);
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user