mirror of https://github.com/openclaw/openclaw.git
telegram: treat message_id as explicit delete input
This commit is contained in:
parent
55d47c1045
commit
c065d432f0
|
|
@ -216,7 +216,8 @@ export const telegramMessageActions: ChannelMessageActionAdapter = {
|
||||||
|
|
||||||
if (action === "delete") {
|
if (action === "delete") {
|
||||||
const chatId = readTelegramChatIdParam(params);
|
const chatId = readTelegramChatIdParam(params);
|
||||||
const hasMessageIdParam = Object.hasOwn(params, "messageId");
|
const hasMessageIdParam =
|
||||||
|
Object.hasOwn(params, "messageId") || Object.hasOwn(params, "message_id");
|
||||||
const messageId = readTelegramMessageIdParam(params, { required: false });
|
const messageId = readTelegramMessageIdParam(params, { required: false });
|
||||||
if (hasMessageIdParam && typeof messageId !== "number") {
|
if (hasMessageIdParam && typeof messageId !== "number") {
|
||||||
throw new Error("messageId must be a valid number for action=delete.");
|
throw new Error("messageId must be a valid number for action=delete.");
|
||||||
|
|
|
||||||
|
|
@ -892,6 +892,29 @@ describe("telegramMessageActions", () => {
|
||||||
expect(handleTelegramAction).not.toHaveBeenCalled();
|
expect(handleTelegramAction).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("rejects invalid snake_case delete message_id instead of falling back to topic deletion", async () => {
|
||||||
|
const cfg = telegramCfg();
|
||||||
|
const handleAction = telegramMessageActions.handleAction;
|
||||||
|
if (!handleAction) {
|
||||||
|
throw new Error("telegram handleAction unavailable");
|
||||||
|
}
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
handleAction({
|
||||||
|
channel: "telegram",
|
||||||
|
action: "delete",
|
||||||
|
params: {
|
||||||
|
to: "-1001234567890",
|
||||||
|
message_id: "oops",
|
||||||
|
topicId: 271,
|
||||||
|
},
|
||||||
|
cfg,
|
||||||
|
}),
|
||||||
|
).rejects.toThrow(/messageId must be a valid number for action=delete/i);
|
||||||
|
|
||||||
|
expect(handleTelegramAction).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it("rejects topic-delete when threadId/topicId is missing", async () => {
|
it("rejects topic-delete when threadId/topicId is missing", async () => {
|
||||||
const cfg = telegramCfg();
|
const cfg = telegramCfg();
|
||||||
const handleAction = telegramMessageActions.handleAction;
|
const handleAction = telegramMessageActions.handleAction;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue