mirror of https://github.com/openclaw/openclaw.git
fix(telegram): include reply hook metadata
This commit is contained in:
parent
9830b7c298
commit
5b8fc68ea2
|
|
@ -459,7 +459,12 @@ export async function deliverReplies(params: {
|
|||
});
|
||||
for (const originalReply of params.replies) {
|
||||
let reply = originalReply;
|
||||
const hasMedia = Boolean(reply?.mediaUrl) || (reply?.mediaUrls?.length ?? 0) > 0;
|
||||
const mediaList = reply.mediaUrls?.length
|
||||
? reply.mediaUrls
|
||||
: reply.mediaUrl
|
||||
? [reply.mediaUrl]
|
||||
: [];
|
||||
const hasMedia = mediaList.length > 0;
|
||||
if (!reply?.text && !hasMedia) {
|
||||
if (reply?.audioAsVoice) {
|
||||
logVerbose("telegram reply has audioAsVoice without media/text; skipping");
|
||||
|
|
@ -475,6 +480,11 @@ export async function deliverReplies(params: {
|
|||
{
|
||||
to: params.chatId,
|
||||
content: rawContent,
|
||||
metadata: {
|
||||
channel: "telegram",
|
||||
mediaUrls: mediaList,
|
||||
threadId: params.thread?.id,
|
||||
},
|
||||
},
|
||||
{
|
||||
channelId: "telegram",
|
||||
|
|
@ -495,11 +505,6 @@ export async function deliverReplies(params: {
|
|||
const deliveredCountBeforeReply = progress.deliveredCount;
|
||||
const replyToId =
|
||||
params.replyToMode === "off" ? undefined : resolveTelegramReplyId(reply.replyToId);
|
||||
const mediaList = reply.mediaUrls?.length
|
||||
? reply.mediaUrls
|
||||
: reply.mediaUrl
|
||||
? [reply.mediaUrl]
|
||||
: [];
|
||||
const telegramData = reply.channelData?.telegram as
|
||||
| { buttons?: TelegramInlineButtons }
|
||||
| undefined;
|
||||
|
|
|
|||
|
|
@ -149,6 +149,34 @@ describe("deliverReplies", () => {
|
|||
);
|
||||
});
|
||||
|
||||
it("passes media metadata to message_sending hooks", async () => {
|
||||
messageHookRunner.hasHooks.mockImplementation((name: string) => name === "message_sending");
|
||||
|
||||
const runtime = createRuntime(false);
|
||||
const sendPhoto = vi.fn().mockResolvedValue({ message_id: 2, chat: { id: "123" } });
|
||||
const bot = createBot({ sendPhoto });
|
||||
|
||||
mockMediaLoad("photo.jpg", "image/jpeg", "image");
|
||||
|
||||
await deliverWith({
|
||||
replies: [{ text: "caption", mediaUrl: "https://example.com/photo.jpg" }],
|
||||
runtime,
|
||||
bot,
|
||||
});
|
||||
|
||||
expect(messageHookRunner.runMessageSending).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
to: "123",
|
||||
content: "caption",
|
||||
metadata: expect.objectContaining({
|
||||
channel: "telegram",
|
||||
mediaUrls: ["https://example.com/photo.jpg"],
|
||||
}),
|
||||
}),
|
||||
expect.objectContaining({ channelId: "telegram", conversationId: "123" }),
|
||||
);
|
||||
});
|
||||
|
||||
it("invokes onVoiceRecording before sending a voice note", async () => {
|
||||
const events: string[] = [];
|
||||
const runtime = createRuntime(false);
|
||||
|
|
|
|||
Loading…
Reference in New Issue