콘텐츠로 이동

KMsgBuilder

Defined in: packages/messaging/src/k-msg.ts:1415

Fluent builder for creating KMsg instances.

Provides a chainable API for configuring providers, routing, defaults, and hooks. Call build() to create the final KMsg instance.

const kmsg = KMsg.builder()
.addProvider(new SolapiProvider({ apiKey: '...', apiSecret: '...' }))
.addProvider(new IWINVProvider({ apiKey: '...' }))
.withRouting({ defaultProviderId: 'solapi', byType: { ALIMTALK: 'iwinv' } })
.withDefaults({ sms: { autoLmsBytes: 90 } })
.withHooks({ onSuccess: (ctx, result) => console.log('Sent:', result.messageId) })
.build();

new KMsgBuilder(): KMsgBuilder

KMsgBuilder

addProvider(provider): this

Defined in: packages/messaging/src/k-msg.ts:1430

Adds a single provider to the builder.

Provider

The provider instance to add

this

this builder for method chaining

builder.addProvider(new SolapiProvider({ apiKey: '...', apiSecret: '...' }))

addProviders(…providers): this

Defined in: packages/messaging/src/k-msg.ts:1449

Adds multiple providers to the builder.

Provider[]

The provider instances to add

this

this builder for method chaining

builder.addProviders(
new SolapiProvider({ apiKey: '...', apiSecret: '...' }),
new IWINVProvider({ apiKey: '...' })
)

build(): KMsg

Defined in: packages/messaging/src/k-msg.ts:1536

Builds and returns a new KMsg instance with the configured settings.

KMsg

A new KMsg instance

Error if no providers have been added

const kmsg = KMsg.builder()
.addProvider(new SolapiProvider({ apiKey: '...' }))
.build();

withDefaults(defaults): this

Defined in: packages/messaging/src/k-msg.ts:1488

Sets the defaults configuration.

KMsgDefaultsConfig

Default values applied to outgoing messages

this

this builder for method chaining

builder.withDefaults({
sms: { autoLmsBytes: 90 },
kakao: { profileId: 'my-profile' }
})

withHooks(hooks): this

Defined in: packages/messaging/src/k-msg.ts:1507

Sets the lifecycle hooks.

KMsgHooks

Hook functions for send lifecycle events

this

this builder for method chaining

builder.withHooks({
onSuccess: (ctx, result) => console.log('Sent:', result.messageId),
onError: (ctx, error) => console.error('Failed:', error.message)
})

withPersistence(persistence): this

Defined in: packages/messaging/src/k-msg.ts:1518

Sets the persistence configuration.

Persistence strategy and repository

{ repo: MessageRepository; strategy: PersistenceStrategy; } | undefined

this

this builder for method chaining


withRouting(routing): this

Defined in: packages/messaging/src/k-msg.ts:1469

Sets the routing configuration.

KMsgRoutingConfig

Routing configuration for provider selection

this

this builder for method chaining

builder.withRouting({
defaultProviderId: 'solapi',
byType: { ALIMTALK: 'iwinv' },
strategy: 'round_robin'
})