feat(v2): support async channel adapter factories
Channel adapter factories can now return a Promise, enabling adapters that need async initialization like loading auth state from disk (e.g. WhatsApp reading credentials via useMultiFileAuthState). Existing sync factories are unaffected — await on a sync return is a no-op. All current adapters remain synchronous. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -97,7 +97,7 @@ export interface ChannelAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Factory function that creates a channel adapter (returns null if credentials missing). */
|
/** Factory function that creates a channel adapter (returns null if credentials missing). */
|
||||||
export type ChannelAdapterFactory = () => ChannelAdapter | null;
|
export type ChannelAdapterFactory = () => ChannelAdapter | Promise<ChannelAdapter> | null;
|
||||||
|
|
||||||
/** Registration entry for a channel adapter. */
|
/** Registration entry for a channel adapter. */
|
||||||
export interface ChannelRegistration {
|
export interface ChannelRegistration {
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ export function getChannelContainerConfig(name: string): ChannelRegistration['co
|
|||||||
export async function initChannelAdapters(setupFn: (adapter: ChannelAdapter) => ChannelSetup): Promise<void> {
|
export async function initChannelAdapters(setupFn: (adapter: ChannelAdapter) => ChannelSetup): Promise<void> {
|
||||||
for (const [name, registration] of registry) {
|
for (const [name, registration] of registry) {
|
||||||
try {
|
try {
|
||||||
const adapter = registration.factory();
|
const adapter = await registration.factory();
|
||||||
if (!adapter) {
|
if (!adapter) {
|
||||||
log.warn('Channel credentials missing, skipping', { channel: name });
|
log.warn('Channel credentials missing, skipping', { channel: name });
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user