@k-msg/messaging 0.4.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 +72 -46
- package/dist/delivery/tracker.d.ts +2 -2
- package/dist/index.js +28 -28
- package/dist/index.js.map +11 -13
- package/dist/index.mjs +28 -28
- package/dist/index.mjs.map +11 -13
- package/dist/k-msg.d.ts +59 -4
- package/dist/queue/retry.handler.d.ts +1 -1
- package/dist/types/message.types.d.ts +5 -5
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,67 +1,93 @@
|
|
|
1
1
|
# @k-msg/messaging
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
##
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
//
|
|
31
|
-
|
|
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
|
-
//
|
|
34
|
-
await
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
##
|
|
47
|
-
|
|
48
|
-
```
|
|
49
|
-
import {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
57
|
-
console.log('Message delivered:', event);
|
|
58
|
-
});
|
|
80
|
+
## Bulk Sending
|
|
59
81
|
|
|
60
|
-
|
|
61
|
-
console.log('Message failed:', event);
|
|
62
|
-
});
|
|
63
|
-
```
|
|
82
|
+
Use `sendMany()` for controlled concurrency.
|
|
64
83
|
|
|
65
|
-
|
|
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
|
-
|
|
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,
|
|
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;
|