refactor(plugins): move channel behavior into plugins

This commit is contained in:
Peter Steinberger
2026-04-03 17:54:01 +01:00
parent c52df32878
commit ab96520bba
158 changed files with 5967 additions and 5054 deletions

View File

@@ -0,0 +1,47 @@
import { loadChannelOutboundAdapter } from "../../channels/plugins/outbound/load.js";
import type { ChannelId } from "../../channels/plugins/types.js";
import { loadConfig } from "../../config/config.js";
type RuntimeSendOpts = {
cfg?: ReturnType<typeof loadConfig>;
mediaUrl?: string;
mediaLocalRoots?: readonly string[];
accountId?: string;
messageThreadId?: string | number;
replyToMessageId?: string | number;
silent?: boolean;
forceDocument?: boolean;
gifPlayback?: boolean;
gatewayClientScopes?: readonly string[];
};
export function createChannelOutboundRuntimeSend(params: {
channelId: ChannelId;
unavailableMessage: string;
}) {
return {
sendMessage: async (to: string, text: string, opts: RuntimeSendOpts = {}) => {
const outbound = await loadChannelOutboundAdapter(params.channelId);
if (!outbound?.sendText) {
throw new Error(params.unavailableMessage);
}
return await outbound.sendText({
cfg: opts.cfg ?? loadConfig(),
to,
text,
mediaUrl: opts.mediaUrl,
mediaLocalRoots: opts.mediaLocalRoots,
accountId: opts.accountId,
threadId: opts.messageThreadId,
replyToId:
opts.replyToMessageId == null
? undefined
: String(opts.replyToMessageId).trim() || undefined,
silent: opts.silent,
forceDocument: opts.forceDocument,
gifPlayback: opts.gifPlayback,
gatewayClientScopes: opts.gatewayClientScopes,
});
},
};
}