mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
refactor(imessage): dedupe outbound media limit resolve
This commit is contained in:
@@ -3,6 +3,19 @@ import { chunkText } from "../../../auto-reply/chunk.js";
|
||||
import { sendMessageIMessage } from "../../../imessage/send.js";
|
||||
import { resolveChannelMediaMaxBytes } from "../media-limits.js";
|
||||
|
||||
function resolveIMessageMaxBytes(params: {
|
||||
cfg: Parameters<typeof resolveChannelMediaMaxBytes>[0]["cfg"];
|
||||
accountId?: string | null;
|
||||
}) {
|
||||
return resolveChannelMediaMaxBytes({
|
||||
cfg: params.cfg,
|
||||
resolveChannelLimitMb: ({ cfg, accountId }) =>
|
||||
cfg.channels?.imessage?.accounts?.[accountId]?.mediaMaxMb ??
|
||||
cfg.channels?.imessage?.mediaMaxMb,
|
||||
accountId: params.accountId,
|
||||
});
|
||||
}
|
||||
|
||||
export const imessageOutbound: ChannelOutboundAdapter = {
|
||||
deliveryMode: "direct",
|
||||
chunker: chunkText,
|
||||
@@ -10,13 +23,7 @@ export const imessageOutbound: ChannelOutboundAdapter = {
|
||||
textChunkLimit: 4000,
|
||||
sendText: async ({ cfg, to, text, accountId, deps }) => {
|
||||
const send = deps?.sendIMessage ?? sendMessageIMessage;
|
||||
const maxBytes = resolveChannelMediaMaxBytes({
|
||||
cfg,
|
||||
resolveChannelLimitMb: ({ cfg, accountId }) =>
|
||||
cfg.channels?.imessage?.accounts?.[accountId]?.mediaMaxMb ??
|
||||
cfg.channels?.imessage?.mediaMaxMb,
|
||||
accountId,
|
||||
});
|
||||
const maxBytes = resolveIMessageMaxBytes({ cfg, accountId });
|
||||
const result = await send(to, text, {
|
||||
maxBytes,
|
||||
accountId: accountId ?? undefined,
|
||||
@@ -25,13 +32,7 @@ export const imessageOutbound: ChannelOutboundAdapter = {
|
||||
},
|
||||
sendMedia: async ({ cfg, to, text, mediaUrl, mediaLocalRoots, accountId, deps }) => {
|
||||
const send = deps?.sendIMessage ?? sendMessageIMessage;
|
||||
const maxBytes = resolveChannelMediaMaxBytes({
|
||||
cfg,
|
||||
resolveChannelLimitMb: ({ cfg, accountId }) =>
|
||||
cfg.channels?.imessage?.accounts?.[accountId]?.mediaMaxMb ??
|
||||
cfg.channels?.imessage?.mediaMaxMb,
|
||||
accountId,
|
||||
});
|
||||
const maxBytes = resolveIMessageMaxBytes({ cfg, accountId });
|
||||
const result = await send(to, text, {
|
||||
mediaUrl,
|
||||
maxBytes,
|
||||
|
||||
Reference in New Issue
Block a user