refactor(outbound): dedupe plugin outbound context
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import type { ReplyPayload } from "../../auto-reply/types.js";
|
||||
import type { ChannelOutboundAdapter } from "../../channels/plugins/types.js";
|
||||
import type {
|
||||
ChannelOutboundAdapter,
|
||||
ChannelOutboundContext,
|
||||
} from "../../channels/plugins/types.js";
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import type { sendMessageDiscord } from "../../discord/send.js";
|
||||
import type { sendMessageIMessage } from "../../imessage/send.js";
|
||||
@@ -110,6 +113,7 @@ function createPluginHandler(
|
||||
if (!outbound?.sendText || !outbound?.sendMedia) {
|
||||
return null;
|
||||
}
|
||||
const baseCtx = createChannelOutboundContextBase(params);
|
||||
const sendText = outbound.sendText;
|
||||
const sendMedia = outbound.sendMedia;
|
||||
const chunker = outbound.chunker ?? null;
|
||||
@@ -121,53 +125,43 @@ function createPluginHandler(
|
||||
sendPayload: outbound.sendPayload
|
||||
? async (payload) =>
|
||||
outbound.sendPayload!({
|
||||
cfg: params.cfg,
|
||||
to: params.to,
|
||||
...baseCtx,
|
||||
text: payload.text ?? "",
|
||||
mediaUrl: payload.mediaUrl,
|
||||
accountId: params.accountId,
|
||||
replyToId: params.replyToId,
|
||||
threadId: params.threadId,
|
||||
identity: params.identity,
|
||||
gifPlayback: params.gifPlayback,
|
||||
deps: params.deps,
|
||||
silent: params.silent,
|
||||
mediaLocalRoots: params.mediaLocalRoots,
|
||||
payload,
|
||||
})
|
||||
: undefined,
|
||||
sendText: async (text) =>
|
||||
sendText({
|
||||
cfg: params.cfg,
|
||||
to: params.to,
|
||||
...baseCtx,
|
||||
text,
|
||||
accountId: params.accountId,
|
||||
replyToId: params.replyToId,
|
||||
threadId: params.threadId,
|
||||
identity: params.identity,
|
||||
gifPlayback: params.gifPlayback,
|
||||
deps: params.deps,
|
||||
silent: params.silent,
|
||||
mediaLocalRoots: params.mediaLocalRoots,
|
||||
}),
|
||||
sendMedia: async (caption, mediaUrl) =>
|
||||
sendMedia({
|
||||
cfg: params.cfg,
|
||||
to: params.to,
|
||||
...baseCtx,
|
||||
text: caption,
|
||||
mediaUrl,
|
||||
accountId: params.accountId,
|
||||
replyToId: params.replyToId,
|
||||
threadId: params.threadId,
|
||||
identity: params.identity,
|
||||
gifPlayback: params.gifPlayback,
|
||||
deps: params.deps,
|
||||
silent: params.silent,
|
||||
mediaLocalRoots: params.mediaLocalRoots,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
function createChannelOutboundContextBase(
|
||||
params: ChannelHandlerParams,
|
||||
): Omit<ChannelOutboundContext, "text" | "mediaUrl"> {
|
||||
return {
|
||||
cfg: params.cfg,
|
||||
to: params.to,
|
||||
accountId: params.accountId,
|
||||
replyToId: params.replyToId,
|
||||
threadId: params.threadId,
|
||||
identity: params.identity,
|
||||
gifPlayback: params.gifPlayback,
|
||||
deps: params.deps,
|
||||
silent: params.silent,
|
||||
mediaLocalRoots: params.mediaLocalRoots,
|
||||
};
|
||||
}
|
||||
|
||||
const isAbortError = (err: unknown): boolean => err instanceof Error && err.name === "AbortError";
|
||||
|
||||
type DeliverOutboundPayloadsCoreParams = {
|
||||
|
||||
Reference in New Issue
Block a user