@warriorteam/redai-zalo-sdk 1.20.0 → 1.22.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/CHANGELOG.md +108 -0
- package/README.md +18 -0
- package/dist/services/broadcast.service.d.ts +19 -1
- package/dist/services/broadcast.service.d.ts.map +1 -1
- package/dist/services/broadcast.service.js +150 -0
- package/dist/services/broadcast.service.js.map +1 -1
- package/dist/services/promotion.service.d.ts +30 -3
- package/dist/services/promotion.service.d.ts.map +1 -1
- package/dist/services/promotion.service.js +225 -44
- package/dist/services/promotion.service.js.map +1 -1
- package/dist/types/broadcast.d.ts +87 -0
- package/dist/types/broadcast.d.ts.map +1 -1
- package/dist/types/message.d.ts +42 -22
- package/dist/types/message.d.ts.map +1 -1
- package/docs/API_REFERENCE.md +14 -0
- package/docs/BROADCAST_SERVICE.md +86 -1
- package/docs/PROMOTION_API_V3_MIGRATION.md +229 -0
- package/examples/broadcast-example.ts +59 -2
- package/examples/promotion-examples.ts +250 -0
- package/package.json +10 -3
|
@@ -44,7 +44,37 @@ const result = await zalo.broadcast.sendBroadcastMessage(
|
|
|
44
44
|
console.log("Message ID:", result.data.message_id);
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
-
### 2.
|
|
47
|
+
### 2. Gửi Nhiều Broadcast Messages
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
// Gửi nhiều article attachments tuần tự
|
|
51
|
+
const attachmentIds = [
|
|
52
|
+
"article-id-1",
|
|
53
|
+
"article-id-2",
|
|
54
|
+
"article-id-3"
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
const target = zalo.broadcast.createBroadcastTarget({
|
|
58
|
+
cities: ["Hồ Chí Minh"]
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const result = await zalo.broadcast.sendMultipleBroadcastMessages(
|
|
62
|
+
accessToken,
|
|
63
|
+
{ target },
|
|
64
|
+
attachmentIds,
|
|
65
|
+
{
|
|
66
|
+
mode: 'sequential',
|
|
67
|
+
delay: 2000, // 2 giây giữa các tin
|
|
68
|
+
onProgress: (progress) => {
|
|
69
|
+
console.log(`${progress.completed}/${progress.total} completed`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
console.log(`Sent ${result.successfulMessages}/${result.totalMessages} messages`);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### 3. Tạo Targeting Criteria
|
|
48
78
|
|
|
49
79
|
```typescript
|
|
50
80
|
// Targeting phức tạp
|
|
@@ -184,6 +214,61 @@ const result = await zalo.broadcast.sendBroadcastMessage(
|
|
|
184
214
|
);
|
|
185
215
|
```
|
|
186
216
|
|
|
217
|
+
### 4. Gửi Nhiều Messages Song Song
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
// Gửi nhiều articles cùng lúc (parallel)
|
|
221
|
+
const attachmentIds = [
|
|
222
|
+
"promo-article-1",
|
|
223
|
+
"promo-article-2",
|
|
224
|
+
"promo-article-3"
|
|
225
|
+
];
|
|
226
|
+
|
|
227
|
+
const result = await zalo.broadcast.sendMultipleBroadcastMessages(
|
|
228
|
+
accessToken,
|
|
229
|
+
{ target },
|
|
230
|
+
attachmentIds,
|
|
231
|
+
{
|
|
232
|
+
mode: 'parallel', // Gửi song song
|
|
233
|
+
onProgress: (progress) => {
|
|
234
|
+
console.log(`Progress: ${progress.completed}/${progress.total}`);
|
|
235
|
+
console.log(`Success: ${progress.successful}, Failed: ${progress.failed}`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
console.log("Results:", result.results.map(r => ({
|
|
241
|
+
attachmentId: r.attachmentId,
|
|
242
|
+
success: r.success,
|
|
243
|
+
messageId: r.messageId
|
|
244
|
+
})));
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### 5. Gửi Với Delay Tùy Chỉnh
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
// Gửi tuần tự với delay 5 giây giữa các tin
|
|
251
|
+
const result = await zalo.broadcast.sendMultipleBroadcastMessages(
|
|
252
|
+
accessToken,
|
|
253
|
+
{ target },
|
|
254
|
+
attachmentIds,
|
|
255
|
+
{
|
|
256
|
+
mode: 'sequential',
|
|
257
|
+
delay: 5000, // 5 giây
|
|
258
|
+
onProgress: (progress) => {
|
|
259
|
+
if (progress.isCompleted) {
|
|
260
|
+
console.log("All messages sent!");
|
|
261
|
+
} else {
|
|
262
|
+
console.log(`Sending: ${progress.currentAttachmentId}`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
console.log(`Campaign completed in ${result.totalDuration}ms`);
|
|
269
|
+
console.log(`Success rate: ${(result.successfulMessages / result.totalMessages * 100).toFixed(1)}%`);
|
|
270
|
+
```
|
|
271
|
+
|
|
187
272
|
## Error Handling
|
|
188
273
|
|
|
189
274
|
### Các Lỗi Thường Gặp
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# Zalo Promotion API v3.0 Migration Guide
|
|
2
|
+
|
|
3
|
+
## Tổng quan thay đổi
|
|
4
|
+
|
|
5
|
+
Promotion Service đã được cập nhật để tương thích với **Zalo Official Account API v3.0**. Đây là những thay đổi chính:
|
|
6
|
+
|
|
7
|
+
### 🔄 Thay đổi URL API
|
|
8
|
+
- **Cũ**: `https://openapi.zalo.me/v2.0/oa/message/promotion`
|
|
9
|
+
- **Mới**: `https://openapi.zalo.me/v3.0/oa/message/promotion`
|
|
10
|
+
|
|
11
|
+
### 🏗️ Cấu trúc Message Elements hoàn toàn mới
|
|
12
|
+
|
|
13
|
+
#### Cũ (v2.0):
|
|
14
|
+
```typescript
|
|
15
|
+
elements: [{
|
|
16
|
+
title: string;
|
|
17
|
+
subtitle?: string;
|
|
18
|
+
image_url?: string;
|
|
19
|
+
buttons?: Array<{...}>;
|
|
20
|
+
}]
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
#### Mới (v3.0):
|
|
24
|
+
```typescript
|
|
25
|
+
elements: [
|
|
26
|
+
{
|
|
27
|
+
type: "banner",
|
|
28
|
+
attachment_id: "...", // hoặc image_url
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
type: "header",
|
|
32
|
+
content: "💥💥Ưu đãi thành viên Platinum💥💥"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
type: "text",
|
|
36
|
+
align: "left",
|
|
37
|
+
content: "Nội dung chi tiết..."
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
type: "table",
|
|
41
|
+
content: [
|
|
42
|
+
{ key: "Voucher", value: "VC09279222" },
|
|
43
|
+
{ key: "Hạn sử dụng", value: "30/12/2023" }
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 🎯 Các Element Types được hỗ trợ
|
|
50
|
+
|
|
51
|
+
1. **Banner Element**
|
|
52
|
+
```typescript
|
|
53
|
+
{
|
|
54
|
+
type: "banner",
|
|
55
|
+
attachment_id?: string, // ID từ API upload ảnh
|
|
56
|
+
image_url?: string // URL trực tiếp (chỉ dùng 1 trong 2)
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
2. **Header Element**
|
|
61
|
+
```typescript
|
|
62
|
+
{
|
|
63
|
+
type: "header",
|
|
64
|
+
content: string, // Tối đa 100 ký tự
|
|
65
|
+
align?: "left" | "center" | "right" // Mặc định: left
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
3. **Text Element**
|
|
70
|
+
```typescript
|
|
71
|
+
{
|
|
72
|
+
type: "text",
|
|
73
|
+
content: string, // Tối đa 1000 ký tự
|
|
74
|
+
align?: "left" | "center" | "right" // Mặc định: left
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
4. **Table Element**
|
|
79
|
+
```typescript
|
|
80
|
+
{
|
|
81
|
+
type: "table",
|
|
82
|
+
content: Array<{
|
|
83
|
+
key: string, // Tối đa 25 ký tự
|
|
84
|
+
value: string // Tối đa 100 ký tự
|
|
85
|
+
}> // Tối đa 5 phần tử
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 🔘 Cấu trúc Buttons mới
|
|
90
|
+
|
|
91
|
+
#### Cũ (v2.0):
|
|
92
|
+
```typescript
|
|
93
|
+
buttons: [{
|
|
94
|
+
type: string;
|
|
95
|
+
title: string;
|
|
96
|
+
url?: string;
|
|
97
|
+
payload?: string;
|
|
98
|
+
}]
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
#### Mới (v3.0):
|
|
102
|
+
```typescript
|
|
103
|
+
buttons: [{
|
|
104
|
+
title: string, // Tối đa 35 ký tự
|
|
105
|
+
image_icon?: string, // URL hoặc attachment_id hoặc "default"
|
|
106
|
+
type: string, // VD: "oa.open.url", "oa.query.hide"
|
|
107
|
+
payload: object | string // Tùy thuộc vào type
|
|
108
|
+
}]
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**Payload format theo type:**
|
|
112
|
+
- `oa.open.url`: `{ url: "https://..." }`
|
|
113
|
+
- `oa.query.show`: `"#callback_data"` (string)
|
|
114
|
+
- `oa.query.hide`: `"#callback_data"` (string)
|
|
115
|
+
- `oa.open.sms`: `{ content: "text", phone_code: "84xxx" }`
|
|
116
|
+
- `oa.open.phone`: `{ phone_code: "84xxx" }`
|
|
117
|
+
|
|
118
|
+
### 🌐 Hỗ trợ đa ngôn ngữ
|
|
119
|
+
|
|
120
|
+
Thêm thuộc tính `language` trong payload:
|
|
121
|
+
```typescript
|
|
122
|
+
{
|
|
123
|
+
template_type: "promotion",
|
|
124
|
+
language: "VI" | "EN", // Mặc định: VI
|
|
125
|
+
elements: [...],
|
|
126
|
+
buttons: [...]
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## 📝 Cách sử dụng mới
|
|
131
|
+
|
|
132
|
+
### 1. Gửi Promotion theo format chuẩn docs
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
import { PromotionService } from "./services/promotion.service";
|
|
136
|
+
|
|
137
|
+
const promotionService = new PromotionService(zaloClient);
|
|
138
|
+
|
|
139
|
+
// Gửi promotion message theo đúng format docs v3.0
|
|
140
|
+
await promotionService.sendCustomPromotion(
|
|
141
|
+
accessToken,
|
|
142
|
+
{ user_id: "user_id" },
|
|
143
|
+
{
|
|
144
|
+
attachmentId: "your_attachment_id",
|
|
145
|
+
headerContent: "💥💥Ưu đãi thành viên Platinum💥💥",
|
|
146
|
+
textContent: "Ưu đãi dành riêng cho khách hàng...",
|
|
147
|
+
tableData: [
|
|
148
|
+
{ key: "Voucher", value: "VC09279222" },
|
|
149
|
+
{ key: "Hạn sử dụng", value: "30/12/2023" }
|
|
150
|
+
],
|
|
151
|
+
footerText: "Áp dụng tất cả cửa hàng trên toàn quốc",
|
|
152
|
+
buttons: [
|
|
153
|
+
{
|
|
154
|
+
title: "Tham khảo chương trình",
|
|
155
|
+
type: "oa.open.url",
|
|
156
|
+
payload: { url: "https://oa.zalo.me/home" }
|
|
157
|
+
}
|
|
158
|
+
],
|
|
159
|
+
language: "VI"
|
|
160
|
+
}
|
|
161
|
+
);
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### 2. Gửi Product Promotion (đã cập nhật)
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
await promotionService.sendProductPromotion(
|
|
168
|
+
accessToken,
|
|
169
|
+
{ user_id: "user_id" },
|
|
170
|
+
{
|
|
171
|
+
title: "iPhone 15 Pro Max",
|
|
172
|
+
description: "Siêu phẩm công nghệ mới nhất...",
|
|
173
|
+
attachmentId: "product_image_id", // Thay vì imageUrl
|
|
174
|
+
originalPrice: 34990000,
|
|
175
|
+
discountPrice: 29990000,
|
|
176
|
+
discountPercent: 14,
|
|
177
|
+
validUntil: "31/12/2024",
|
|
178
|
+
productUrl: "https://example.com/product"
|
|
179
|
+
}
|
|
180
|
+
);
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### 3. Gửi Event Notification (đã cập nhật)
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
await promotionService.sendEventNotification(
|
|
187
|
+
accessToken,
|
|
188
|
+
{ user_id: "user_id" },
|
|
189
|
+
{
|
|
190
|
+
title: "Hội thảo Digital Marketing 2024",
|
|
191
|
+
description: "Khám phá xu hướng marketing...",
|
|
192
|
+
attachmentId: "event_image_id",
|
|
193
|
+
eventDate: "15/01/2024 - 9:00 AM",
|
|
194
|
+
location: "Trung tâm Hội nghị Quốc gia, Hà Nội",
|
|
195
|
+
registrationUrl: "https://example.com/register"
|
|
196
|
+
}
|
|
197
|
+
);
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## ⚠️ Breaking Changes
|
|
201
|
+
|
|
202
|
+
1. **URL API**: Phải cập nhật từ v2.0 lên v3.0
|
|
203
|
+
2. **Elements Structure**: Hoàn toàn khác, không tương thích ngược
|
|
204
|
+
3. **Buttons Payload**: Từ `string` thành `object`
|
|
205
|
+
4. **Image Handling**: Ưu tiên `attachment_id` thay vì `image_url`
|
|
206
|
+
5. **Validation**: Thêm validation cho elements và buttons
|
|
207
|
+
|
|
208
|
+
## 🔍 Validation Rules
|
|
209
|
+
|
|
210
|
+
- **Header content**: Tối đa 100 ký tự
|
|
211
|
+
- **Text content**: Tối đa 1000 ký tự mỗi đoạn, tối đa 2 đoạn text
|
|
212
|
+
- **Table**: Tối đa 5 phần tử, key ≤ 25 ký tự, value ≤ 100 ký tự
|
|
213
|
+
- **Button title**: Tối đa 35 ký tự, tối đa 4 buttons
|
|
214
|
+
- **Sending time**: Chỉ từ 8:00 - 22:00 hàng ngày
|
|
215
|
+
|
|
216
|
+
## 📚 Examples
|
|
217
|
+
|
|
218
|
+
Xem file `examples/promotion-examples.ts` để có ví dụ chi tiết về cách sử dụng tất cả các tính năng mới.
|
|
219
|
+
|
|
220
|
+
## 🚀 Migration Checklist
|
|
221
|
+
|
|
222
|
+
- [ ] Cập nhật URL API từ v2.0 lên v3.0
|
|
223
|
+
- [ ] Thay đổi cấu trúc elements theo format mới
|
|
224
|
+
- [ ] Cập nhật cấu trúc buttons với payload object
|
|
225
|
+
- [ ] Thêm support cho attachment_id
|
|
226
|
+
- [ ] Thêm language parameter
|
|
227
|
+
- [ ] Test với các element types khác nhau
|
|
228
|
+
- [ ] Kiểm tra validation rules mới
|
|
229
|
+
- [ ] Cập nhật documentation và examples
|
|
@@ -101,8 +101,65 @@ async function broadcastExample() {
|
|
|
101
101
|
message: complexResult.message
|
|
102
102
|
});
|
|
103
103
|
|
|
104
|
-
// Example 5:
|
|
105
|
-
console.log("\n5.
|
|
104
|
+
// Example 5: Gửi nhiều broadcast messages cùng lúc
|
|
105
|
+
console.log("\n5. Multiple broadcast messages (Sequential):");
|
|
106
|
+
const multipleAttachmentIds = [
|
|
107
|
+
"bd5ea46bb32e5a0033f",
|
|
108
|
+
"cd6fb57cc43f6b1144g",
|
|
109
|
+
"de7gc68dd54g7c2255h"
|
|
110
|
+
];
|
|
111
|
+
|
|
112
|
+
const multipleTarget = zalo.broadcast.createBroadcastTarget({
|
|
113
|
+
cities: ["Hà Nội"],
|
|
114
|
+
gender: "ALL"
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const multipleResult = await zalo.broadcast.sendMultipleBroadcastMessages(
|
|
118
|
+
accessToken,
|
|
119
|
+
{ target: multipleTarget },
|
|
120
|
+
multipleAttachmentIds,
|
|
121
|
+
{
|
|
122
|
+
mode: 'sequential',
|
|
123
|
+
delay: 2000, // 2 seconds delay between messages
|
|
124
|
+
onProgress: (progress) => {
|
|
125
|
+
console.log(`Progress: ${progress.completed}/${progress.total} - Current: ${progress.currentAttachmentId}`);
|
|
126
|
+
console.log(`Success: ${progress.successful}, Failed: ${progress.failed}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
console.log("Multiple broadcast result:", {
|
|
132
|
+
totalMessages: multipleResult.totalMessages,
|
|
133
|
+
successful: multipleResult.successfulMessages,
|
|
134
|
+
failed: multipleResult.failedMessages,
|
|
135
|
+
duration: `${multipleResult.totalDuration}ms`,
|
|
136
|
+
mode: multipleResult.mode
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// Example 6: Gửi nhiều broadcast messages song song
|
|
140
|
+
console.log("\n6. Multiple broadcast messages (Parallel):");
|
|
141
|
+
const parallelResult = await zalo.broadcast.sendMultipleBroadcastMessages(
|
|
142
|
+
accessToken,
|
|
143
|
+
{ target: multipleTarget },
|
|
144
|
+
multipleAttachmentIds,
|
|
145
|
+
{
|
|
146
|
+
mode: 'parallel',
|
|
147
|
+
onProgress: (progress) => {
|
|
148
|
+
console.log(`Parallel progress: ${progress.completed}/${progress.total}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
console.log("Parallel broadcast result:", {
|
|
154
|
+
totalMessages: parallelResult.totalMessages,
|
|
155
|
+
successful: parallelResult.successfulMessages,
|
|
156
|
+
failed: parallelResult.failedMessages,
|
|
157
|
+
duration: `${parallelResult.totalDuration}ms`,
|
|
158
|
+
mode: parallelResult.mode
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// Example 7: Hiển thị các mã targeting có sẵn
|
|
162
|
+
console.log("\n7. Available targeting codes:");
|
|
106
163
|
console.log("City codes:", Object.keys(zalo.broadcast.getCityCodes()).slice(0, 10), "...");
|
|
107
164
|
console.log("Age group codes:", zalo.broadcast.getAgeGroupCodes());
|
|
108
165
|
console.log("Gender codes:", zalo.broadcast.getGenderCodes());
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { PromotionService } from "../src/services/promotion.service";
|
|
2
|
+
import { ZaloClient } from "../src/clients/zalo-client";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Examples sử dụng Promotion Service với API v3.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// Khởi tạo service
|
|
9
|
+
const client = new ZaloClient();
|
|
10
|
+
const promotionService = new PromotionService(client);
|
|
11
|
+
|
|
12
|
+
const ACCESS_TOKEN = "your_access_token_here";
|
|
13
|
+
const USER_ID = "4356639876691778517";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Example 1: Gửi promotion message theo format chuẩn docs v3.0
|
|
17
|
+
*/
|
|
18
|
+
export async function sendStandardPromotion() {
|
|
19
|
+
try {
|
|
20
|
+
const result = await promotionService.sendCustomPromotion(
|
|
21
|
+
ACCESS_TOKEN,
|
|
22
|
+
{ user_id: USER_ID },
|
|
23
|
+
{
|
|
24
|
+
attachmentId: "aERC3A0iYGgQxim8fYIK6fxzsXkaFfq7ZFRB3RCyZH6RyziRis3RNydebK3iSPCJX_cJ3k1nW1EQufjN_pUL1f6Ypq3rTef5nxp6H_HnXKFDiyD5y762HS-baqRpQe5FdA376lTfq1sRyPr8ypd74ecbaLyA-tGmuJ-97W",
|
|
25
|
+
headerContent: "💥💥Ưu đãi thành viên Platinum💥💥",
|
|
26
|
+
textContent: "Ưu đãi dành riêng cho khách hàng Nguyen Van A hạng thẻ Platinum<br>Voucher trị giá 150$",
|
|
27
|
+
tableData: [
|
|
28
|
+
{
|
|
29
|
+
key: "Voucher",
|
|
30
|
+
value: "VC09279222"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
key: "Hạn sử dụng",
|
|
34
|
+
value: "30/12/2023"
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
footerText: "Áp dụng tất cả cửa hàng trên toàn quốc",
|
|
38
|
+
buttons: [
|
|
39
|
+
{
|
|
40
|
+
title: "Tham khảo chương trình",
|
|
41
|
+
imageIcon: "",
|
|
42
|
+
type: "oa.open.url",
|
|
43
|
+
payload: {
|
|
44
|
+
url: "https://oa.zalo.me/home"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
title: "Liên hệ chăm sóc viên",
|
|
49
|
+
imageIcon: "aeqg9SYn3nIUYYeWohGI1fYRF3V9f0GHceig8Ckq4WQVcpmWb-9SL8JLPt-6gX0QbTCfSuQv40UEst1imAm53CwFPsQ1jq9MsOnlQe6rIrZOYcrlWBTAKy_UQsV9vnfGozCuOvFfIbN5rcXddFKM4sSYVM0D50I9eWy3",
|
|
50
|
+
type: "oa.query.hide",
|
|
51
|
+
payload: "#tuvan" // String trực tiếp theo docs
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
language: "VI"
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
console.log("Promotion sent successfully:", result);
|
|
59
|
+
return result;
|
|
60
|
+
} catch (error) {
|
|
61
|
+
console.error("Failed to send promotion:", error);
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Example 2: Gửi product promotion
|
|
68
|
+
*/
|
|
69
|
+
export async function sendProductPromotion() {
|
|
70
|
+
try {
|
|
71
|
+
const result = await promotionService.sendProductPromotion(
|
|
72
|
+
ACCESS_TOKEN,
|
|
73
|
+
{ user_id: USER_ID },
|
|
74
|
+
{
|
|
75
|
+
title: "iPhone 15 Pro Max",
|
|
76
|
+
description: "Siêu phẩm công nghệ mới nhất từ Apple với chip A17 Pro mạnh mẽ",
|
|
77
|
+
attachmentId: "your_product_image_attachment_id",
|
|
78
|
+
originalPrice: 34990000,
|
|
79
|
+
discountPrice: 29990000,
|
|
80
|
+
discountPercent: 14,
|
|
81
|
+
validUntil: "31/12/2024",
|
|
82
|
+
productUrl: "https://example.com/iphone-15-pro-max"
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
console.log("Product promotion sent successfully:", result);
|
|
87
|
+
return result;
|
|
88
|
+
} catch (error) {
|
|
89
|
+
console.error("Failed to send product promotion:", error);
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Example 3: Gửi event notification
|
|
96
|
+
*/
|
|
97
|
+
export async function sendEventNotification() {
|
|
98
|
+
try {
|
|
99
|
+
const result = await promotionService.sendEventNotification(
|
|
100
|
+
ACCESS_TOKEN,
|
|
101
|
+
{ user_id: USER_ID },
|
|
102
|
+
{
|
|
103
|
+
title: "Hội thảo Digital Marketing 2024",
|
|
104
|
+
description: "Khám phá xu hướng marketing số mới nhất và chiến lược tăng trưởng bền vững",
|
|
105
|
+
attachmentId: "your_event_image_attachment_id",
|
|
106
|
+
eventDate: "15/01/2024 - 9:00 AM",
|
|
107
|
+
location: "Trung tâm Hội nghị Quốc gia, Hà Nội",
|
|
108
|
+
registrationUrl: "https://example.com/register-event"
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
console.log("Event notification sent successfully:", result);
|
|
113
|
+
return result;
|
|
114
|
+
} catch (error) {
|
|
115
|
+
console.error("Failed to send event notification:", error);
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Example 4: Gửi newsletter
|
|
122
|
+
*/
|
|
123
|
+
export async function sendNewsletter() {
|
|
124
|
+
try {
|
|
125
|
+
const result = await promotionService.sendNewsletter(
|
|
126
|
+
ACCESS_TOKEN,
|
|
127
|
+
{ user_id: USER_ID },
|
|
128
|
+
{
|
|
129
|
+
title: "Bản tin công nghệ tuần 52/2024",
|
|
130
|
+
summary: "Cập nhật những tin tức công nghệ hot nhất trong tuần qua",
|
|
131
|
+
attachmentId: "your_newsletter_image_attachment_id",
|
|
132
|
+
articles: [
|
|
133
|
+
{
|
|
134
|
+
title: "AI và tương lai của lập trình",
|
|
135
|
+
url: "https://example.com/ai-programming-future"
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
title: "Blockchain trong fintech",
|
|
139
|
+
url: "https://example.com/blockchain-fintech"
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
title: "IoT và smart city",
|
|
143
|
+
url: "https://example.com/iot-smart-city"
|
|
144
|
+
}
|
|
145
|
+
],
|
|
146
|
+
unsubscribeUrl: "https://example.com/unsubscribe"
|
|
147
|
+
}
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
console.log("Newsletter sent successfully:", result);
|
|
151
|
+
return result;
|
|
152
|
+
} catch (error) {
|
|
153
|
+
console.error("Failed to send newsletter:", error);
|
|
154
|
+
throw error;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Example 5: Demo tất cả button types
|
|
160
|
+
*/
|
|
161
|
+
export async function sendAllButtonTypes() {
|
|
162
|
+
try {
|
|
163
|
+
const result = await promotionService.sendCustomPromotion(
|
|
164
|
+
ACCESS_TOKEN,
|
|
165
|
+
{ user_id: USER_ID },
|
|
166
|
+
{
|
|
167
|
+
attachmentId: "your_attachment_id",
|
|
168
|
+
headerContent: "🔘 Demo tất cả button types",
|
|
169
|
+
textContent: "Thử nghiệm các loại button được hỗ trợ trong Zalo API v3.0",
|
|
170
|
+
tableData: [
|
|
171
|
+
{ key: "Button types", value: "5 loại" },
|
|
172
|
+
{ key: "Tính năng", value: "Chỉ trên Mobile" }
|
|
173
|
+
],
|
|
174
|
+
buttons: [
|
|
175
|
+
{
|
|
176
|
+
title: "Mở URL",
|
|
177
|
+
type: "oa.open.url",
|
|
178
|
+
payload: { url: "https://developers.zalo.me/" }
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
title: "Query Show",
|
|
182
|
+
type: "oa.query.show",
|
|
183
|
+
payload: "#callback_show"
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
title: "Query Hide",
|
|
187
|
+
type: "oa.query.hide",
|
|
188
|
+
payload: "#callback_hide"
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
title: "Gửi SMS",
|
|
192
|
+
type: "oa.open.sms",
|
|
193
|
+
payload: {
|
|
194
|
+
content: "Xin chào từ Zalo OA",
|
|
195
|
+
phone_code: "84919018791"
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
title: "Gọi điện",
|
|
200
|
+
type: "oa.open.phone",
|
|
201
|
+
payload: { phone_code: "84919018791" }
|
|
202
|
+
}
|
|
203
|
+
],
|
|
204
|
+
language: "VI"
|
|
205
|
+
}
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
console.log("All button types demo sent successfully:", result);
|
|
209
|
+
return result;
|
|
210
|
+
} catch (error) {
|
|
211
|
+
console.error("Failed to send all button types demo:", error);
|
|
212
|
+
throw error;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Chạy tất cả examples
|
|
218
|
+
*/
|
|
219
|
+
export async function runAllExamples() {
|
|
220
|
+
console.log("=== Zalo Promotion API v3.0 Examples ===\n");
|
|
221
|
+
|
|
222
|
+
try {
|
|
223
|
+
console.log("1. Sending standard promotion...");
|
|
224
|
+
await sendStandardPromotion();
|
|
225
|
+
console.log("✅ Standard promotion sent\n");
|
|
226
|
+
|
|
227
|
+
console.log("2. Sending product promotion...");
|
|
228
|
+
await sendProductPromotion();
|
|
229
|
+
console.log("✅ Product promotion sent\n");
|
|
230
|
+
|
|
231
|
+
console.log("3. Sending event notification...");
|
|
232
|
+
await sendEventNotification();
|
|
233
|
+
console.log("✅ Event notification sent\n");
|
|
234
|
+
|
|
235
|
+
console.log("4. Sending newsletter...");
|
|
236
|
+
await sendNewsletter();
|
|
237
|
+
console.log("✅ Newsletter sent\n");
|
|
238
|
+
|
|
239
|
+
console.log("5. Sending all button types demo...");
|
|
240
|
+
await sendAllButtonTypes();
|
|
241
|
+
console.log("✅ All button types demo sent\n");
|
|
242
|
+
|
|
243
|
+
console.log("🎉 All examples completed successfully!");
|
|
244
|
+
} catch (error) {
|
|
245
|
+
console.error("❌ Error running examples:", error);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Uncomment để chạy examples
|
|
250
|
+
// runAllExamples();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@warriorteam/redai-zalo-sdk",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Comprehensive TypeScript/JavaScript SDK for Zalo APIs - Official Account, ZNS, Consultation Service, Broadcast Service, Group Messaging with List APIs, Social APIs, Enhanced Article Management, and Message Sequence APIs with Real-time Tracking",
|
|
3
|
+
"version": "1.22.0",
|
|
4
|
+
"description": "Comprehensive TypeScript/JavaScript SDK for Zalo APIs - Official Account v3.0, ZNS, Consultation Service, Broadcast Service, Group Messaging with List APIs, Social APIs, Enhanced Article Management, Promotion Service v3.0, and Message Sequence APIs with Real-time Tracking",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
@@ -48,7 +48,14 @@
|
|
|
48
48
|
"bulk-group-messaging",
|
|
49
49
|
"group-notifications",
|
|
50
50
|
"team-communication",
|
|
51
|
-
"group-automation"
|
|
51
|
+
"group-automation",
|
|
52
|
+
"promotion-service",
|
|
53
|
+
"promotion-v3",
|
|
54
|
+
"zalo-v3",
|
|
55
|
+
"banner-element",
|
|
56
|
+
"table-element",
|
|
57
|
+
"multi-language",
|
|
58
|
+
"button-actions"
|
|
52
59
|
],
|
|
53
60
|
"author": "RedAI Team",
|
|
54
61
|
"license": "MIT",
|