@rune-kit/rune 2.10.0 → 2.12.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/LICENSE +21 -21
- package/README.md +65 -6
- package/commands/rune.md +168 -168
- package/compiler/__tests__/detect-invariants.test.js +136 -0
- package/compiler/__tests__/doctor-mesh.test.js +229 -0
- package/compiler/__tests__/hook-dispatch.test.js +91 -0
- package/compiler/__tests__/hooks-antigravity.test.js +118 -0
- package/compiler/__tests__/hooks-cursor.test.js +139 -0
- package/compiler/__tests__/hooks-install.test.js +305 -0
- package/compiler/__tests__/hooks-merge.test.js +204 -0
- package/compiler/__tests__/hooks-tiers.test.js +519 -0
- package/compiler/__tests__/hooks-windsurf.test.js +115 -0
- package/compiler/__tests__/inject-claude-md.test.js +152 -0
- package/compiler/__tests__/load-invariants.test.js +408 -0
- package/compiler/__tests__/onboard-invariants.test.js +240 -0
- package/compiler/adapters/hooks/antigravity.js +140 -0
- package/compiler/adapters/hooks/claude.js +166 -0
- package/compiler/adapters/hooks/cursor.js +191 -0
- package/compiler/adapters/hooks/index.js +82 -0
- package/compiler/adapters/hooks/tier-emitter.js +182 -0
- package/compiler/adapters/hooks/windsurf.js +202 -0
- package/compiler/bin/rune.js +196 -6
- package/compiler/commands/hook-dispatch.js +87 -0
- package/compiler/commands/hooks/install.js +120 -0
- package/compiler/commands/hooks/merge.js +211 -0
- package/compiler/commands/hooks/presets.js +116 -0
- package/compiler/commands/hooks/status.js +112 -0
- package/compiler/commands/hooks/tiers.js +221 -0
- package/compiler/commands/hooks/uninstall.js +94 -0
- package/compiler/doctor.js +236 -0
- package/contexts/dev.md +34 -34
- package/contexts/research.md +43 -43
- package/contexts/review.md +55 -55
- package/extensions/ai-ml/PACK.md +88 -88
- package/extensions/ai-ml/skills/ai-agents.md +172 -172
- package/extensions/ai-ml/skills/code-sandbox.md +187 -187
- package/extensions/ai-ml/skills/deep-research.md +146 -146
- package/extensions/ai-ml/skills/embedding-search.md +66 -66
- package/extensions/ai-ml/skills/fine-tuning-guide.md +74 -74
- package/extensions/ai-ml/skills/llm-architect.md +125 -125
- package/extensions/ai-ml/skills/llm-integration.md +64 -64
- package/extensions/ai-ml/skills/prompt-patterns.md +72 -72
- package/extensions/ai-ml/skills/rag-patterns.md +66 -66
- package/extensions/ai-ml/skills/web-extraction.md +114 -114
- package/extensions/analytics/PACK.md +92 -92
- package/extensions/analytics/skills/ab-testing.md +72 -72
- package/extensions/analytics/skills/dashboard-patterns.md +83 -83
- package/extensions/analytics/skills/data-validation.md +68 -68
- package/extensions/analytics/skills/funnel-analysis.md +81 -81
- package/extensions/analytics/skills/sql-patterns.md +57 -57
- package/extensions/analytics/skills/statistical-analysis.md +79 -79
- package/extensions/analytics/skills/tracking-setup.md +71 -71
- package/extensions/backend/PACK.md +104 -104
- package/extensions/backend/skills/api-patterns.md +84 -84
- package/extensions/backend/skills/async-pipeline.md +193 -193
- package/extensions/backend/skills/auth-patterns.md +97 -97
- package/extensions/backend/skills/background-jobs.md +133 -133
- package/extensions/backend/skills/caching-patterns.md +108 -108
- package/extensions/backend/skills/cli-generation.md +133 -133
- package/extensions/backend/skills/database-patterns.md +87 -87
- package/extensions/backend/skills/middleware-patterns.md +104 -104
- package/extensions/chrome-ext/PACK.md +93 -93
- package/extensions/chrome-ext/skills/cws-preflight.md +143 -143
- package/extensions/chrome-ext/skills/cws-publish.md +104 -104
- package/extensions/chrome-ext/skills/ext-ai-integration.md +251 -251
- package/extensions/chrome-ext/skills/ext-messaging.md +139 -139
- package/extensions/chrome-ext/skills/ext-storage.md +133 -133
- package/extensions/chrome-ext/skills/mv3-scaffold.md +164 -164
- package/extensions/content/PACK.md +96 -96
- package/extensions/content/skills/blog-patterns.md +88 -88
- package/extensions/content/skills/cms-integration.md +131 -131
- package/extensions/content/skills/content-scoring.md +107 -107
- package/extensions/content/skills/i18n.md +83 -83
- package/extensions/content/skills/mdx-authoring.md +137 -137
- package/extensions/content/skills/reference.md +1014 -1014
- package/extensions/content/skills/seo-patterns.md +67 -67
- package/extensions/content/skills/video-repurpose.md +153 -153
- package/extensions/devops/PACK.md +101 -101
- package/extensions/devops/skills/chaos-testing.md +67 -67
- package/extensions/devops/skills/ci-cd.md +75 -75
- package/extensions/devops/skills/docker.md +58 -58
- package/extensions/devops/skills/edge-serverless.md +163 -163
- package/extensions/devops/skills/infra-as-code.md +158 -158
- package/extensions/devops/skills/kubernetes.md +110 -110
- package/extensions/devops/skills/monitoring.md +57 -57
- package/extensions/devops/skills/server-setup.md +64 -64
- package/extensions/devops/skills/ssl-domain.md +42 -42
- package/extensions/ecommerce/PACK.md +116 -116
- package/extensions/ecommerce/skills/cart-system.md +79 -79
- package/extensions/ecommerce/skills/inventory-mgmt.md +102 -102
- package/extensions/ecommerce/skills/order-management.md +126 -126
- package/extensions/ecommerce/skills/payment-integration.md +472 -472
- package/extensions/ecommerce/skills/shopify-dev.md +69 -69
- package/extensions/ecommerce/skills/subscription-billing.md +93 -93
- package/extensions/ecommerce/skills/tax-compliance.md +117 -117
- package/extensions/gamedev/PACK.md +142 -142
- package/extensions/gamedev/skills/asset-pipeline.md +74 -74
- package/extensions/gamedev/skills/audio-system.md +129 -129
- package/extensions/gamedev/skills/camera-system.md +87 -87
- package/extensions/gamedev/skills/ecs.md +98 -98
- package/extensions/gamedev/skills/game-loops.md +72 -72
- package/extensions/gamedev/skills/input-system.md +199 -199
- package/extensions/gamedev/skills/multiplayer.md +180 -180
- package/extensions/gamedev/skills/particles.md +105 -105
- package/extensions/gamedev/skills/physics-engine.md +89 -89
- package/extensions/gamedev/skills/scene-management.md +146 -146
- package/extensions/gamedev/skills/threejs-patterns.md +90 -90
- package/extensions/gamedev/skills/webgl.md +71 -71
- package/extensions/mobile/PACK.md +106 -106
- package/extensions/mobile/skills/app-store-connect.md +152 -152
- package/extensions/mobile/skills/app-store-prep.md +66 -66
- package/extensions/mobile/skills/deep-linking.md +109 -109
- package/extensions/mobile/skills/flutter.md +60 -60
- package/extensions/mobile/skills/ios-build-pipeline.md +142 -142
- package/extensions/mobile/skills/native-bridge.md +66 -66
- package/extensions/mobile/skills/ota-updates.md +97 -97
- package/extensions/mobile/skills/push-notifications.md +111 -111
- package/extensions/mobile/skills/react-native.md +82 -82
- package/extensions/saas/PACK.md +116 -116
- package/extensions/saas/skills/billing-integration.md +200 -200
- package/extensions/saas/skills/feature-flags.md +130 -130
- package/extensions/saas/skills/multi-tenant.md +103 -103
- package/extensions/saas/skills/onboarding-flow.md +139 -139
- package/extensions/saas/skills/subscription-flow.md +95 -95
- package/extensions/saas/skills/team-management.md +144 -144
- package/extensions/security/PACK.md +99 -99
- package/extensions/security/skills/api-security.md +140 -140
- package/extensions/security/skills/compliance.md +68 -68
- package/extensions/security/skills/owasp-audit.md +64 -64
- package/extensions/security/skills/pentest-patterns.md +77 -77
- package/extensions/security/skills/secret-mgmt.md +65 -65
- package/extensions/security/skills/supply-chain.md +65 -65
- package/extensions/trading/PACK.md +80 -80
- package/extensions/trading/skills/chart-components.md +55 -55
- package/extensions/trading/skills/experiment-loop.md +125 -125
- package/extensions/trading/skills/fintech-patterns.md +47 -47
- package/extensions/trading/skills/indicator-library.md +58 -58
- package/extensions/trading/skills/quant-analysis.md +111 -111
- package/extensions/trading/skills/realtime-data.md +58 -58
- package/extensions/trading/skills/trade-logic.md +104 -104
- package/extensions/ui/PACK.md +130 -130
- package/extensions/ui/skills/a11y-audit.md +91 -91
- package/extensions/ui/skills/animation-patterns.md +127 -127
- package/extensions/ui/skills/component-patterns.md +100 -100
- package/extensions/ui/skills/design-decision.md +108 -108
- package/extensions/ui/skills/design-system.md +68 -68
- package/extensions/ui/skills/landing-patterns.md +155 -155
- package/extensions/ui/skills/palette-picker.md +173 -173
- package/extensions/ui/skills/react-health.md +90 -90
- package/extensions/ui/skills/type-system.md +125 -125
- package/extensions/ui/skills/web-vitals.md +153 -153
- package/extensions/zalo/PACK.md +145 -145
- package/extensions/zalo/skills/zalo-oa-mcp.md +317 -317
- package/extensions/zalo/skills/zalo-oa-messaging.md +429 -429
- package/extensions/zalo/skills/zalo-oa-setup.md +236 -236
- package/extensions/zalo/skills/zalo-oa-webhook.md +189 -189
- package/extensions/zalo/skills/zalo-personal-messaging.md +194 -194
- package/extensions/zalo/skills/zalo-personal-setup.md +153 -153
- package/extensions/zalo/skills/zalo-rate-guard.md +219 -219
- package/hooks/auto-format/index.cjs +48 -48
- package/hooks/hooks.json +111 -111
- package/hooks/post-session-reflect/index.cjs +189 -189
- package/hooks/pre-compact/index.cjs +95 -95
- package/hooks/run-hook.cmd +1 -1
- package/hooks/secrets-scan/index.cjs +100 -100
- package/hooks/session-start/index.cjs +71 -71
- package/hooks/typecheck/index.cjs +65 -65
- package/package.json +63 -63
- package/references/ui-pro-max-data/LICENSE-UI-PRO-MAX +21 -21
- package/references/ui-pro-max-data/charts.csv +26 -26
- package/references/ui-pro-max-data/colors.csv +161 -161
- package/references/ui-pro-max-data/styles.csv +68 -68
- package/references/ui-pro-max-data/typography.csv +74 -74
- package/references/ui-pro-max-data/ui-reasoning.csv +162 -162
- package/references/ui-pro-max-data/ux-guidelines.csv +99 -99
- package/skills/adversary/SKILL.md +283 -283
- package/skills/asset-creator/SKILL.md +157 -157
- package/skills/audit/SKILL.md +147 -2
- package/skills/autopsy/SKILL.md +335 -335
- package/skills/ba/SKILL.md +85 -1
- package/skills/brainstorm/SKILL.md +380 -342
- package/skills/browser-pilot/SKILL.md +169 -168
- package/skills/constraint-check/SKILL.md +165 -165
- package/skills/context-engine/SKILL.md +408 -404
- package/skills/cook/SKILL.md +917 -863
- package/skills/db/SKILL.md +273 -273
- package/skills/debug/SKILL.md +465 -465
- package/skills/dependency-doctor/SKILL.md +265 -235
- package/skills/deploy/SKILL.md +274 -231
- package/skills/design/DESIGN-REFERENCE.md +365 -365
- package/skills/design/SKILL.md +590 -589
- package/skills/doc-processor/SKILL.md +254 -254
- package/skills/docs/SKILL.md +374 -374
- package/skills/docs-seeker/SKILL.md +178 -177
- package/skills/fix/SKILL.md +332 -330
- package/skills/git/SKILL.md +339 -339
- package/skills/hallucination-guard/SKILL.md +220 -219
- package/skills/incident/SKILL.md +254 -253
- package/skills/integrity-check/SKILL.md +169 -169
- package/skills/journal/SKILL.md +241 -240
- package/skills/launch/SKILL.md +344 -344
- package/skills/logic-guardian/SKILL.md +269 -251
- package/skills/marketing/SKILL.md +351 -289
- package/skills/mcp-builder/SKILL.md +425 -425
- package/skills/neural-memory/SKILL.md +359 -362
- package/skills/onboard/SKILL.md +432 -403
- package/skills/onboard/references/invariants-template.md +76 -0
- package/skills/onboard/scripts/detect-invariants.js +439 -0
- package/skills/onboard/scripts/inject-claude-md.js +150 -0
- package/skills/onboard/scripts/onboard-invariants.js +194 -0
- package/skills/perf/SKILL.md +347 -346
- package/skills/plan/SKILL.md +435 -428
- package/skills/preflight/SKILL.md +415 -415
- package/skills/problem-solver/SKILL.md +380 -284
- package/skills/rescue/SKILL.md +474 -474
- package/skills/research/SKILL.md +4 -0
- package/skills/retro/SKILL.md +3 -1
- package/skills/review/SKILL.md +614 -588
- package/skills/review-intake/SKILL.md +249 -249
- package/skills/safeguard/SKILL.md +200 -200
- package/skills/sast/SKILL.md +190 -190
- package/skills/scaffold/SKILL.md +328 -287
- package/skills/scope-guard/SKILL.md +183 -180
- package/skills/scout/SKILL.md +269 -263
- package/skills/sentinel/SKILL.md +384 -381
- package/skills/sentinel-env/SKILL.md +254 -254
- package/skills/sequential-thinking/SKILL.md +234 -234
- package/skills/session-bridge/SKILL.md +595 -543
- package/skills/session-bridge/scripts/load-invariants.js +397 -0
- package/skills/skill-forge/SKILL.md +581 -581
- package/skills/skill-router/SKILL.md +3 -0
- package/skills/slides/SKILL.md +19 -0
- package/skills/surgeon/SKILL.md +215 -215
- package/skills/team/SKILL.md +557 -537
- package/skills/test/SKILL.md +620 -614
- package/skills/trend-scout/SKILL.md +145 -145
- package/skills/verification/SKILL.md +334 -326
- package/skills/video-creator/SKILL.md +201 -201
- package/skills/watchdog/SKILL.md +168 -168
- package/skills/worktree/SKILL.md +140 -140
|
@@ -1,429 +1,429 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: zalo-oa-messaging
|
|
3
|
-
pack: "@rune/zalo"
|
|
4
|
-
description: All 8 OA message types (text, image, file, sticker, list, template, transaction, promotion), follower management, and broadcast with demographic targeting.
|
|
5
|
-
model: sonnet
|
|
6
|
-
tools: "Read, Glob, Grep, Bash, Write, Edit"
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
# zalo-oa-messaging
|
|
10
|
-
|
|
11
|
-
Send any of the 8 Zalo OA message types, manage followers, and run broadcast campaigns via the v3 Official Account API.
|
|
12
|
-
|
|
13
|
-
## Base Config
|
|
14
|
-
|
|
15
|
-
```
|
|
16
|
-
Base URL : https://openapi.zalo.me/v3.0/oa
|
|
17
|
-
Upload : https://openapi.zalo.me/v2.0/oa (intentional version mismatch)
|
|
18
|
-
Auth : Authorization: Bearer {oa_access_token}
|
|
19
|
-
Content : Content-Type: application/json
|
|
20
|
-
Endpoint : POST /message/cs (all 8 CS message types)
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Step 1 — Identify the Message Type
|
|
24
|
-
|
|
25
|
-
| # | Type | Use Case | Constraint |
|
|
26
|
-
|---|------|----------|------------|
|
|
27
|
-
| 1 | Text | Simple reply, notification | 2000 char limit |
|
|
28
|
-
| 2 | Image | Product photo, banner | attachment_id from upload |
|
|
29
|
-
| 3 | File | PDF, invoice, document | attachment_id from upload |
|
|
30
|
-
| 4 | Sticker | Friendly interaction | sticker_id from catalog |
|
|
31
|
-
| 5 | List | Menu, product listing | max 10 items |
|
|
32
|
-
| 6 | Template | CTA with buttons | max 5 buttons |
|
|
33
|
-
| 7 | Transaction | Order/shipping update | pre-approved template required |
|
|
34
|
-
| 8 | Promotion | Marketing campaign | approved template + quota |
|
|
35
|
-
|
|
36
|
-
**All CS messages**: only sendable within 7 days of user's last interaction with the OA.
|
|
37
|
-
|
|
38
|
-
---
|
|
39
|
-
|
|
40
|
-
## Step 2 — Send the Right Payload
|
|
41
|
-
|
|
42
|
-
### Type 1 — Text Message
|
|
43
|
-
|
|
44
|
-
```http
|
|
45
|
-
POST https://openapi.zalo.me/v3.0/oa/message/cs
|
|
46
|
-
Authorization: Bearer {oa_access_token}
|
|
47
|
-
|
|
48
|
-
{
|
|
49
|
-
"recipient": { "user_id": "4337842264521611405" },
|
|
50
|
-
"message": { "text": "Xin chào! Chúng tôi có thể giúp gì cho bạn?" }
|
|
51
|
-
}
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
Response (success):
|
|
55
|
-
```json
|
|
56
|
-
{ "error": 0, "message": "Success", "data": { "message_id": "oaMsgId.567890" } }
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
---
|
|
60
|
-
|
|
61
|
-
### Type 2 — Image Message
|
|
62
|
-
|
|
63
|
-
Upload first (v2.0 endpoint), then send:
|
|
64
|
-
|
|
65
|
-
```http
|
|
66
|
-
POST https://openapi.zalo.me/v2.0/oa/upload/image
|
|
67
|
-
Authorization: Bearer {oa_access_token}
|
|
68
|
-
Content-Type: multipart/form-data
|
|
69
|
-
|
|
70
|
-
file=@banner.jpg (max 1MB)
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
```json
|
|
74
|
-
{ "error": 0, "data": { "attachment_id": "f8d5a7e1-2b3c-4d5e-8f9a-1b2c3d4e5f6a" } }
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
Then send:
|
|
78
|
-
|
|
79
|
-
```json
|
|
80
|
-
{
|
|
81
|
-
"recipient": { "user_id": "4337842264521611405" },
|
|
82
|
-
"message": {
|
|
83
|
-
"attachment": {
|
|
84
|
-
"type": "template",
|
|
85
|
-
"payload": {
|
|
86
|
-
"template_type": "media",
|
|
87
|
-
"elements": [{
|
|
88
|
-
"media_type": "image",
|
|
89
|
-
"attachment_id": "f8d5a7e1-2b3c-4d5e-8f9a-1b2c3d4e5f6a"
|
|
90
|
-
}]
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
---
|
|
98
|
-
|
|
99
|
-
### Type 3 — File Message
|
|
100
|
-
|
|
101
|
-
```http
|
|
102
|
-
POST https://openapi.zalo.me/v2.0/oa/upload/file
|
|
103
|
-
Authorization: Bearer {oa_access_token}
|
|
104
|
-
Content-Type: multipart/form-data
|
|
105
|
-
|
|
106
|
-
file=@invoice.pdf (max 5MB)
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
```json
|
|
110
|
-
{ "error": 0, "data": { "attachment_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890" } }
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
Send payload same shape as image but `"media_type": "file"`.
|
|
114
|
-
|
|
115
|
-
---
|
|
116
|
-
|
|
117
|
-
### Type 4 — Sticker Message
|
|
118
|
-
|
|
119
|
-
```json
|
|
120
|
-
{
|
|
121
|
-
"recipient": { "user_id": "4337842264521611405" },
|
|
122
|
-
"message": {
|
|
123
|
-
"attachment": {
|
|
124
|
-
"type": "template",
|
|
125
|
-
"payload": {
|
|
126
|
-
"template_type": "media",
|
|
127
|
-
"elements": [{ "media_type": "sticker", "attachment_id": "87521" }]
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
Sticker IDs: fetch from Zalo sticker catalog. Common IDs: 87521 (thumbs up), 87522 (heart), 87523 (smile).
|
|
135
|
-
|
|
136
|
-
---
|
|
137
|
-
|
|
138
|
-
### Type 5 — List Message
|
|
139
|
-
|
|
140
|
-
```json
|
|
141
|
-
{
|
|
142
|
-
"recipient": { "user_id": "4337842264521611405" },
|
|
143
|
-
"message": {
|
|
144
|
-
"attachment": {
|
|
145
|
-
"type": "template",
|
|
146
|
-
"payload": {
|
|
147
|
-
"template_type": "list",
|
|
148
|
-
"elements": [
|
|
149
|
-
{
|
|
150
|
-
"title": "Sản phẩm A",
|
|
151
|
-
"subtitle": "Giá: 299.000đ",
|
|
152
|
-
"image_url": "https://cdn.example.com/product-a.jpg",
|
|
153
|
-
"default_action": { "type": "oa.open.url", "url": "https://example.com/product-a" }
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
"title": "Sản phẩm B",
|
|
157
|
-
"subtitle": "Giá: 199.000đ",
|
|
158
|
-
"image_url": "https://cdn.example.com/product-b.jpg",
|
|
159
|
-
"default_action": { "type": "oa.open.url", "url": "https://example.com/product-b" }
|
|
160
|
-
}
|
|
161
|
-
],
|
|
162
|
-
"buttons": [{
|
|
163
|
-
"title": "Xem tất cả sản phẩm",
|
|
164
|
-
"type": "oa.open.url",
|
|
165
|
-
"payload": { "url": "https://example.com/products" }
|
|
166
|
-
}]
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
Limits: max 10 elements, max 5 buttons at bottom.
|
|
174
|
-
|
|
175
|
-
---
|
|
176
|
-
|
|
177
|
-
### Type 6 — Template Message (Button Template)
|
|
178
|
-
|
|
179
|
-
```json
|
|
180
|
-
{
|
|
181
|
-
"recipient": { "user_id": "4337842264521611405" },
|
|
182
|
-
"message": {
|
|
183
|
-
"attachment": {
|
|
184
|
-
"type": "template",
|
|
185
|
-
"payload": {
|
|
186
|
-
"template_type": "button",
|
|
187
|
-
"text": "Chọn hành động bạn muốn thực hiện:",
|
|
188
|
-
"buttons": [
|
|
189
|
-
{
|
|
190
|
-
"title": "Xem đơn hàng",
|
|
191
|
-
"type": "oa.open.url",
|
|
192
|
-
"payload": { "url": "https://example.com/orders" }
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
"title": "Gọi hỗ trợ",
|
|
196
|
-
"type": "oa.open.phone",
|
|
197
|
-
"payload": { "phone_code": "0901234567" }
|
|
198
|
-
},
|
|
199
|
-
{
|
|
200
|
-
"title": "Theo dõi vận chuyển",
|
|
201
|
-
"type": "oa.query.show",
|
|
202
|
-
"payload": { "content": "TRACK_ORDER_12345" }
|
|
203
|
-
}
|
|
204
|
-
]
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
Button types: `oa.open.url`, `oa.open.phone`, `oa.query.show` (postback), `oa.open.sms`.
|
|
212
|
-
|
|
213
|
-
---
|
|
214
|
-
|
|
215
|
-
### Type 7 — Transaction Message
|
|
216
|
-
|
|
217
|
-
Requires a pre-approved template from Zalo OA portal. Cannot send arbitrary content.
|
|
218
|
-
|
|
219
|
-
```json
|
|
220
|
-
{
|
|
221
|
-
"recipient": { "user_id": "4337842264521611405" },
|
|
222
|
-
"message": {
|
|
223
|
-
"attachment": {
|
|
224
|
-
"type": "template",
|
|
225
|
-
"payload": {
|
|
226
|
-
"template_type": "transaction_order",
|
|
227
|
-
"language": "VI",
|
|
228
|
-
"elements": [{
|
|
229
|
-
"attachment_id": "approved-template-id-from-zalo",
|
|
230
|
-
"type": "banner"
|
|
231
|
-
}],
|
|
232
|
-
"parameters": {
|
|
233
|
-
"order_id": "ORD-2026-001234",
|
|
234
|
-
"order_status": "Đã giao hàng",
|
|
235
|
-
"delivery_date": "15/03/2026",
|
|
236
|
-
"tracking_url": "https://example.com/track/ORD-2026-001234"
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
Template must match an approved template ID. Parameter keys defined by the template.
|
|
245
|
-
|
|
246
|
-
---
|
|
247
|
-
|
|
248
|
-
### Type 8 — Promotion Message
|
|
249
|
-
|
|
250
|
-
Requires approved template + sufficient broadcast quota.
|
|
251
|
-
|
|
252
|
-
```json
|
|
253
|
-
{
|
|
254
|
-
"recipient": { "user_id": "4337842264521611405" },
|
|
255
|
-
"message": {
|
|
256
|
-
"attachment": {
|
|
257
|
-
"type": "template",
|
|
258
|
-
"payload": {
|
|
259
|
-
"template_type": "promotion",
|
|
260
|
-
"language": "VI",
|
|
261
|
-
"elements": [{
|
|
262
|
-
"attachment_id": "approved-promo-banner-id",
|
|
263
|
-
"type": "banner"
|
|
264
|
-
}],
|
|
265
|
-
"parameters": {
|
|
266
|
-
"coupon_code": "SALE30",
|
|
267
|
-
"discount": "30%",
|
|
268
|
-
"expiry": "31/03/2026"
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
```
|
|
275
|
-
|
|
276
|
-
---
|
|
277
|
-
|
|
278
|
-
## Step 3 — Long Text Chunking
|
|
279
|
-
|
|
280
|
-
Text limit is 2000 chars. Chunk before sending:
|
|
281
|
-
|
|
282
|
-
```typescript
|
|
283
|
-
function chunkMessage(text: string, limit = 2000): string[] {
|
|
284
|
-
if (text.length <= limit) return [text]
|
|
285
|
-
const chunks: string[] = []
|
|
286
|
-
let remaining = text
|
|
287
|
-
while (remaining.length > 0) {
|
|
288
|
-
if (remaining.length <= limit) { chunks.push(remaining); break }
|
|
289
|
-
let splitAt = remaining.lastIndexOf('\n', limit)
|
|
290
|
-
if (splitAt === -1) splitAt = remaining.lastIndexOf(' ', limit)
|
|
291
|
-
if (splitAt === -1) splitAt = limit
|
|
292
|
-
chunks.push(remaining.slice(0, splitAt))
|
|
293
|
-
remaining = remaining.slice(splitAt).trimStart()
|
|
294
|
-
}
|
|
295
|
-
return chunks
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
// Send each chunk with delay to respect rate limits
|
|
299
|
-
for (const chunk of chunkMessage(longText)) {
|
|
300
|
-
await sendTextMessage(userId, chunk)
|
|
301
|
-
await new Promise(r => setTimeout(r, 300))
|
|
302
|
-
}
|
|
303
|
-
```
|
|
304
|
-
|
|
305
|
-
---
|
|
306
|
-
|
|
307
|
-
## Step 4 — Follower Management
|
|
308
|
-
|
|
309
|
-
### List Followers
|
|
310
|
-
|
|
311
|
-
```http
|
|
312
|
-
GET https://openapi.zalo.me/v3.0/oa/user/getlist?offset=0&count=50
|
|
313
|
-
Authorization: Bearer {oa_access_token}
|
|
314
|
-
```
|
|
315
|
-
|
|
316
|
-
```json
|
|
317
|
-
{
|
|
318
|
-
"error": 0,
|
|
319
|
-
"data": {
|
|
320
|
-
"users": [
|
|
321
|
-
{ "user_id": "4337842264521611405", "display_name": "Nguyen Van A", "followed_date": 1709827200 }
|
|
322
|
-
],
|
|
323
|
-
"total": 1250,
|
|
324
|
-
"offset": 0,
|
|
325
|
-
"count": 50
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
```
|
|
329
|
-
|
|
330
|
-
Paginate: increment `offset` by `count` until `offset >= total`.
|
|
331
|
-
|
|
332
|
-
### User Profile
|
|
333
|
-
|
|
334
|
-
```http
|
|
335
|
-
GET https://openapi.zalo.me/v3.0/oa/user/detail?user_id=4337842264521611405
|
|
336
|
-
Authorization: Bearer {oa_access_token}
|
|
337
|
-
```
|
|
338
|
-
|
|
339
|
-
```json
|
|
340
|
-
{
|
|
341
|
-
"error": 0,
|
|
342
|
-
"data": {
|
|
343
|
-
"user_id": "4337842264521611405",
|
|
344
|
-
"display_name": "Nguyen Van A",
|
|
345
|
-
"birth_date": 0,
|
|
346
|
-
"gender": 1,
|
|
347
|
-
"phone": "",
|
|
348
|
-
"city": "Ho Chi Minh City",
|
|
349
|
-
"district": "",
|
|
350
|
-
"tags_and_notes_info": { "tag_names": ["VIP", "Repeat-buyer"] }
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
```
|
|
354
|
-
|
|
355
|
-
Note: `user_id` is OA-scoped — same person has a different `user_id` for each OA they follow.
|
|
356
|
-
|
|
357
|
-
### Tag Management
|
|
358
|
-
|
|
359
|
-
```http
|
|
360
|
-
POST https://openapi.zalo.me/v3.0/oa/tag/tagfollower
|
|
361
|
-
Authorization: Bearer {oa_access_token}
|
|
362
|
-
|
|
363
|
-
{ "user_id": "4337842264521611405", "tag_name": "VIP" }
|
|
364
|
-
```
|
|
365
|
-
|
|
366
|
-
```http
|
|
367
|
-
POST https://openapi.zalo.me/v3.0/oa/tag/rmfollowerfromtag
|
|
368
|
-
Authorization: Bearer {oa_access_token}
|
|
369
|
-
|
|
370
|
-
{ "user_id": "4337842264521611405", "tag_name": "VIP" }
|
|
371
|
-
```
|
|
372
|
-
|
|
373
|
-
---
|
|
374
|
-
|
|
375
|
-
## Step 5 — Broadcast
|
|
376
|
-
|
|
377
|
-
```http
|
|
378
|
-
POST https://openapi.zalo.me/v3.0/oa/message/promotion
|
|
379
|
-
Authorization: Bearer {oa_access_token}
|
|
380
|
-
|
|
381
|
-
{
|
|
382
|
-
"recipient": {
|
|
383
|
-
"target": {
|
|
384
|
-
"gender": 1,
|
|
385
|
-
"ages": ["18-25", "26-35"],
|
|
386
|
-
"cities": ["Ho Chi Minh City", "Ha Noi"],
|
|
387
|
-
"platforms": ["iOS", "Android"],
|
|
388
|
-
"telcos": ["Viettel", "Mobifone"]
|
|
389
|
-
}
|
|
390
|
-
},
|
|
391
|
-
"message": {
|
|
392
|
-
"attachment": {
|
|
393
|
-
"type": "template",
|
|
394
|
-
"payload": {
|
|
395
|
-
"template_type": "promotion",
|
|
396
|
-
"language": "VI",
|
|
397
|
-
"elements": [{ "attachment_id": "approved-promo-banner-id", "type": "banner" }],
|
|
398
|
-
"parameters": { "coupon_code": "SUMMER30", "discount": "30%" }
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
```
|
|
404
|
-
|
|
405
|
-
Response includes estimated reach count before send is confirmed. Quota resets monthly.
|
|
406
|
-
|
|
407
|
-
---
|
|
408
|
-
|
|
409
|
-
## Sharp Edges
|
|
410
|
-
|
|
411
|
-
- **7-day CS window** — `error: 12` means the user hasn't interacted in 7 days. Cannot bypass. Solution: use Transaction or Promotion templates (pre-approved) which ignore the window.
|
|
412
|
-
- **Version mismatch is intentional** — upload endpoints stay on `v2.0`, message send is `v3.0`. Do not "fix" this.
|
|
413
|
-
- **OA-scoped user_id** — never assume the same physical person has the same `user_id` across different OAs. Always store per-OA.
|
|
414
|
-
- **Template approval lag** — Transaction/Promotion templates take 1-5 business days to approve. Plan ahead; cannot substitute with CS messages after approval delay.
|
|
415
|
-
- **Image 1MB / File 5MB hard limits** — compress images server-side before upload. Zalo returns `error: 201` for oversized files.
|
|
416
|
-
- **Broadcast quota** — based on follower count × OA verification tier. Track monthly usage; `error: 133` = quota exceeded.
|
|
417
|
-
- **Button limit 5** — template messages silently drop buttons beyond index 4. Always validate `buttons.length <= 5` before sending.
|
|
418
|
-
|
|
419
|
-
## Error Codes Quick Reference
|
|
420
|
-
|
|
421
|
-
| Code | Meaning | Fix |
|
|
422
|
-
|------|---------|-----|
|
|
423
|
-
| 0 | Success | — |
|
|
424
|
-
| 12 | Outside 7-day CS window | Use approved template type |
|
|
425
|
-
| 14 | Invalid access token | Refresh token, retry |
|
|
426
|
-
| 107 | Invalid recipient | Verify user_id is OA-scoped and valid |
|
|
427
|
-
| 133 | Broadcast quota exceeded | Wait for monthly reset |
|
|
428
|
-
| 201 | File size exceeded | Compress/split before upload |
|
|
429
|
-
| 216 | Template not approved | Submit template for Zalo review |
|
|
1
|
+
---
|
|
2
|
+
name: zalo-oa-messaging
|
|
3
|
+
pack: "@rune/zalo"
|
|
4
|
+
description: All 8 OA message types (text, image, file, sticker, list, template, transaction, promotion), follower management, and broadcast with demographic targeting.
|
|
5
|
+
model: sonnet
|
|
6
|
+
tools: "Read, Glob, Grep, Bash, Write, Edit"
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# zalo-oa-messaging
|
|
10
|
+
|
|
11
|
+
Send any of the 8 Zalo OA message types, manage followers, and run broadcast campaigns via the v3 Official Account API.
|
|
12
|
+
|
|
13
|
+
## Base Config
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
Base URL : https://openapi.zalo.me/v3.0/oa
|
|
17
|
+
Upload : https://openapi.zalo.me/v2.0/oa (intentional version mismatch)
|
|
18
|
+
Auth : Authorization: Bearer {oa_access_token}
|
|
19
|
+
Content : Content-Type: application/json
|
|
20
|
+
Endpoint : POST /message/cs (all 8 CS message types)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Step 1 — Identify the Message Type
|
|
24
|
+
|
|
25
|
+
| # | Type | Use Case | Constraint |
|
|
26
|
+
|---|------|----------|------------|
|
|
27
|
+
| 1 | Text | Simple reply, notification | 2000 char limit |
|
|
28
|
+
| 2 | Image | Product photo, banner | attachment_id from upload |
|
|
29
|
+
| 3 | File | PDF, invoice, document | attachment_id from upload |
|
|
30
|
+
| 4 | Sticker | Friendly interaction | sticker_id from catalog |
|
|
31
|
+
| 5 | List | Menu, product listing | max 10 items |
|
|
32
|
+
| 6 | Template | CTA with buttons | max 5 buttons |
|
|
33
|
+
| 7 | Transaction | Order/shipping update | pre-approved template required |
|
|
34
|
+
| 8 | Promotion | Marketing campaign | approved template + quota |
|
|
35
|
+
|
|
36
|
+
**All CS messages**: only sendable within 7 days of user's last interaction with the OA.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Step 2 — Send the Right Payload
|
|
41
|
+
|
|
42
|
+
### Type 1 — Text Message
|
|
43
|
+
|
|
44
|
+
```http
|
|
45
|
+
POST https://openapi.zalo.me/v3.0/oa/message/cs
|
|
46
|
+
Authorization: Bearer {oa_access_token}
|
|
47
|
+
|
|
48
|
+
{
|
|
49
|
+
"recipient": { "user_id": "4337842264521611405" },
|
|
50
|
+
"message": { "text": "Xin chào! Chúng tôi có thể giúp gì cho bạn?" }
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Response (success):
|
|
55
|
+
```json
|
|
56
|
+
{ "error": 0, "message": "Success", "data": { "message_id": "oaMsgId.567890" } }
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
### Type 2 — Image Message
|
|
62
|
+
|
|
63
|
+
Upload first (v2.0 endpoint), then send:
|
|
64
|
+
|
|
65
|
+
```http
|
|
66
|
+
POST https://openapi.zalo.me/v2.0/oa/upload/image
|
|
67
|
+
Authorization: Bearer {oa_access_token}
|
|
68
|
+
Content-Type: multipart/form-data
|
|
69
|
+
|
|
70
|
+
file=@banner.jpg (max 1MB)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
{ "error": 0, "data": { "attachment_id": "f8d5a7e1-2b3c-4d5e-8f9a-1b2c3d4e5f6a" } }
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Then send:
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"recipient": { "user_id": "4337842264521611405" },
|
|
82
|
+
"message": {
|
|
83
|
+
"attachment": {
|
|
84
|
+
"type": "template",
|
|
85
|
+
"payload": {
|
|
86
|
+
"template_type": "media",
|
|
87
|
+
"elements": [{
|
|
88
|
+
"media_type": "image",
|
|
89
|
+
"attachment_id": "f8d5a7e1-2b3c-4d5e-8f9a-1b2c3d4e5f6a"
|
|
90
|
+
}]
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
### Type 3 — File Message
|
|
100
|
+
|
|
101
|
+
```http
|
|
102
|
+
POST https://openapi.zalo.me/v2.0/oa/upload/file
|
|
103
|
+
Authorization: Bearer {oa_access_token}
|
|
104
|
+
Content-Type: multipart/form-data
|
|
105
|
+
|
|
106
|
+
file=@invoice.pdf (max 5MB)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
```json
|
|
110
|
+
{ "error": 0, "data": { "attachment_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890" } }
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Send payload same shape as image but `"media_type": "file"`.
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
### Type 4 — Sticker Message
|
|
118
|
+
|
|
119
|
+
```json
|
|
120
|
+
{
|
|
121
|
+
"recipient": { "user_id": "4337842264521611405" },
|
|
122
|
+
"message": {
|
|
123
|
+
"attachment": {
|
|
124
|
+
"type": "template",
|
|
125
|
+
"payload": {
|
|
126
|
+
"template_type": "media",
|
|
127
|
+
"elements": [{ "media_type": "sticker", "attachment_id": "87521" }]
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Sticker IDs: fetch from Zalo sticker catalog. Common IDs: 87521 (thumbs up), 87522 (heart), 87523 (smile).
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
### Type 5 — List Message
|
|
139
|
+
|
|
140
|
+
```json
|
|
141
|
+
{
|
|
142
|
+
"recipient": { "user_id": "4337842264521611405" },
|
|
143
|
+
"message": {
|
|
144
|
+
"attachment": {
|
|
145
|
+
"type": "template",
|
|
146
|
+
"payload": {
|
|
147
|
+
"template_type": "list",
|
|
148
|
+
"elements": [
|
|
149
|
+
{
|
|
150
|
+
"title": "Sản phẩm A",
|
|
151
|
+
"subtitle": "Giá: 299.000đ",
|
|
152
|
+
"image_url": "https://cdn.example.com/product-a.jpg",
|
|
153
|
+
"default_action": { "type": "oa.open.url", "url": "https://example.com/product-a" }
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
"title": "Sản phẩm B",
|
|
157
|
+
"subtitle": "Giá: 199.000đ",
|
|
158
|
+
"image_url": "https://cdn.example.com/product-b.jpg",
|
|
159
|
+
"default_action": { "type": "oa.open.url", "url": "https://example.com/product-b" }
|
|
160
|
+
}
|
|
161
|
+
],
|
|
162
|
+
"buttons": [{
|
|
163
|
+
"title": "Xem tất cả sản phẩm",
|
|
164
|
+
"type": "oa.open.url",
|
|
165
|
+
"payload": { "url": "https://example.com/products" }
|
|
166
|
+
}]
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Limits: max 10 elements, max 5 buttons at bottom.
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
### Type 6 — Template Message (Button Template)
|
|
178
|
+
|
|
179
|
+
```json
|
|
180
|
+
{
|
|
181
|
+
"recipient": { "user_id": "4337842264521611405" },
|
|
182
|
+
"message": {
|
|
183
|
+
"attachment": {
|
|
184
|
+
"type": "template",
|
|
185
|
+
"payload": {
|
|
186
|
+
"template_type": "button",
|
|
187
|
+
"text": "Chọn hành động bạn muốn thực hiện:",
|
|
188
|
+
"buttons": [
|
|
189
|
+
{
|
|
190
|
+
"title": "Xem đơn hàng",
|
|
191
|
+
"type": "oa.open.url",
|
|
192
|
+
"payload": { "url": "https://example.com/orders" }
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"title": "Gọi hỗ trợ",
|
|
196
|
+
"type": "oa.open.phone",
|
|
197
|
+
"payload": { "phone_code": "0901234567" }
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
"title": "Theo dõi vận chuyển",
|
|
201
|
+
"type": "oa.query.show",
|
|
202
|
+
"payload": { "content": "TRACK_ORDER_12345" }
|
|
203
|
+
}
|
|
204
|
+
]
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Button types: `oa.open.url`, `oa.open.phone`, `oa.query.show` (postback), `oa.open.sms`.
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
### Type 7 — Transaction Message
|
|
216
|
+
|
|
217
|
+
Requires a pre-approved template from Zalo OA portal. Cannot send arbitrary content.
|
|
218
|
+
|
|
219
|
+
```json
|
|
220
|
+
{
|
|
221
|
+
"recipient": { "user_id": "4337842264521611405" },
|
|
222
|
+
"message": {
|
|
223
|
+
"attachment": {
|
|
224
|
+
"type": "template",
|
|
225
|
+
"payload": {
|
|
226
|
+
"template_type": "transaction_order",
|
|
227
|
+
"language": "VI",
|
|
228
|
+
"elements": [{
|
|
229
|
+
"attachment_id": "approved-template-id-from-zalo",
|
|
230
|
+
"type": "banner"
|
|
231
|
+
}],
|
|
232
|
+
"parameters": {
|
|
233
|
+
"order_id": "ORD-2026-001234",
|
|
234
|
+
"order_status": "Đã giao hàng",
|
|
235
|
+
"delivery_date": "15/03/2026",
|
|
236
|
+
"tracking_url": "https://example.com/track/ORD-2026-001234"
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Template must match an approved template ID. Parameter keys defined by the template.
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
### Type 8 — Promotion Message
|
|
249
|
+
|
|
250
|
+
Requires approved template + sufficient broadcast quota.
|
|
251
|
+
|
|
252
|
+
```json
|
|
253
|
+
{
|
|
254
|
+
"recipient": { "user_id": "4337842264521611405" },
|
|
255
|
+
"message": {
|
|
256
|
+
"attachment": {
|
|
257
|
+
"type": "template",
|
|
258
|
+
"payload": {
|
|
259
|
+
"template_type": "promotion",
|
|
260
|
+
"language": "VI",
|
|
261
|
+
"elements": [{
|
|
262
|
+
"attachment_id": "approved-promo-banner-id",
|
|
263
|
+
"type": "banner"
|
|
264
|
+
}],
|
|
265
|
+
"parameters": {
|
|
266
|
+
"coupon_code": "SALE30",
|
|
267
|
+
"discount": "30%",
|
|
268
|
+
"expiry": "31/03/2026"
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
## Step 3 — Long Text Chunking
|
|
279
|
+
|
|
280
|
+
Text limit is 2000 chars. Chunk before sending:
|
|
281
|
+
|
|
282
|
+
```typescript
|
|
283
|
+
function chunkMessage(text: string, limit = 2000): string[] {
|
|
284
|
+
if (text.length <= limit) return [text]
|
|
285
|
+
const chunks: string[] = []
|
|
286
|
+
let remaining = text
|
|
287
|
+
while (remaining.length > 0) {
|
|
288
|
+
if (remaining.length <= limit) { chunks.push(remaining); break }
|
|
289
|
+
let splitAt = remaining.lastIndexOf('\n', limit)
|
|
290
|
+
if (splitAt === -1) splitAt = remaining.lastIndexOf(' ', limit)
|
|
291
|
+
if (splitAt === -1) splitAt = limit
|
|
292
|
+
chunks.push(remaining.slice(0, splitAt))
|
|
293
|
+
remaining = remaining.slice(splitAt).trimStart()
|
|
294
|
+
}
|
|
295
|
+
return chunks
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// Send each chunk with delay to respect rate limits
|
|
299
|
+
for (const chunk of chunkMessage(longText)) {
|
|
300
|
+
await sendTextMessage(userId, chunk)
|
|
301
|
+
await new Promise(r => setTimeout(r, 300))
|
|
302
|
+
}
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
307
|
+
## Step 4 — Follower Management
|
|
308
|
+
|
|
309
|
+
### List Followers
|
|
310
|
+
|
|
311
|
+
```http
|
|
312
|
+
GET https://openapi.zalo.me/v3.0/oa/user/getlist?offset=0&count=50
|
|
313
|
+
Authorization: Bearer {oa_access_token}
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
```json
|
|
317
|
+
{
|
|
318
|
+
"error": 0,
|
|
319
|
+
"data": {
|
|
320
|
+
"users": [
|
|
321
|
+
{ "user_id": "4337842264521611405", "display_name": "Nguyen Van A", "followed_date": 1709827200 }
|
|
322
|
+
],
|
|
323
|
+
"total": 1250,
|
|
324
|
+
"offset": 0,
|
|
325
|
+
"count": 50
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
Paginate: increment `offset` by `count` until `offset >= total`.
|
|
331
|
+
|
|
332
|
+
### User Profile
|
|
333
|
+
|
|
334
|
+
```http
|
|
335
|
+
GET https://openapi.zalo.me/v3.0/oa/user/detail?user_id=4337842264521611405
|
|
336
|
+
Authorization: Bearer {oa_access_token}
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
```json
|
|
340
|
+
{
|
|
341
|
+
"error": 0,
|
|
342
|
+
"data": {
|
|
343
|
+
"user_id": "4337842264521611405",
|
|
344
|
+
"display_name": "Nguyen Van A",
|
|
345
|
+
"birth_date": 0,
|
|
346
|
+
"gender": 1,
|
|
347
|
+
"phone": "",
|
|
348
|
+
"city": "Ho Chi Minh City",
|
|
349
|
+
"district": "",
|
|
350
|
+
"tags_and_notes_info": { "tag_names": ["VIP", "Repeat-buyer"] }
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
Note: `user_id` is OA-scoped — same person has a different `user_id` for each OA they follow.
|
|
356
|
+
|
|
357
|
+
### Tag Management
|
|
358
|
+
|
|
359
|
+
```http
|
|
360
|
+
POST https://openapi.zalo.me/v3.0/oa/tag/tagfollower
|
|
361
|
+
Authorization: Bearer {oa_access_token}
|
|
362
|
+
|
|
363
|
+
{ "user_id": "4337842264521611405", "tag_name": "VIP" }
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
```http
|
|
367
|
+
POST https://openapi.zalo.me/v3.0/oa/tag/rmfollowerfromtag
|
|
368
|
+
Authorization: Bearer {oa_access_token}
|
|
369
|
+
|
|
370
|
+
{ "user_id": "4337842264521611405", "tag_name": "VIP" }
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
---
|
|
374
|
+
|
|
375
|
+
## Step 5 — Broadcast
|
|
376
|
+
|
|
377
|
+
```http
|
|
378
|
+
POST https://openapi.zalo.me/v3.0/oa/message/promotion
|
|
379
|
+
Authorization: Bearer {oa_access_token}
|
|
380
|
+
|
|
381
|
+
{
|
|
382
|
+
"recipient": {
|
|
383
|
+
"target": {
|
|
384
|
+
"gender": 1,
|
|
385
|
+
"ages": ["18-25", "26-35"],
|
|
386
|
+
"cities": ["Ho Chi Minh City", "Ha Noi"],
|
|
387
|
+
"platforms": ["iOS", "Android"],
|
|
388
|
+
"telcos": ["Viettel", "Mobifone"]
|
|
389
|
+
}
|
|
390
|
+
},
|
|
391
|
+
"message": {
|
|
392
|
+
"attachment": {
|
|
393
|
+
"type": "template",
|
|
394
|
+
"payload": {
|
|
395
|
+
"template_type": "promotion",
|
|
396
|
+
"language": "VI",
|
|
397
|
+
"elements": [{ "attachment_id": "approved-promo-banner-id", "type": "banner" }],
|
|
398
|
+
"parameters": { "coupon_code": "SUMMER30", "discount": "30%" }
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
Response includes estimated reach count before send is confirmed. Quota resets monthly.
|
|
406
|
+
|
|
407
|
+
---
|
|
408
|
+
|
|
409
|
+
## Sharp Edges
|
|
410
|
+
|
|
411
|
+
- **7-day CS window** — `error: 12` means the user hasn't interacted in 7 days. Cannot bypass. Solution: use Transaction or Promotion templates (pre-approved) which ignore the window.
|
|
412
|
+
- **Version mismatch is intentional** — upload endpoints stay on `v2.0`, message send is `v3.0`. Do not "fix" this.
|
|
413
|
+
- **OA-scoped user_id** — never assume the same physical person has the same `user_id` across different OAs. Always store per-OA.
|
|
414
|
+
- **Template approval lag** — Transaction/Promotion templates take 1-5 business days to approve. Plan ahead; cannot substitute with CS messages after approval delay.
|
|
415
|
+
- **Image 1MB / File 5MB hard limits** — compress images server-side before upload. Zalo returns `error: 201` for oversized files.
|
|
416
|
+
- **Broadcast quota** — based on follower count × OA verification tier. Track monthly usage; `error: 133` = quota exceeded.
|
|
417
|
+
- **Button limit 5** — template messages silently drop buttons beyond index 4. Always validate `buttons.length <= 5` before sending.
|
|
418
|
+
|
|
419
|
+
## Error Codes Quick Reference
|
|
420
|
+
|
|
421
|
+
| Code | Meaning | Fix |
|
|
422
|
+
|------|---------|-----|
|
|
423
|
+
| 0 | Success | — |
|
|
424
|
+
| 12 | Outside 7-day CS window | Use approved template type |
|
|
425
|
+
| 14 | Invalid access token | Refresh token, retry |
|
|
426
|
+
| 107 | Invalid recipient | Verify user_id is OA-scoped and valid |
|
|
427
|
+
| 133 | Broadcast quota exceeded | Wait for monthly reset |
|
|
428
|
+
| 201 | File size exceeded | Compress/split before upload |
|
|
429
|
+
| 216 | Template not approved | Submit template for Zalo review |
|