mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 22:04:31 +00:00
fix(channels): normalize MIME kind parsing and reaction fallbacks
This commit is contained in:
@@ -25,12 +25,12 @@ import { readSessionUpdatedAt, resolveStorePath } from "../../config/sessions.js
|
||||
import { danger, logVerbose, shouldLogVerbose, warn } from "../../globals.js";
|
||||
import { normalizeScpRemoteHost } from "../../infra/scp-host.js";
|
||||
import { waitForTransportReady } from "../../infra/transport-ready.js";
|
||||
import { mediaKindFromMime } from "../../media/constants.js";
|
||||
import {
|
||||
isInboundPathAllowed,
|
||||
resolveIMessageAttachmentRoots,
|
||||
resolveIMessageRemoteAttachmentRoots,
|
||||
} from "../../media/inbound-path-policy.js";
|
||||
import { kindFromMime } from "../../media/mime.js";
|
||||
import { buildPairingReply } from "../../pairing/pairing-messages.js";
|
||||
import {
|
||||
readChannelAllowFromStore,
|
||||
@@ -224,7 +224,7 @@ export async function monitorIMessageProvider(opts: MonitorIMessageOpts = {}): P
|
||||
// Build arrays for all attachments (for multi-image support)
|
||||
const mediaPaths = validAttachments.map((a) => a.original_path).filter(Boolean) as string[];
|
||||
const mediaTypes = validAttachments.map((a) => a.mime_type ?? undefined);
|
||||
const kind = mediaKindFromMime(mediaType ?? undefined);
|
||||
const kind = kindFromMime(mediaType ?? undefined);
|
||||
const placeholder = kind
|
||||
? `<media:${kind}>`
|
||||
: validAttachments.length
|
||||
|
||||
@@ -71,6 +71,19 @@ describe("sendMessageIMessage", () => {
|
||||
expect(params.text).toBe("<media:image>");
|
||||
});
|
||||
|
||||
it("normalizes mixed-case parameterized MIME for attachment placeholder text", async () => {
|
||||
await sendWithDefaults("chat_id:7", "", {
|
||||
mediaUrl: "http://x/voice",
|
||||
resolveAttachmentImpl: async () => ({
|
||||
path: "/tmp/imessage-media.ogg",
|
||||
contentType: " Audio/Ogg; codecs=opus ",
|
||||
}),
|
||||
});
|
||||
const params = getSentParams();
|
||||
expect(params.file).toBe("/tmp/imessage-media.ogg");
|
||||
expect(params.text).toBe("<media:audio>");
|
||||
});
|
||||
|
||||
it("returns message id when rpc provides one", async () => {
|
||||
requestMock.mockResolvedValue({ ok: true, id: 123 });
|
||||
const result = await sendWithDefaults("chat_id:7", "hello");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { loadConfig } from "../config/config.js";
|
||||
import { resolveMarkdownTableMode } from "../config/markdown-tables.js";
|
||||
import { convertMarkdownTables } from "../markdown/tables.js";
|
||||
import { mediaKindFromMime } from "../media/constants.js";
|
||||
import { kindFromMime } from "../media/mime.js";
|
||||
import { resolveOutboundAttachmentFromUrl } from "../media/outbound-attachment.js";
|
||||
import { resolveIMessageAccount, type ResolvedIMessageAccount } from "./accounts.js";
|
||||
import { createIMessageRpcClient, type IMessageRpcClient } from "./client.js";
|
||||
@@ -129,7 +129,7 @@ export async function sendMessageIMessage(
|
||||
});
|
||||
filePath = resolved.path;
|
||||
if (!message.trim()) {
|
||||
const kind = mediaKindFromMime(resolved.contentType ?? undefined);
|
||||
const kind = kindFromMime(resolved.contentType ?? undefined);
|
||||
if (kind) {
|
||||
message = kind === "image" ? "<media:image>" : `<media:${kind}>`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user