mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 02:34:32 +00:00
telegram: align sent hooks with command session
This commit is contained in:
@@ -595,17 +595,6 @@ export const registerTelegramNativeCommands = ({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { threadSpec, route, mediaLocalRoots, tableMode, chunkMode } = runtimeContext;
|
const { threadSpec, route, mediaLocalRoots, tableMode, chunkMode } = runtimeContext;
|
||||||
const deliveryBaseOptions = buildCommandDeliveryBaseOptions({
|
|
||||||
chatId,
|
|
||||||
accountId: route.accountId,
|
|
||||||
sessionKeyForInternalHooks: route.sessionKey,
|
|
||||||
mirrorIsGroup: isGroup,
|
|
||||||
mirrorGroupId: isGroup ? String(chatId) : undefined,
|
|
||||||
mediaLocalRoots,
|
|
||||||
threadSpec,
|
|
||||||
tableMode,
|
|
||||||
chunkMode,
|
|
||||||
});
|
|
||||||
const threadParams = buildTelegramThreadParams(threadSpec) ?? {};
|
const threadParams = buildTelegramThreadParams(threadSpec) ?? {};
|
||||||
|
|
||||||
const commandDefinition = findCommandByNativeName(command.name, "telegram");
|
const commandDefinition = findCommandByNativeName(command.name, "telegram");
|
||||||
@@ -680,6 +669,17 @@ export const registerTelegramNativeCommands = ({
|
|||||||
userId: String(senderId || chatId),
|
userId: String(senderId || chatId),
|
||||||
targetSessionKey: sessionKey,
|
targetSessionKey: sessionKey,
|
||||||
});
|
});
|
||||||
|
const deliveryBaseOptions = buildCommandDeliveryBaseOptions({
|
||||||
|
chatId,
|
||||||
|
accountId: route.accountId,
|
||||||
|
sessionKeyForInternalHooks: commandSessionKey,
|
||||||
|
mirrorIsGroup: isGroup,
|
||||||
|
mirrorGroupId: isGroup ? String(chatId) : undefined,
|
||||||
|
mediaLocalRoots,
|
||||||
|
threadSpec,
|
||||||
|
tableMode,
|
||||||
|
chunkMode,
|
||||||
|
});
|
||||||
const conversationLabel = isGroup
|
const conversationLabel = isGroup
|
||||||
? msg.chat.title
|
? msg.chat.title
|
||||||
? `${msg.chat.title} id:${chatId}`
|
? `${msg.chat.title} id:${chatId}`
|
||||||
|
|||||||
@@ -258,6 +258,37 @@ describe("deliverReplies", () => {
|
|||||||
expect(triggerInternalHook).not.toHaveBeenCalled();
|
expect(triggerInternalHook).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("emits internal message:sent with success=false on delivery failure", async () => {
|
||||||
|
const runtime = createRuntime(false);
|
||||||
|
const sendMessage = vi.fn().mockRejectedValue(new Error("network error"));
|
||||||
|
const bot = createBot({ sendMessage });
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
deliverWith({
|
||||||
|
sessionKeyForInternalHooks: "agent:test:telegram:123",
|
||||||
|
replies: [{ text: "hello" }],
|
||||||
|
runtime,
|
||||||
|
bot,
|
||||||
|
}),
|
||||||
|
).rejects.toThrow("network error");
|
||||||
|
|
||||||
|
expect(triggerInternalHook).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
type: "message",
|
||||||
|
action: "sent",
|
||||||
|
sessionKey: "agent:test:telegram:123",
|
||||||
|
context: expect.objectContaining({
|
||||||
|
to: "123",
|
||||||
|
content: "hello",
|
||||||
|
success: false,
|
||||||
|
error: "network error",
|
||||||
|
channelId: "telegram",
|
||||||
|
conversationId: "123",
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("passes media metadata to message_sending hooks", async () => {
|
it("passes media metadata to message_sending hooks", async () => {
|
||||||
messageHookRunner.hasHooks.mockImplementation((name: string) => name === "message_sending");
|
messageHookRunner.hasHooks.mockImplementation((name: string) => name === "message_sending");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user