@warriorteam/redai-zalo-sdk 1.21.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 +52 -0
- 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/message.d.ts +42 -22
- package/dist/types/message.d.ts.map +1 -1
- package/docs/PROMOTION_API_V3_MIGRATION.md +229 -0
- package/examples/promotion-examples.ts +250 -0
- package/package.json +10 -3
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,58 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.22.0] - 2025-08-29
|
|
9
|
+
|
|
10
|
+
### 🚀 MAJOR UPDATE - Promotion Service v3.0
|
|
11
|
+
|
|
12
|
+
#### ⬆️ API Version Upgrade
|
|
13
|
+
- **UPGRADED**: Promotion Service từ v2.0 lên **v3.0** API
|
|
14
|
+
- **URL**: Cập nhật endpoint từ `/v2.0/oa/message/promotion` lên `/v3.0/oa/message/promotion`
|
|
15
|
+
- **BREAKING**: Cấu trúc message elements hoàn toàn mới, không tương thích ngược
|
|
16
|
+
|
|
17
|
+
#### 🏗️ New Message Elements Structure
|
|
18
|
+
- **BANNER**: Element với `attachment_id` hoặc `image_url`, type="banner"
|
|
19
|
+
- **HEADER**: Element với `content` và `align`, type="header" (tối đa 100 ký tự)
|
|
20
|
+
- **TEXT**: Element với `content` và `align`, type="text" (tối đa 1000 ký tự, tối đa 2 đoạn)
|
|
21
|
+
- **TABLE**: Element với `content` array, type="table" (tối đa 5 items, key ≤ 25 chars, value ≤ 100 chars)
|
|
22
|
+
|
|
23
|
+
#### 🔘 Enhanced Button System
|
|
24
|
+
- **PAYLOAD**: Hỗ trợ cả object và string tùy theo button type
|
|
25
|
+
- **TYPES**: `oa.open.url`, `oa.query.show`, `oa.query.hide`, `oa.open.sms`, `oa.open.phone`
|
|
26
|
+
- **VALIDATION**: Title tối đa 35 ký tự, tối đa 4 buttons
|
|
27
|
+
- **ICONS**: Hỗ trợ `image_icon` với URL/attachment_id/"default"
|
|
28
|
+
|
|
29
|
+
#### 🌐 Multi-language Support
|
|
30
|
+
- **LANGUAGE**: Thêm thuộc tính `language: "VI" | "EN"`
|
|
31
|
+
- **LOCALIZATION**: Nội dung mặc định tự động chuyển ngôn ngữ
|
|
32
|
+
|
|
33
|
+
#### 🆕 New Methods & Features
|
|
34
|
+
- **ADDED**: `sendCustomPromotion()` - Gửi promotion theo format chuẩn docs v3.0
|
|
35
|
+
- **ENHANCED**: `sendProductPromotion()` - Cập nhật với elements structure mới
|
|
36
|
+
- **ENHANCED**: `sendEventNotification()` - Cập nhật với table và text elements
|
|
37
|
+
- **ENHANCED**: `sendNewsletter()` - Cập nhật với banner và table elements
|
|
38
|
+
- **VALIDATION**: Nâng cao validation cho elements và buttons
|
|
39
|
+
|
|
40
|
+
#### 📚 Comprehensive Documentation & Examples
|
|
41
|
+
- **ADDED**: `docs/PROMOTION_API_V3_MIGRATION.md` - Hướng dẫn migration chi tiết
|
|
42
|
+
- **ADDED**: `examples/promotion-examples.ts` - Examples đầy đủ cho tất cả tính năng
|
|
43
|
+
- **EXAMPLES**: Demo 5 button types với payload format đúng
|
|
44
|
+
- **MIGRATION**: Breaking changes và checklist migration
|
|
45
|
+
|
|
46
|
+
#### 🛡️ Enhanced Validation & Error Handling
|
|
47
|
+
- **TIME**: Kiểm tra sending time (8:00-22:00)
|
|
48
|
+
- **ELEMENTS**: Validate structure và content length
|
|
49
|
+
- **BUTTONS**: Validate payload format theo từng type
|
|
50
|
+
- **ERRORS**: Error codes cụ thể cho từng violation
|
|
51
|
+
|
|
52
|
+
### 🔧 BREAKING CHANGES
|
|
53
|
+
- **Elements Structure**: Hoàn toàn khác v2.0, cần migration
|
|
54
|
+
- **Button Payload**: Từ string thành object/string tùy type
|
|
55
|
+
- **Image Handling**: Ưu tiên `attachment_id` thay vì `image_url`
|
|
56
|
+
- **API URL**: Phải cập nhật từ v2.0 lên v3.0
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
8
60
|
## [1.21.0] - 2025-08-29
|
|
9
61
|
|
|
10
62
|
### 🚀 NEW FEATURES
|
|
@@ -62,7 +62,8 @@ export declare class PromotionService {
|
|
|
62
62
|
sendProductPromotion(accessToken: string, recipient: MessageRecipient, promotionInfo: {
|
|
63
63
|
title: string;
|
|
64
64
|
description: string;
|
|
65
|
-
imageUrl
|
|
65
|
+
imageUrl?: string;
|
|
66
|
+
attachmentId?: string;
|
|
66
67
|
originalPrice: number;
|
|
67
68
|
discountPrice: number;
|
|
68
69
|
discountPercent: number;
|
|
@@ -79,7 +80,8 @@ export declare class PromotionService {
|
|
|
79
80
|
sendEventNotification(accessToken: string, recipient: MessageRecipient, eventInfo: {
|
|
80
81
|
title: string;
|
|
81
82
|
description: string;
|
|
82
|
-
imageUrl
|
|
83
|
+
imageUrl?: string;
|
|
84
|
+
attachmentId?: string;
|
|
83
85
|
eventDate: string;
|
|
84
86
|
location: string;
|
|
85
87
|
registrationUrl: string;
|
|
@@ -94,13 +96,38 @@ export declare class PromotionService {
|
|
|
94
96
|
sendNewsletter(accessToken: string, recipient: MessageRecipient, newsletterInfo: {
|
|
95
97
|
title: string;
|
|
96
98
|
summary: string;
|
|
97
|
-
imageUrl
|
|
99
|
+
imageUrl?: string;
|
|
100
|
+
attachmentId?: string;
|
|
98
101
|
articles: Array<{
|
|
99
102
|
title: string;
|
|
100
103
|
url: string;
|
|
101
104
|
}>;
|
|
102
105
|
unsubscribeUrl: string;
|
|
103
106
|
}): Promise<SendMessageResponse>;
|
|
107
|
+
/**
|
|
108
|
+
* Tạo promotion message theo format chuẩn v3.0 (như trong docs)
|
|
109
|
+
* @param accessToken Access token của Official Account
|
|
110
|
+
* @param recipient Thông tin người nhận
|
|
111
|
+
* @param promotionData Dữ liệu promotion
|
|
112
|
+
* @returns Thông tin tin nhắn đã gửi
|
|
113
|
+
*/
|
|
114
|
+
sendCustomPromotion(accessToken: string, recipient: MessageRecipient, promotionData: {
|
|
115
|
+
attachmentId: string;
|
|
116
|
+
headerContent: string;
|
|
117
|
+
textContent: string;
|
|
118
|
+
tableData: Array<{
|
|
119
|
+
key: string;
|
|
120
|
+
value: string;
|
|
121
|
+
}>;
|
|
122
|
+
footerText?: string;
|
|
123
|
+
buttons: Array<{
|
|
124
|
+
title: string;
|
|
125
|
+
imageIcon?: string;
|
|
126
|
+
type: string;
|
|
127
|
+
payload: Record<string, any> | string;
|
|
128
|
+
}>;
|
|
129
|
+
language?: "VI" | "EN";
|
|
130
|
+
}): Promise<SendMessageResponse>;
|
|
104
131
|
/**
|
|
105
132
|
* Validate promotion message format
|
|
106
133
|
* @param message Promotion message to validate
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promotion.service.d.ts","sourceRoot":"","sources":["../../src/services/promotion.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,kBAAkB,CAAC;AAG1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,qBAAa,gBAAgB;IAIf,OAAO,CAAC,QAAQ,CAAC,MAAM;IAHnC,OAAO,CAAC,QAAQ,CAAC,eAAe,CACsB;gBAEzB,MAAM,EAAE,UAAU;IAE/C;;;;;;OAMG;IACU,oBAAoB,CAC/B,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,gBAAgB,EAC3B,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,mBAAmB,CAAC;IAyC/B;;;;;;OAMG;IACU,oBAAoB,CAC/B,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,gBAAgB,EAC3B,aAAa,EAAE;QACb,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,EAAE,MAAM,CAAC;QACpB,QAAQ,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"promotion.service.d.ts","sourceRoot":"","sources":["../../src/services/promotion.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,kBAAkB,CAAC;AAG1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,qBAAa,gBAAgB;IAIf,OAAO,CAAC,QAAQ,CAAC,MAAM;IAHnC,OAAO,CAAC,QAAQ,CAAC,eAAe,CACsB;gBAEzB,MAAM,EAAE,UAAU;IAE/C;;;;;;OAMG;IACU,oBAAoB,CAC/B,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,gBAAgB,EAC3B,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,mBAAmB,CAAC;IAyC/B;;;;;;OAMG;IACU,oBAAoB,CAC/B,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,gBAAgB,EAC3B,aAAa,EAAE;QACb,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,EAAE,MAAM,CAAC;QACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,aAAa,EAAE,MAAM,CAAC;QACtB,aAAa,EAAE,MAAM,CAAC;QACtB,eAAe,EAAE,MAAM,CAAC;QACxB,UAAU,EAAE,MAAM,CAAC;QACnB,UAAU,EAAE,MAAM,CAAC;KACpB,GACA,OAAO,CAAC,mBAAmB,CAAC;IAyF/B;;;;;;OAMG;IACU,qBAAqB,CAChC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,gBAAgB,EAC3B,SAA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Q,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;KACxB,GACA,OAAO,CAAC,mBAAmB,CAAC;IAkE/B;;;OAGG;IACH,OAAO,CAAC,wBAAwB;IA2BhC;;OAEG;IACH,OAAO,CAAC,mBAAmB;CAW5B"}
|
|
@@ -45,7 +45,7 @@ const common_1 = require("../types/common");
|
|
|
45
45
|
class PromotionService {
|
|
46
46
|
constructor(client) {
|
|
47
47
|
this.client = client;
|
|
48
|
-
this.promotionApiUrl = "https://openapi.zalo.me/
|
|
48
|
+
this.promotionApiUrl = "https://openapi.zalo.me/v3.0/oa/message/promotion";
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
51
|
* Gửi tin nhắn truyền thông/quảng cáo
|
|
@@ -95,28 +95,71 @@ class PromotionService {
|
|
|
95
95
|
type: "template",
|
|
96
96
|
payload: {
|
|
97
97
|
template_type: "promotion",
|
|
98
|
+
language: "VI",
|
|
98
99
|
elements: [
|
|
100
|
+
// Banner element
|
|
99
101
|
{
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
102
|
+
type: "banner",
|
|
103
|
+
...(promotionInfo.attachmentId
|
|
104
|
+
? { attachment_id: promotionInfo.attachmentId }
|
|
105
|
+
: { image_url: promotionInfo.imageUrl }),
|
|
106
|
+
},
|
|
107
|
+
// Header element
|
|
108
|
+
{
|
|
109
|
+
type: "header",
|
|
110
|
+
content: `💥💥 ${promotionInfo.title} 💥💥`,
|
|
111
|
+
align: "center",
|
|
112
|
+
},
|
|
113
|
+
// Description text
|
|
114
|
+
{
|
|
115
|
+
type: "text",
|
|
116
|
+
content: promotionInfo.description,
|
|
117
|
+
align: "left",
|
|
118
|
+
},
|
|
119
|
+
// Price table
|
|
120
|
+
{
|
|
121
|
+
type: "table",
|
|
122
|
+
content: [
|
|
108
123
|
{
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
url: promotionInfo.productUrl,
|
|
124
|
+
key: "Giá gốc",
|
|
125
|
+
value: `${promotionInfo.originalPrice.toLocaleString('vi-VN')}đ`,
|
|
112
126
|
},
|
|
113
127
|
{
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
128
|
+
key: "Giá khuyến mãi",
|
|
129
|
+
value: `${promotionInfo.discountPrice.toLocaleString('vi-VN')}đ`,
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
key: "Giảm giá",
|
|
133
|
+
value: `${promotionInfo.discountPercent}%`,
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
key: "Hạn sử dụng",
|
|
137
|
+
value: promotionInfo.validUntil,
|
|
117
138
|
},
|
|
118
139
|
],
|
|
119
140
|
},
|
|
141
|
+
// Footer text
|
|
142
|
+
{
|
|
143
|
+
type: "text",
|
|
144
|
+
content: "🛒 Nhanh tay đặt hàng để không bỏ lỡ ưu đãi!",
|
|
145
|
+
align: "center",
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
buttons: [
|
|
149
|
+
{
|
|
150
|
+
title: "Mua ngay",
|
|
151
|
+
image_icon: "",
|
|
152
|
+
type: "oa.open.url",
|
|
153
|
+
payload: {
|
|
154
|
+
url: promotionInfo.productUrl,
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
title: "Xem thêm sản phẩm",
|
|
159
|
+
image_icon: "",
|
|
160
|
+
type: "oa.query.hide",
|
|
161
|
+
payload: "#xemthem",
|
|
162
|
+
},
|
|
120
163
|
],
|
|
121
164
|
},
|
|
122
165
|
},
|
|
@@ -142,28 +185,63 @@ class PromotionService {
|
|
|
142
185
|
type: "template",
|
|
143
186
|
payload: {
|
|
144
187
|
template_type: "promotion",
|
|
188
|
+
language: "VI",
|
|
145
189
|
elements: [
|
|
190
|
+
// Banner element
|
|
146
191
|
{
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
192
|
+
type: "banner",
|
|
193
|
+
...(eventInfo.attachmentId
|
|
194
|
+
? { attachment_id: eventInfo.attachmentId }
|
|
195
|
+
: { image_url: eventInfo.imageUrl }),
|
|
196
|
+
},
|
|
197
|
+
// Header element
|
|
198
|
+
{
|
|
199
|
+
type: "header",
|
|
200
|
+
content: `🎉 ${eventInfo.title} 🎉`,
|
|
201
|
+
align: "center",
|
|
202
|
+
},
|
|
203
|
+
// Description text
|
|
204
|
+
{
|
|
205
|
+
type: "text",
|
|
206
|
+
content: eventInfo.description,
|
|
207
|
+
align: "left",
|
|
208
|
+
},
|
|
209
|
+
// Event details table
|
|
210
|
+
{
|
|
211
|
+
type: "table",
|
|
212
|
+
content: [
|
|
155
213
|
{
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
url: eventInfo.registrationUrl,
|
|
214
|
+
key: "Thời gian",
|
|
215
|
+
value: eventInfo.eventDate,
|
|
159
216
|
},
|
|
160
217
|
{
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
payload: `SHARE_EVENT_${Date.now()}`,
|
|
218
|
+
key: "Địa điểm",
|
|
219
|
+
value: eventInfo.location,
|
|
164
220
|
},
|
|
165
221
|
],
|
|
166
222
|
},
|
|
223
|
+
// Call to action text
|
|
224
|
+
{
|
|
225
|
+
type: "text",
|
|
226
|
+
content: "🎫 Đăng ký ngay để không bỏ lỡ sự kiện!",
|
|
227
|
+
align: "center",
|
|
228
|
+
},
|
|
229
|
+
],
|
|
230
|
+
buttons: [
|
|
231
|
+
{
|
|
232
|
+
title: "Đăng ký tham gia",
|
|
233
|
+
image_icon: "",
|
|
234
|
+
type: "oa.open.url",
|
|
235
|
+
payload: {
|
|
236
|
+
url: eventInfo.registrationUrl,
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
title: "Chia sẻ sự kiện",
|
|
241
|
+
image_icon: "",
|
|
242
|
+
type: "oa.query.hide",
|
|
243
|
+
payload: "#chiase",
|
|
244
|
+
},
|
|
167
245
|
],
|
|
168
246
|
},
|
|
169
247
|
},
|
|
@@ -189,23 +267,58 @@ class PromotionService {
|
|
|
189
267
|
type: "template",
|
|
190
268
|
payload: {
|
|
191
269
|
template_type: "promotion",
|
|
270
|
+
language: "VI",
|
|
192
271
|
elements: [
|
|
272
|
+
// Banner element
|
|
193
273
|
{
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
274
|
+
type: "banner",
|
|
275
|
+
...(newsletterInfo.attachmentId
|
|
276
|
+
? { attachment_id: newsletterInfo.attachmentId }
|
|
277
|
+
: { image_url: newsletterInfo.imageUrl }),
|
|
278
|
+
},
|
|
279
|
+
// Header element
|
|
280
|
+
{
|
|
281
|
+
type: "header",
|
|
282
|
+
content: `📰 ${newsletterInfo.title}`,
|
|
283
|
+
align: "center",
|
|
284
|
+
},
|
|
285
|
+
// Summary text
|
|
286
|
+
{
|
|
287
|
+
type: "text",
|
|
288
|
+
content: newsletterInfo.summary,
|
|
289
|
+
align: "left",
|
|
290
|
+
},
|
|
291
|
+
// Articles table
|
|
292
|
+
{
|
|
293
|
+
type: "table",
|
|
294
|
+
content: newsletterInfo.articles.slice(0, 5).map((article, index) => ({
|
|
295
|
+
key: `Bài viết ${index + 1}`,
|
|
296
|
+
value: article.title,
|
|
297
|
+
})),
|
|
298
|
+
},
|
|
299
|
+
// Footer text
|
|
300
|
+
{
|
|
301
|
+
type: "text",
|
|
302
|
+
content: "📖 Đọc ngay để cập nhật thông tin mới nhất!",
|
|
303
|
+
align: "center",
|
|
304
|
+
},
|
|
305
|
+
],
|
|
306
|
+
buttons: [
|
|
307
|
+
{
|
|
308
|
+
title: "Đọc toàn bộ",
|
|
309
|
+
image_icon: "",
|
|
310
|
+
type: "oa.open.url",
|
|
311
|
+
payload: {
|
|
312
|
+
url: newsletterInfo.articles[0]?.url || "#",
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
title: "Hủy đăng ký",
|
|
317
|
+
image_icon: "",
|
|
318
|
+
type: "oa.open.url",
|
|
319
|
+
payload: {
|
|
320
|
+
url: newsletterInfo.unsubscribeUrl,
|
|
321
|
+
},
|
|
209
322
|
},
|
|
210
323
|
],
|
|
211
324
|
},
|
|
@@ -217,6 +330,71 @@ class PromotionService {
|
|
|
217
330
|
throw new common_1.ZaloSDKError(`Failed to send newsletter: ${error.message}`, -1, error);
|
|
218
331
|
}
|
|
219
332
|
}
|
|
333
|
+
/**
|
|
334
|
+
* Tạo promotion message theo format chuẩn v3.0 (như trong docs)
|
|
335
|
+
* @param accessToken Access token của Official Account
|
|
336
|
+
* @param recipient Thông tin người nhận
|
|
337
|
+
* @param promotionData Dữ liệu promotion
|
|
338
|
+
* @returns Thông tin tin nhắn đã gửi
|
|
339
|
+
*/
|
|
340
|
+
async sendCustomPromotion(accessToken, recipient, promotionData) {
|
|
341
|
+
try {
|
|
342
|
+
const elements = [
|
|
343
|
+
// Banner element
|
|
344
|
+
{
|
|
345
|
+
attachment_id: promotionData.attachmentId,
|
|
346
|
+
type: "banner",
|
|
347
|
+
},
|
|
348
|
+
// Header element
|
|
349
|
+
{
|
|
350
|
+
type: "header",
|
|
351
|
+
content: promotionData.headerContent,
|
|
352
|
+
},
|
|
353
|
+
// Text element
|
|
354
|
+
{
|
|
355
|
+
type: "text",
|
|
356
|
+
align: "left",
|
|
357
|
+
content: promotionData.textContent,
|
|
358
|
+
},
|
|
359
|
+
];
|
|
360
|
+
// Add table if provided
|
|
361
|
+
if (promotionData.tableData && promotionData.tableData.length > 0) {
|
|
362
|
+
elements.push({
|
|
363
|
+
type: "table",
|
|
364
|
+
content: promotionData.tableData,
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
// Add footer text if provided
|
|
368
|
+
if (promotionData.footerText) {
|
|
369
|
+
elements.push({
|
|
370
|
+
type: "text",
|
|
371
|
+
align: "center",
|
|
372
|
+
content: promotionData.footerText,
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
const message = {
|
|
376
|
+
type: "promotion",
|
|
377
|
+
attachment: {
|
|
378
|
+
type: "template",
|
|
379
|
+
payload: {
|
|
380
|
+
template_type: "promotion",
|
|
381
|
+
language: promotionData.language || "VI",
|
|
382
|
+
elements,
|
|
383
|
+
buttons: promotionData.buttons.map(btn => ({
|
|
384
|
+
title: btn.title,
|
|
385
|
+
image_icon: btn.imageIcon || "",
|
|
386
|
+
type: btn.type,
|
|
387
|
+
payload: btn.payload,
|
|
388
|
+
})),
|
|
389
|
+
},
|
|
390
|
+
},
|
|
391
|
+
};
|
|
392
|
+
return this.sendPromotionMessage(accessToken, recipient, message);
|
|
393
|
+
}
|
|
394
|
+
catch (error) {
|
|
395
|
+
throw new common_1.ZaloSDKError(`Failed to send custom promotion: ${error.message}`, -1, error);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
220
398
|
/**
|
|
221
399
|
* Validate promotion message format
|
|
222
400
|
* @param message Promotion message to validate
|
|
@@ -231,6 +409,9 @@ class PromotionService {
|
|
|
231
409
|
if (message.attachment.payload.template_type !== "promotion") {
|
|
232
410
|
throw new common_1.ZaloSDKError("Promotion message must use promotion template type", -1);
|
|
233
411
|
}
|
|
412
|
+
if (!message.attachment.payload.elements || message.attachment.payload.elements.length === 0) {
|
|
413
|
+
throw new common_1.ZaloSDKError("Promotion message must have at least one element", -1);
|
|
414
|
+
}
|
|
234
415
|
}
|
|
235
416
|
/**
|
|
236
417
|
* Validate sending time (8:00 - 22:00)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promotion.service.js","sourceRoot":"","sources":["../../src/services/promotion.service.ts"],"names":[],"mappings":";;;AAMA,4CAA6D;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAC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J,CAAC;QAED,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7F,MAAM,IAAI,qBAAY,CACpB,kDAAkD,EAClD,CAAC,CAAC,CACH,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;OAEG;IACK,mBAAmB;QACzB,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;QAE5B,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,IAAI,EAAE,EAAE,CAAC;YAC3B,MAAM,IAAI,qBAAY,CACpB,oEAAoE,EACpE,IAAI,CACL,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AArfD,4CAqfC"}
|
package/dist/types/message.d.ts
CHANGED
|
@@ -264,32 +264,52 @@ export interface TransactionMessage extends BaseMessage {
|
|
|
264
264
|
};
|
|
265
265
|
}
|
|
266
266
|
/**
|
|
267
|
-
* Promotion message types
|
|
267
|
+
* Promotion message element types for v3.0 API
|
|
268
|
+
*/
|
|
269
|
+
export interface PromotionBannerElement {
|
|
270
|
+
type: "banner";
|
|
271
|
+
attachment_id?: string;
|
|
272
|
+
image_url?: string;
|
|
273
|
+
}
|
|
274
|
+
export interface PromotionHeaderElement {
|
|
275
|
+
type: "header";
|
|
276
|
+
content: string;
|
|
277
|
+
align?: "left" | "center" | "right";
|
|
278
|
+
}
|
|
279
|
+
export interface PromotionTextElement {
|
|
280
|
+
type: "text";
|
|
281
|
+
content: string;
|
|
282
|
+
align?: "left" | "center" | "right";
|
|
283
|
+
}
|
|
284
|
+
export interface PromotionTableElement {
|
|
285
|
+
type: "table";
|
|
286
|
+
content: Array<{
|
|
287
|
+
key: string;
|
|
288
|
+
value: string;
|
|
289
|
+
}>;
|
|
290
|
+
}
|
|
291
|
+
export type PromotionElement = PromotionBannerElement | PromotionHeaderElement | PromotionTextElement | PromotionTableElement;
|
|
292
|
+
/**
|
|
293
|
+
* Promotion message button for v3.0 API
|
|
294
|
+
*/
|
|
295
|
+
export interface PromotionButton {
|
|
296
|
+
title: string;
|
|
297
|
+
image_icon?: string;
|
|
298
|
+
type: string;
|
|
299
|
+
payload: Record<string, any> | string;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Promotion message types for v3.0 API
|
|
268
303
|
*/
|
|
269
304
|
export interface PromotionMessage extends BaseMessage {
|
|
270
305
|
type: "promotion";
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
mode?: "development" | "production";
|
|
274
|
-
attachment?: {
|
|
275
|
-
type: string;
|
|
306
|
+
attachment: {
|
|
307
|
+
type: "template";
|
|
276
308
|
payload: {
|
|
277
|
-
template_type:
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
image_url?: string;
|
|
282
|
-
default_action?: {
|
|
283
|
-
type: string;
|
|
284
|
-
url: string;
|
|
285
|
-
};
|
|
286
|
-
buttons?: Array<{
|
|
287
|
-
type: string;
|
|
288
|
-
title: string;
|
|
289
|
-
url?: string;
|
|
290
|
-
payload?: string;
|
|
291
|
-
}>;
|
|
292
|
-
}>;
|
|
309
|
+
template_type: "promotion";
|
|
310
|
+
language?: "VI" | "EN";
|
|
311
|
+
elements: PromotionElement[];
|
|
312
|
+
buttons?: PromotionButton[];
|
|
293
313
|
};
|
|
294
314
|
};
|
|
295
315
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src/types/message.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,WAAY,SAAQ,WAAW;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;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,CAAC;CAClB;AAED,MAAM,WAAW,oBAAqB,SAAQ,WAAW;IACvD,IAAI,EAAE,gBAAgB,CAAC;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,uBAAwB,SAAQ,WAAW;IAC1D,IAAI,EAAE,mBAAmB,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,eAAgB,SAAQ,WAAW;IAClD,IAAI,EAAE,UAAU,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,OAAO,CAAC;CACpE;AAED;;GAEG;AACH,MAAM,WAAW,cAAe,SAAQ,WAAW;IACjD,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GACvB,OAAO,GACP,uBAAuB,GACvB,wBAAwB,GACxB,uBAAuB,GACvB,0BAA0B,GAC1B,wBAAwB,GACxB,8BAA8B,GAC9B,kBAAkB,GAClB,gBAAgB,GAChB,oBAAoB,GACpB,qBAAqB,GACrB,oBAAoB,GACpB,uBAAuB,GACvB,eAAe,GACf,cAAc,CAAC"}
|
|
@@ -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
|
|
@@ -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",
|