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.
Example
Section titled “Example”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();Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new KMsgBuilder():
KMsgBuilder
Returns
Section titled “Returns”KMsgBuilder
Methods
Section titled “Methods”addProvider()
Section titled “addProvider()”addProvider(
provider):this
Defined in: packages/messaging/src/k-msg.ts:1430
Adds a single provider to the builder.
Parameters
Section titled “Parameters”provider
Section titled “provider”The provider instance to add
Returns
Section titled “Returns”this
this builder for method chaining
Example
Section titled “Example”builder.addProvider(new SolapiProvider({ apiKey: '...', apiSecret: '...' }))addProviders()
Section titled “addProviders()”addProviders(…
providers):this
Defined in: packages/messaging/src/k-msg.ts:1449
Adds multiple providers to the builder.
Parameters
Section titled “Parameters”providers
Section titled “providers”…Provider[]
The provider instances to add
Returns
Section titled “Returns”this
this builder for method chaining
Example
Section titled “Example”builder.addProviders( new SolapiProvider({ apiKey: '...', apiSecret: '...' }), new IWINVProvider({ apiKey: '...' }))build()
Section titled “build()”build():
KMsg
Defined in: packages/messaging/src/k-msg.ts:1536
Builds and returns a new KMsg instance with the configured settings.
Returns
Section titled “Returns”A new KMsg instance
Throws
Section titled “Throws”Error if no providers have been added
Example
Section titled “Example”const kmsg = KMsg.builder() .addProvider(new SolapiProvider({ apiKey: '...' })) .build();withDefaults()
Section titled “withDefaults()”withDefaults(
defaults):this
Defined in: packages/messaging/src/k-msg.ts:1488
Sets the defaults configuration.
Parameters
Section titled “Parameters”defaults
Section titled “defaults”KMsgDefaultsConfig
Default values applied to outgoing messages
Returns
Section titled “Returns”this
this builder for method chaining
Example
Section titled “Example”builder.withDefaults({ sms: { autoLmsBytes: 90 }, kakao: { profileId: 'my-profile' }})withHooks()
Section titled “withHooks()”withHooks(
hooks):this
Defined in: packages/messaging/src/k-msg.ts:1507
Sets the lifecycle hooks.
Parameters
Section titled “Parameters”Hook functions for send lifecycle events
Returns
Section titled “Returns”this
this builder for method chaining
Example
Section titled “Example”builder.withHooks({ onSuccess: (ctx, result) => console.log('Sent:', result.messageId), onError: (ctx, error) => console.error('Failed:', error.message)})withPersistence()
Section titled “withPersistence()”withPersistence(
persistence):this
Defined in: packages/messaging/src/k-msg.ts:1518
Sets the persistence configuration.
Parameters
Section titled “Parameters”persistence
Section titled “persistence”Persistence strategy and repository
{ repo: MessageRepository; strategy: PersistenceStrategy; } | undefined
Returns
Section titled “Returns”this
this builder for method chaining
withRouting()
Section titled “withRouting()”withRouting(
routing):this
Defined in: packages/messaging/src/k-msg.ts:1469
Sets the routing configuration.
Parameters
Section titled “Parameters”routing
Section titled “routing”KMsgRoutingConfig
Routing configuration for provider selection
Returns
Section titled “Returns”this
this builder for method chaining
Example
Section titled “Example”builder.withRouting({ defaultProviderId: 'solapi', byType: { ALIMTALK: 'iwinv' }, strategy: 'round_robin'})