mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 23:58:25 +00:00
refactor(outbound): dedupe channel handler params
This commit is contained in:
@@ -79,8 +79,7 @@ type ChannelHandler = {
|
|||||||
sendMedia: (caption: string, mediaUrl: string) => Promise<OutboundDeliveryResult>;
|
sendMedia: (caption: string, mediaUrl: string) => Promise<OutboundDeliveryResult>;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Channel docking: outbound delivery delegates to plugin.outbound adapters.
|
type ChannelHandlerParams = {
|
||||||
async function createChannelHandler(params: {
|
|
||||||
cfg: OpenClawConfig;
|
cfg: OpenClawConfig;
|
||||||
channel: Exclude<OutboundChannel, "none">;
|
channel: Exclude<OutboundChannel, "none">;
|
||||||
to: string;
|
to: string;
|
||||||
@@ -92,45 +91,21 @@ async function createChannelHandler(params: {
|
|||||||
gifPlayback?: boolean;
|
gifPlayback?: boolean;
|
||||||
silent?: boolean;
|
silent?: boolean;
|
||||||
mediaLocalRoots?: readonly string[];
|
mediaLocalRoots?: readonly string[];
|
||||||
}): Promise<ChannelHandler> {
|
};
|
||||||
|
|
||||||
|
// Channel docking: outbound delivery delegates to plugin.outbound adapters.
|
||||||
|
async function createChannelHandler(params: ChannelHandlerParams): Promise<ChannelHandler> {
|
||||||
const outbound = await loadChannelOutboundAdapter(params.channel);
|
const outbound = await loadChannelOutboundAdapter(params.channel);
|
||||||
if (!outbound?.sendText || !outbound?.sendMedia) {
|
const handler = createPluginHandler({ ...params, outbound });
|
||||||
throw new Error(`Outbound not configured for channel: ${params.channel}`);
|
|
||||||
}
|
|
||||||
const handler = createPluginHandler({
|
|
||||||
outbound,
|
|
||||||
cfg: params.cfg,
|
|
||||||
channel: params.channel,
|
|
||||||
to: params.to,
|
|
||||||
accountId: params.accountId,
|
|
||||||
replyToId: params.replyToId,
|
|
||||||
threadId: params.threadId,
|
|
||||||
identity: params.identity,
|
|
||||||
deps: params.deps,
|
|
||||||
gifPlayback: params.gifPlayback,
|
|
||||||
silent: params.silent,
|
|
||||||
mediaLocalRoots: params.mediaLocalRoots,
|
|
||||||
});
|
|
||||||
if (!handler) {
|
if (!handler) {
|
||||||
throw new Error(`Outbound not configured for channel: ${params.channel}`);
|
throw new Error(`Outbound not configured for channel: ${params.channel}`);
|
||||||
}
|
}
|
||||||
return handler;
|
return handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createPluginHandler(params: {
|
function createPluginHandler(
|
||||||
outbound?: ChannelOutboundAdapter;
|
params: ChannelHandlerParams & { outbound?: ChannelOutboundAdapter },
|
||||||
cfg: OpenClawConfig;
|
): ChannelHandler | null {
|
||||||
channel: Exclude<OutboundChannel, "none">;
|
|
||||||
to: string;
|
|
||||||
accountId?: string;
|
|
||||||
replyToId?: string | null;
|
|
||||||
threadId?: string | number | null;
|
|
||||||
identity?: OutboundIdentity;
|
|
||||||
deps?: OutboundSendDeps;
|
|
||||||
gifPlayback?: boolean;
|
|
||||||
silent?: boolean;
|
|
||||||
mediaLocalRoots?: readonly string[];
|
|
||||||
}): ChannelHandler | null {
|
|
||||||
const outbound = params.outbound;
|
const outbound = params.outbound;
|
||||||
if (!outbound?.sendText || !outbound?.sendMedia) {
|
if (!outbound?.sendText || !outbound?.sendMedia) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user