refactor(channels): route core through registered plugin capabilities

This commit is contained in:
Peter Steinberger
2026-03-30 01:00:20 +01:00
parent 471e059b69
commit 63cbc097b5
38 changed files with 1014 additions and 429 deletions

View File

@@ -1,9 +1,28 @@
import { sendMessageIMessage as sendMessageIMessageImpl } from "../../plugin-sdk/imessage.js";
import { loadChannelOutboundAdapter } from "../../channels/plugins/outbound/load.js";
import { loadConfig } from "../../config/config.js";
type RuntimeSend = {
sendMessage: typeof import("../../plugin-sdk/imessage.js").sendMessageIMessage;
type IMessageRuntimeSendOpts = {
config?: ReturnType<typeof loadConfig>;
mediaUrl?: string;
mediaLocalRoots?: readonly string[];
accountId?: string;
replyToId?: string;
};
export const runtimeSend = {
sendMessage: sendMessageIMessageImpl,
} satisfies RuntimeSend;
sendMessage: async (to: string, text: string, opts: IMessageRuntimeSendOpts = {}) => {
const outbound = await loadChannelOutboundAdapter("imessage");
if (!outbound?.sendText) {
throw new Error("iMessage outbound adapter is unavailable.");
}
return await outbound.sendText({
cfg: opts.config ?? loadConfig(),
to,
text,
mediaUrl: opts.mediaUrl,
mediaLocalRoots: opts.mediaLocalRoots,
accountId: opts.accountId,
replyToId: opts.replyToId,
});
},
};

View File

@@ -1,9 +1,39 @@
import { sendMessageTelegram as sendMessageTelegramImpl } from "../../plugin-sdk/telegram-runtime.js";
import { loadChannelOutboundAdapter } from "../../channels/plugins/outbound/load.js";
import { loadConfig } from "../../config/config.js";
type RuntimeSend = {
sendMessage: typeof import("../../plugin-sdk/telegram-runtime.js").sendMessageTelegram;
type TelegramRuntimeSendOpts = {
cfg?: ReturnType<typeof loadConfig>;
mediaUrl?: string;
mediaLocalRoots?: readonly string[];
accountId?: string;
messageThreadId?: string | number;
replyToMessageId?: string | number;
silent?: boolean;
forceDocument?: boolean;
gatewayClientScopes?: readonly string[];
};
export const runtimeSend = {
sendMessage: sendMessageTelegramImpl,
} satisfies RuntimeSend;
sendMessage: async (to: string, text: string, opts: TelegramRuntimeSendOpts = {}) => {
const outbound = await loadChannelOutboundAdapter("telegram");
if (!outbound?.sendText) {
throw new Error("Telegram outbound adapter is unavailable.");
}
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,
gatewayClientScopes: opts.gatewayClientScopes,
});
},
};