@k-msg/messaging 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,67 +1,93 @@
1
1
  # @k-msg/messaging
2
2
 
3
- Messaging and delivery tracking system for the K-Message platform.
3
+ High-level messaging facade for `k-msg`.
4
+
5
+ This package provides `KMsg`, which normalizes user input, routes to a provider, and returns a `Result`.
4
6
 
5
7
  ## Installation
6
8
 
7
9
  ```bash
8
10
  npm install @k-msg/messaging @k-msg/core
9
- # or
11
+ # or
10
12
  bun add @k-msg/messaging @k-msg/core
11
13
  ```
12
14
 
13
- ## Features
14
-
15
- - **DeliveryTracker**: Message delivery status tracking
16
- - **Message Events**: Comprehensive event management for sent, delivered, and failed messages
17
- - **Retry Logic**: Automatic retry for failed message deliveries
18
- - **Bulk Processing**: Efficient handling of bulk message operations
19
-
20
- ## Basic Usage
21
-
22
- ```typescript
23
- import { DeliveryTracker, MessageEventType } from '@k-msg/messaging';
24
-
25
- const tracker = new DeliveryTracker({
26
- retryAttempts: 3,
27
- retryDelay: 1000
15
+ ## Quick Start
16
+
17
+ ```ts
18
+ import { KMsg } from "@k-msg/messaging";
19
+ import { SolapiProvider } from "@k-msg/provider";
20
+
21
+ const kmsg = new KMsg({
22
+ providers: [
23
+ new SolapiProvider({
24
+ apiKey: process.env.SOLAPI_API_KEY!,
25
+ apiSecret: process.env.SOLAPI_API_SECRET!,
26
+ defaultFrom: "01000000000",
27
+ }),
28
+ ],
29
+ defaults: {
30
+ from: "01000000000",
31
+ sms: { autoLmsBytes: 90 },
32
+ },
28
33
  });
29
34
 
30
- // Configure webhook URL
31
- tracker.setWebhookUrl('https://your-app.com/webhook');
35
+ // Default SMS (type omitted). If the content is long, it can auto-upgrade to LMS.
36
+ await kmsg.send({ to: "01012345678", text: "hello" });
32
37
 
33
- // Start tracking a message
34
- await tracker.trackMessage({
35
- messageId: 'msg-123',
36
- phone: '01012345678',
37
- provider: 'iwinv',
38
- templateCode: 'TPL001',
39
- variables: { code: '123456' }
38
+ // Explicit typed send
39
+ await kmsg.send({
40
+ type: "ALIMTALK",
41
+ to: "01012345678",
42
+ templateCode: "AUTH_OTP",
43
+ variables: { code: "123456" },
40
44
  });
41
-
42
- // Check message status
43
- const status = await tracker.getMessageStatus('msg-123');
44
45
  ```
45
46
 
46
- ## Event Handling
47
-
48
- ```typescript
49
- import { MessageEvent, MessageEventType } from '@k-msg/messaging';
50
-
51
- // Register event listeners
52
- tracker.on(MessageEventType.MESSAGE_SENT, (event: MessageEvent) => {
53
- console.log('Message sent:', event);
47
+ ## Routing
48
+
49
+ ```ts
50
+ import { KMsg } from "@k-msg/messaging";
51
+ import { IWINVProvider, SolapiProvider } from "@k-msg/provider";
52
+
53
+ const kmsg = new KMsg({
54
+ providers: [
55
+ new IWINVProvider({
56
+ apiKey: process.env.IWINV_API_KEY!,
57
+ baseUrl: "https://alimtalk.bizservice.iwinv.kr",
58
+ smsApiKey: process.env.IWINV_SMS_API_KEY,
59
+ smsAuthKey: process.env.IWINV_SMS_AUTH_KEY,
60
+ }),
61
+ new SolapiProvider({
62
+ apiKey: process.env.SOLAPI_API_KEY!,
63
+ apiSecret: process.env.SOLAPI_API_SECRET!,
64
+ defaultFrom: "01000000000",
65
+ kakaoPfId: process.env.SOLAPI_KAKAO_PF_ID,
66
+ rcsBrandId: process.env.SOLAPI_RCS_BRAND_ID,
67
+ }),
68
+ ],
69
+ routing: {
70
+ defaultProviderId: "solapi",
71
+ byType: {
72
+ ALIMTALK: "iwinv",
73
+ SMS: ["solapi"],
74
+ },
75
+ strategy: "first",
76
+ },
54
77
  });
78
+ ```
55
79
 
56
- tracker.on(MessageEventType.MESSAGE_DELIVERED, (event: MessageEvent) => {
57
- console.log('Message delivered:', event);
58
- });
80
+ ## Bulk Sending
59
81
 
60
- tracker.on(MessageEventType.MESSAGE_FAILED, (event: MessageEvent) => {
61
- console.log('Message failed:', event);
62
- });
63
- ```
82
+ Use `sendMany()` for controlled concurrency.
64
83
 
65
- ## License
84
+ ```ts
85
+ const results = await kmsg.sendMany(
86
+ [
87
+ { to: "01011112222", text: "hello 1" },
88
+ { to: "01033334444", text: "hello 2" },
89
+ ],
90
+ { concurrency: 10 },
91
+ );
92
+ ```
66
93
 
67
- MIT
@@ -26,7 +26,7 @@ export interface DeliveryWebhook {
26
26
  export interface TrackingRecord {
27
27
  messageId: string;
28
28
  phoneNumber: string;
29
- templateId: string;
29
+ templateCode: string;
30
30
  provider: string;
31
31
  currentStatus: MessageStatus;
32
32
  statusHistory: StatusHistoryEntry[];
@@ -81,7 +81,7 @@ export declare class DeliveryTracker extends EventEmitter {
81
81
  /**
82
82
  * Start tracking a message
83
83
  */
84
- trackMessage(messageId: string, phoneNumber: string, templateId: string, provider: string, options?: {
84
+ trackMessage(messageId: string, phoneNumber: string, templateCode: string, provider: string, options?: {
85
85
  webhooks?: DeliveryWebhook[];
86
86
  metadata?: Record<string, any>;
87
87
  initialStatus?: MessageStatus;