openclaw-zalo-mod 2.29.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.
Files changed (37) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +295 -0
  3. package/README.vi.md +306 -0
  4. package/bvbank.jpg +0 -0
  5. package/dashboard.css +5954 -0
  6. package/dashboard.js +7392 -0
  7. package/index.html +1212 -0
  8. package/index.js +7558 -0
  9. package/logo.png +0 -0
  10. package/openclaw.plugin.json +96 -0
  11. package/package.json +85 -0
  12. package/skills/zalo-mod-control/SKILL.md +236 -0
  13. package/src/agent/commands.js +224 -0
  14. package/src/agent/connect-actions.js +160 -0
  15. package/src/agent/skill-content.js +327 -0
  16. package/src/agent/tool-surface.js +990 -0
  17. package/src/context/context-selector.js +72 -0
  18. package/src/context/conversation-buffer.js +120 -0
  19. package/src/context/prompt-injector.js +91 -0
  20. package/src/context/turn-context.js +142 -0
  21. package/src/crm/crm-api.js +121 -0
  22. package/src/crm/crm-store.js +1023 -0
  23. package/src/crm/task-reconcile.js +169 -0
  24. package/src/crm/zalo-people.js +191 -0
  25. package/src/integration/openclaw-adapter.js +235 -0
  26. package/src/integration/owner-claim.js +11 -0
  27. package/src/integration/zalo-connect-bridge.js +335 -0
  28. package/src/integration/zalo-mod-engine.js +379 -0
  29. package/src/integration/zca-facade.js +204 -0
  30. package/src/licensing/entitlements.js +96 -0
  31. package/src/messaging/conversation-queue.js +110 -0
  32. package/src/messaging/mention-builder.js +83 -0
  33. package/src/messaging/reply-mention-correlator.js +104 -0
  34. package/src/messaging/reply-router.js +182 -0
  35. package/src/storage/database.js +178 -0
  36. package/src/storage/migrations.js +314 -0
  37. package/upgrade/plans.json +80 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 tuanminhole
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,295 @@
1
+ # 🛡️ openclaw-zalo-mod — Zero-Token Zalo Group Moderation
2
+
3
+ > OpenClaw runtime plugin dành cho quản trị nhóm Zalo. Xử lý kiểm duyệt, slash commands, anti-spam với **0 token LLM**. Chỉ có tin nhắn `@mention` mới được chuyển lên AI agent.
4
+
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![OpenClaw Plugin](https://img.shields.io/badge/OpenClaw-Plugin-blue.svg)](https://openclaw.ai)
7
+ [![Version](https://img.shields.io/badge/version-2.29.0-green.svg)](./CHANGELOG.md)
8
+
9
+ **[🇺🇸 English](./README.md)**
10
+
11
+ ---
12
+
13
+ <div align="center">
14
+ <a href="https://www.youtube.com/watch?v=hPusYX-5Pmw">
15
+ <img src="https://img.youtube.com/vi/hPusYX-5Pmw/maxresdefault.jpg" alt="Watch the OpenClaw and Zalo video guide" width="820" />
16
+ </a>
17
+ <br />
18
+ <strong>▶ Watch the OpenClaw + Zalo video guide on YouTube</strong>
19
+ </div>
20
+
21
+ ---
22
+
23
+ ## ✨ Tính năng
24
+
25
+ | Tính năng | Token | Mô tả |
26
+ | ------------------------ | ----- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
27
+ | **Zalo Owner Dashboard** | 0 | Stunning graphical UI Dashboard (Premium Glassmorphism), manage groups, approve pending members, and compose direct messages via real ZCA API! |
28
+ | **Chat workspace** | 0 | Read and reply to Zalo threads inside the dashboard: conversation list, two-way message thread, composer, typing indicator |
29
+ | **Chat history sync** | 0 | Pulls older Zalo messages (groups *and* DMs) into `context.db` so the chat workspace does not start empty |
30
+ | **CRM Contacts** | 0 | Friends and not-yet-friend customers in one page: phone, gender, birthday, shared groups, scoped per bot |
31
+ | **Zalo labels** | 0 | Syncs the classification labels you already set in the Zalo app (colors preserved), filter and bulk-tag by them |
32
+ | **CSV import / export** | 0 | Round-trip contacts through Excel, de-duplicating by phone → name+birthday → name |
33
+ | **AI assistant column** | LLM | Draft · Summarize · Suggest · Analyze scoped to the open conversation (runs only when clicked) |
34
+ | **Slash Commands** | 0 | `/noi-quy`, `/menu`, `/huong-dan`, `/groupid`, `/ownerid`, `/report`, `/rules` |
35
+ | **Warn System** | 0 | `/warn @name [reason]` — member violation tracker |
36
+ | **Anti-Spam** | 0 | Detect repeated messages, suspicious links, emoji floods |
37
+ | **Admin Notes** | 0 | `/note [text]` — quick admin annotations |
38
+ | **Memory Sync** | 0 | `/memory` — saves context digest in `skills/memory/` |
39
+ | **Smart Q&A** | 0 | Native retrieval: "who is warned?", "spam log?" via local data |
40
+ | **ZCA Admin Sync** | 0 | Synchronizes `creatorId` & `adminIds` from Zalo API |
41
+ | **Owner DM** | 0 | Administrative command control panel over private DM |
42
+
43
+ ---
44
+
45
+ ## 🖥️ Zalo Owner Dashboard (UI)
46
+
47
+ The plugin features a built-in administrative graphical user interface **Zalo Owner Dashboard** crafted under **Premium Glassmorphism & High-Density Studio v1.5** design guidelines.
48
+
49
+ - **Access URL:** `http://127.0.0.1:19790` (the plugin's own default) or your server IP on port `19790`.
50
+
51
+ > ⚠️ **Installed through OpenClaw Setup? The port is different.** Setup writes
52
+ > `dashboardPort = gateway port + 1` so every project gets its own dashboard — gateway `18789` →
53
+ > dashboard **`18790`**. When in doubt, read `plugins.entries["zalo-mod"].config.dashboardPort` from
54
+ > `openclaw.json`, or click **Open** on the `openclaw-zalo-mod` card in Setup (that button derives the
55
+ > right port). On a VPS you also have to forward that port over an SSH tunnel — the dashboard listens
56
+ > on loopback only.
57
+ - **Configuration inside `openclaw.json`:**
58
+ ```json
59
+ "dashboardEnabled": true,
60
+ "dashboardHost": "127.0.0.1",
61
+ "dashboardPort": 19790
62
+ ```
63
+
64
+ ### Key Modules:
65
+
66
+ 1. **📊 Operations Overview**: Live monitoring of group statistics, pending member requests, and operational audit logs.
67
+ 2. **👥 Group Management**: Configure Silent Mode, Welcome messages, view invite links, and track group administrators.
68
+ 3. **⏳ Member Approvals**: Quickly accept pending group membership requests and watch flagged members.
69
+ 4. **✍️ Message Composer**: Write and dispatch raw text or image announcements directly to chosen groups with immediate preview.
70
+ 5. **💬 Chat workspace**: A three-column, Zalo-Web-style view — conversation list (filtered per bot), two-way message thread with a *typing* indicator, and an AI assistant column (Draft · Summarize · Suggest · Analyze). The composer is enabled for DMs only; groups point you to the bulk-send page.
71
+ 6. **🗂️ Contacts (CRM)**: Friends and not-yet-friend customers in one page — phone, gender, birthday, shared groups, colored Zalo labels. Filter by label / type / upcoming birthday, bulk-select to tag or delete, import and export CSV.
72
+ 7. **🔌 API Directory**: Inspect fully documented ZCA JavaScript APIs with real integration examples.
73
+
74
+ > **Data is scoped per bot.** Each Zalo account is its own mailbox, so the chat workspace and the
75
+ > Contacts page always filter by the selected bot. "All bots" mode merges duplicate *people* (Zalo
76
+ > issues a different uid per account for the same person) but never merges conversations.
77
+
78
+ ---
79
+
80
+ ### Feature tiers
81
+
82
+ Every first installation automatically receives a **30-day Pro trial**. The license server signs and binds the trial to the Device ID, so no manual key is required.
83
+
84
+ | Plan | View dashboard | Single group/member actions | Multi-group / bulk / `all` | Multi-bot actions |
85
+ | --- | --- | --- | --- | --- |
86
+ | Free | ✅ | ✅ | ❌ | ❌ |
87
+ | Pro | ✅ | ✅ | ✅ | ❌ |
88
+ | Team / Lifetime | ✅ | ✅ | ✅ | ✅ |
89
+
90
+ After the trial, every page remains readable and all single-item actions continue to work.
91
+
92
+ ---
93
+
94
+ ## 🏗️ Kiến trúc
95
+
96
+ ```
97
+ Tin nhắn Zalo đến
98
+ │ OpenClaw Zalo Connect owns the connection and inbound gate
99
+ ├─ Mute → drop before pipeline/model (0 tokens)
100
+ ├─ Silent, no mention → drop before pipeline/model (0 tokens)
101
+ └─ Allowed message → Zalo Mod commands/policy/context
102
+ ├─ local command, anti-spam (0 tokens)
103
+ └─ agent reply → tag triggering sender
104
+ → Zalo Connect native mention
105
+
106
+ Chat workspace + CRM (dashboard)
107
+ │ Zalo Connect publishes 3 bridge channels: inbound · history · typing
108
+ ├─ inbound + history → written to `context.db`, keyed per Zalo account
109
+ ├─ typing → kept in RAM only, expires after 3s
110
+ └─ dashboard polls a ~68-byte fingerprint every 2s to detect changes
111
+ ```
112
+
113
+ OpenClaw Zalo Connect is the only Zalo channel/runtime used in production. Zalo Mod
114
+ does not log in separately, patch private `dist` files, or own a second transport.
115
+ Internal architecture and bridge notes live in the ignored `docs_dev/`
116
+ directory and are intentionally not included in public releases.
117
+
118
+ ---
119
+
120
+ ## 🔐 Data & security
121
+
122
+ The published package is intentionally auditable and ships readable source code.
123
+
124
+ - **Local data:** reads OpenClaw configuration plus Zalo Mod state under the local OpenClaw project; writes only plugin settings, audit records, memory/history, and a random persistent 16-character installation ID.
125
+ - **Chat history and contacts:** the chat workspace and CRM store messages and contact details in `context.db` **inside your own OpenClaw project** — the same machine the bot already runs on. Nothing is uploaded; the license server never receives them. Delete the file and the data is gone. Typing indicators are never written to disk at all.
126
+ - **Zalo access:** uses the locally installed OpenClaw Zalo Connect bridge. Zalo Mod does not collect Zalo login cookies or create a second Zalo session.
127
+ - **License service:** sends the random installation ID and license/order state only to `https://zalo-mod-server.monkeytech.io.vn` to issue the 30-day trial, activate purchases, and refresh signed entitlements. It does not send hostname, hardware identifiers, browser cookies, chat history, or Zalo credentials.
128
+ - **AI summaries:** only when a summary feature is used, the relevant text is sent to the 9Router/OpenAI-compatible endpoint already configured by the OpenClaw owner. No hidden endpoint is used.
129
+ - **Dashboard:** listens on `127.0.0.1` by default. In Docker it listens on the container interface so a host-side `127.0.0.1:PORT:PORT` mapping can reach it; OpenClaw Setup creates that localhost-only mapping automatically. An explicitly configured non-loopback `dashboardHost` still requires a `dashboardToken` of at least 24 characters.
130
+ - **Removed scope:** this package contains no Facebook crawler and never reads, stores, or forwards Facebook/browser cookies.
131
+ - **Telemetry:** the plugin has no analytics or background telemetry.
132
+
133
+ ---
134
+
135
+ ## 📦 Cài đặt
136
+
137
+ ### 1. Docker (khuyến nghị — dùng với openclaw-setup)
138
+
139
+ ```powershell
140
+ # Install the pinned OpenClaw Zalo Connect release first, then Zalo Mod
141
+ docker exec openclaw-bot openclaw plugins install "https://github.com/tuanminhhole/openclaw-zalo-connect.git#v3.0.0"
142
+ docker exec openclaw-bot openclaw plugins install clawhub:openclaw-zalo-mod --force
143
+ docker restart openclaw-bot
144
+ ```
145
+
146
+ ### 2. Native (không Docker)
147
+
148
+ ```bash
149
+ openclaw plugins install "https://github.com/tuanminhhole/openclaw-zalo-connect.git#v3.0.0"
150
+ openclaw plugins install openclaw-zalo-mod
151
+ openclaw gateway restart
152
+ ```
153
+
154
+ ### 3. Cài thủ công từ source
155
+
156
+ ```powershell
157
+ # Copy source vào thư mục extensions
158
+ xcopy /E /I openclaw-zalo-mod "%OPENCLAW_HOME%\extensions\zalo-mod"
159
+
160
+ # Hoặc trên Linux
161
+ cp -r openclaw-zalo-mod ~/.openclaw/extensions/zalo-mod
162
+
163
+ # Restart gateway
164
+ openclaw gateway restart
165
+ ```
166
+
167
+ ### 4. Patch nhanh khi phát triển (Docker)
168
+
169
+ ```powershell
170
+ # Copy file đã sửa vào container
171
+ Copy-Item -Path "D:\openclaw-zalo-mod\index.js" -Destination "E:\final\.openclaw\extensions\zalo-mod\index.js" -Force
172
+
173
+ # Fix quyền (Windows bind mount tạo quyền 777)
174
+ docker exec openclaw-bot chmod 644 /root/project/.openclaw/extensions/zalo-mod/index.js
175
+
176
+ # Restart
177
+ docker restart openclaw-bot
178
+ ```
179
+
180
+ > ⚠️ **Lưu ý quyền file:** Windows bind mounts tạo file với quyền `0777`. OpenClaw sẽ từ chối load plugin có quyền world-writable. Luôn chạy `chmod 644` sau khi copy.
181
+
182
+ ---
183
+
184
+ ## ⚙️ Cấu hình ban đầu
185
+
186
+ ### Bước 1: Xác nhận bot đã load plugin
187
+
188
+ Kiểm tra log sau khi restart:
189
+
190
+ ```
191
+ [gateway] ... plugins: ..., zalo-connect, zalo-mod, ...
192
+ [openclaw-zalo-mod] bridge backend: zalo-connect-service connected=true
193
+ [openclaw-zalo-mod] live group policy replayed: N/N
194
+ ```
195
+
196
+ Plugin phải xuất hiện trong danh sách. Nếu thiếu, kiểm tra quyền file.
197
+
198
+ ### Bước 2: Nhận quyền Owner
199
+
200
+ Mở **Zalo Mod Dashboard → Cài đặt**, copy **Device ID**, rồi gửi DM riêng cho bot:
201
+
202
+ ```
203
+ i'm owner <DEVICE_ID>
204
+ ```
205
+
206
+ Device ID chứng minh bạn có quyền truy cập máy chủ, tránh người lạ tự nhận Owner. Chỉ cần xác nhận một lần; bot sẽ ghi `ownerId` vào config và khóa quyền sở hữu.
207
+
208
+ ### Bước 3: Đăng ký Group
209
+
210
+ Vào group cần quản lý, gửi lệnh:
211
+
212
+ ```
213
+ /bot-rules groupid
214
+ ```
215
+
216
+ Bot sẽ quét session, lấy `creatorId` + `adminIds` từ Zalo API, rồi tự ghi vào config.
217
+
218
+ ---
219
+
220
+ ## 📋 Danh sách lệnh đầy đủ
221
+
222
+ ### 👤 Mọi người (trong group)
223
+
224
+ | Lệnh | Mô tả |
225
+ | ---------------------- | --------------------- |
226
+ | `/{botname}-noi-quy` | Xem nội quy nhóm |
227
+ | `/{botname}-menu` | Danh sách lệnh |
228
+ | `/{botname}-huong-dan` | Hướng dẫn sử dụng bot |
229
+ | `/{botname}-report` | Báo cáo vi phạm |
230
+
231
+ ### 🔧 Admin (trong group)
232
+
233
+ | Lệnh | Mô tả |
234
+ | ------------------------------- | ----------------- |
235
+ | `/{botname}-mute` | Tắt bot hoàn toàn |
236
+ | `/{botname}-unmute` | Bật lại bot |
237
+ | `/{botname}-warn @name [lý do]` | Cảnh cáo member |
238
+ | `/{botname}-note [text]` | Ghi chú admin |
239
+ | `/{botname}-memory [note]` | Lưu memory digest |
240
+
241
+ ### 👑 Owner — trong group
242
+
243
+ | Lệnh | Mô tả |
244
+ | ---------------------------- | ------------------------------------------ |
245
+ | `/bot-rules` | Xem panel sub-lệnh |
246
+ | `/bot-rules status` | Cấu hình group hiện tại |
247
+ | `/bot-rules groupid` | Thêm group + lấy adminIds/creatorId từ ZCA |
248
+ | `/bot-rules silent-on/off` | Bật/tắt silent mode |
249
+ | `/bot-rules welcome-on/off` | Bật/tắt chào member mới |
250
+ | `/bot-rules tracking-on/off` | Bật/tắt ghi lịch sử |
251
+
252
+ ### 🔐 Owner — qua DM riêng
253
+
254
+ | Lệnh | Mô tả |
255
+ | -------------------------------------- | ------------------------ |
256
+ | `/bot-rules mute <groupId> on/off` | Mute/unmute group cụ thể |
257
+ | `/bot-rules mute all on/off` | Mute/unmute tất cả |
258
+ | `/bot-rules silent <groupId> on/off` | Silent group cụ thể |
259
+ | `/bot-rules welcome <groupId> on/off` | Welcome group cụ thể |
260
+ | `/bot-rules tracking <groupId> on/off` | Tracking group cụ thể |
261
+ | `/bot-rules dm-add <userId>` | Thêm vào DM whitelist |
262
+ | `/bot-rules groupid-list` | Danh sách tất cả groups |
263
+ | `/bot-ownerid` | Xem owner ID hiện tại |
264
+
265
+ ---
266
+
267
+ ## 🛑 Anti-Spam
268
+
269
+ | Loại | Phát hiện |
270
+ | --------------- | ---------------------------------------------- |
271
+ | **Repeat Spam** | Cùng tin nhắn gửi N lần trong khoảng thời gian |
272
+ | **Link Spam** | URL rút gọn hoặc link affiliate đáng ngờ |
273
+ | **Emoji Flood** | 5+ emoji liên tiếp |
274
+
275
+ Cấu hình trong `openclaw.json`:
276
+
277
+ ```json
278
+ "spamRepeatN": 3,
279
+ "spamWindowSeconds": 300
280
+ ```
281
+
282
+ ---
283
+
284
+ ## 🔧 Yêu cầu
285
+
286
+ - OpenClaw `>= 2026.5.7`
287
+ - Plugin/channel `zalo-connect` is configured and authenticated
288
+ - OpenClaw Zalo Connect bridge service v2 (including live group policy)
289
+ - Node.js `>= 22`
290
+
291
+ ---
292
+
293
+ ## 📄 License
294
+
295
+ MIT — see [LICENSE](./LICENSE)
package/README.vi.md ADDED
@@ -0,0 +1,306 @@
1
+ # 🛡️ openclaw-zalo-mod — Quản Trị Nhóm Zalo Zero-Token
2
+
3
+ > Plugin OpenClaw dành cho quản trị nhóm Zalo. Xử lý kiểm duyệt, slash commands, anti-spam với **0 token LLM**. Chỉ tin nhắn `@mention` được chuyển lên AI agent.
4
+
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![OpenClaw Plugin](https://img.shields.io/badge/OpenClaw-Plugin-blue.svg)](https://openclaw.ai)
7
+ [![Version](https://img.shields.io/badge/version-2.29.0-green.svg)](./CHANGELOG.md)
8
+
9
+ **[🇺🇸 English](./README.md)**
10
+
11
+ ---
12
+
13
+ <div align="center">
14
+ <a href="https://www.youtube.com/watch?v=hPusYX-5Pmw">
15
+ <img src="https://img.youtube.com/vi/hPusYX-5Pmw/maxresdefault.jpg" alt="Xem video hướng dẫn OpenClaw và Zalo" width="820" />
16
+ </a>
17
+ <br />
18
+ <strong>▶ Xem video hướng dẫn OpenClaw + Zalo trên YouTube</strong>
19
+ </div>
20
+
21
+ ---
22
+
23
+ ## ✨ Tính năng
24
+
25
+ | Tính năng | Token | Mô tả |
26
+ | --------- | ----- | ----- |
27
+ | **Zalo Owner Dashboard** | 0 | UI Dashboard đồ họa tuyệt đẹp (Premium Glassmorphism), quản lý group, duyệt member, soạn gửi tin nhắn trực tiếp qua ZCA API! |
28
+ | **Khung chat** | 0 | Đọc và trả lời tin nhắn Zalo ngay trong dashboard: danh sách hội thoại, luồng tin hai chiều, ô soạn tin, chỉ báo "đang soạn tin" |
29
+ | **Lịch sử chat** | 0 | Kéo tin cũ từ Zalo về `context.db` (cả nhóm lẫn tin riêng) để khung chat không bắt đầu từ con số 0 |
30
+ | **CRM Liên hệ** | 0 | Bạn bè + khách hàng chưa kết bạn trong một trang: SĐT, giới tính, sinh nhật, nhóm chung, tách theo từng bot |
31
+ | **Nhãn Zalo** | 0 | Đồng bộ nhãn phân loại đã gán sẵn trên app Zalo (giữ nguyên màu), lọc và gắn nhãn hàng loạt |
32
+ | **Nhập / tải CSV** | 0 | Đưa danh sách liên hệ ra Excel và nạp ngược lại, tự gộp trùng theo SĐT → tên+ngày sinh → tên |
33
+ | **Trợ lý AI trong chat** | LLM | Soạn hộ · Tóm tắt · Gợi ý · Phân tích cho đúng hội thoại đang mở (chỉ chạy khi bấm) |
34
+ | **Slash Commands** | 0 | `/[botname]-noi-quy`, `/[botname]-menu`, `/[botname]-huong-dan`, v.v. |
35
+ | **Warn System** | 0 | `/[botname]-warn @name [lý do]` — theo dõi vi phạm theo member |
36
+ | **Anti-Spam** | 0 | Tự phát hiện tin nhắn lặp, spam link, emoji flood |
37
+ | **Admin Notes** | 0 | `/[botname]-note [text]` — ghi chú admin |
38
+ | **Memory Sync** | 0 | `/[botname]-memory` — lưu digest vào `skills/memory/` |
39
+ | **Smart Q&A** | 0 | Tự trả lời "ai bị warn?", "vi phạm?" từ dữ liệu local |
40
+ | **ZCA Admin Sync** | 0 | Tự động lấy `creatorId` + `adminIds` từ Zalo API |
41
+ | **Owner DM** | 0 | Nhận lệnh quản trị qua DM riêng với bot |
42
+
43
+ > **Lưu ý về prefix lệnh:** Tất cả lệnh dùng prefix `/{tên-bot}-`. Ví dụ nếu bot tên `Williams` thì lệnh là `/williams-menu`, `/williams-noi-quy`, v.v.
44
+
45
+ ---
46
+
47
+ ## 🖥️ Zalo Owner Dashboard (UI)
48
+
49
+ Plugin tích hợp sẵn giao diện quản trị đồ họa **Zalo Owner Dashboard** được thiết kế theo chuẩn **Premium Glassmorphism & High-Density Studio v1.5** siêu sang trọng.
50
+
51
+ - **Cách truy cập:** `http://127.0.0.1:19790` (mặc định của plugin) hoặc IP máy chủ của bạn trên cổng `19790`.
52
+
53
+ > ⚠️ **Cài qua OpenClaw Setup thì cổng KHÁC.** Setup tự ghi `dashboardPort = cổng gateway + 1` để mỗi
54
+ > project có dashboard riêng — gateway `18789` → dashboard **`18790`**. Không chắc thì mở
55
+ > `openclaw.json` xem `plugins.entries["zalo-mod"].config.dashboardPort`, hoặc bấm **Mở web** trên
56
+ > card `openclaw-zalo-mod` trong Setup (nút đó tự suy ra cổng đúng). Trên VPS còn phải forward cổng
57
+ > đó qua SSH tunnel vì dashboard chỉ nghe trên loopback.
58
+ - **Cấu hình trong `openclaw.json`:**
59
+ ```json
60
+ "dashboardEnabled": true,
61
+ "dashboardHost": "127.0.0.1",
62
+ "dashboardPort": 19790
63
+ ```
64
+
65
+ ### Các phân hệ chính trên Dashboard:
66
+
67
+ 1. **📊 Tổng quan vận hành**: Xem nhanh số lượng nhóm, member chờ duyệt, logs hoạt động theo thời gian thực.
68
+ 2. **👥 Quản lý Nhóm**: Cấu hình chế độ Silent Mode, Welcome message, xem link mời nhóm, xem danh sách Admin từng nhóm.
69
+ 3. **⏳ Thành viên & Duyệt**: Duyệt nhanh thành viên xin vào nhóm, theo dõi member vi phạm/cảnh cáo.
70
+ 4. **✍️ Gửi tin nhắn (Composer)**: Soạn thảo tin nhắn và gửi trực tiếp đến các nhóm nhanh chóng, hỗ trợ preview hình ảnh trước khi gửi.
71
+ 5. **💬 Khung chat**: Ba cột kiểu Zalo Web — danh sách hội thoại (lọc theo bot), luồng tin hai chiều kèm chỉ báo *đang soạn tin*, và cột trợ lý AI (Soạn hộ · Tóm tắt · Gợi ý · Phân tích). Ô soạn tin chỉ mở ở tin nhắn riêng; nhóm chuyển sang trang Gửi hàng loạt.
72
+ 6. **🗂️ Liên hệ (CRM)**: Bạn bè và khách hàng chưa kết bạn chung một trang — SĐT, giới tính, sinh nhật, nhóm chung, nhãn Zalo có màu. Lọc theo nhãn / loại / sinh nhật sắp tới, chọn hàng loạt để gắn nhãn hoặc xoá, nhập-tải CSV.
73
+ 7. **🔌 Danh mục API**: Tra cứu toàn bộ các ZCA API khả dụng và các ví dụ thực tế.
74
+
75
+ > **Dữ liệu tách theo từng bot.** Mỗi tài khoản Zalo là một hộp thư riêng, nên khung chat và trang
76
+ > Liên hệ luôn lọc theo bot đang chọn. Chế độ "tất cả bot" có gộp trùng người (Zalo cấp uid khác
77
+ > nhau cho cùng một người ở hai tài khoản) nhưng **không** trộn hội thoại.
78
+
79
+ ---
80
+
81
+ ### Gói tính năng
82
+
83
+ Mỗi bản cài mới được tự động dùng thử **Pro trong 30 ngày**. Trial được license server ký và gắn với Device ID, không cần nhập key.
84
+
85
+ | Gói | Xem dashboard | Thao tác từng group/member | Nhiều group / hàng loạt / `all` | Nhiều bot cùng lúc |
86
+ | --- | --- | --- | --- | --- |
87
+ | Free | ✅ | ✅ | ❌ | ❌ |
88
+ | Pro | ✅ | ✅ | ✅ | ❌ |
89
+ | Team / Lifetime | ✅ | ✅ | ✅ | ✅ |
90
+
91
+ Hết trial, dashboard và mọi dữ liệu vẫn xem được; các thao tác đơn vẫn hoạt động bình thường.
92
+
93
+ ---
94
+
95
+ ## 🏗️ Kiến trúc
96
+
97
+ ```
98
+ Tin nhắn Zalo đến
99
+ │ OpenClaw Zalo Connect sở hữu kết nối Zalo + inbound gate
100
+ ├─ Mute → chặn trước pipeline/model (0 token)
101
+ ├─ Silent, không tag → chặn trước pipeline/model (0 token)
102
+ └─ Tin được phép → Zalo Mod xử lý lệnh/policy/context
103
+ ├─ lệnh local, anti-spam (0 token)
104
+ └─ agent reply → tự tag đúng người gửi
105
+ → Zalo Connect gửi mention native
106
+
107
+ Khung chat + CRM (dashboard)
108
+ │ Zalo Connect phát 3 kênh riêng qua bridge: inbound · lịch sử · đang-soạn-tin
109
+ ├─ inbound + lịch sử → ghi vào `context.db` (theo từng tài khoản Zalo)
110
+ ├─ đang-soạn-tin → giữ trong RAM, hết 3 giây là bỏ
111
+ └─ dashboard poll một dấu-vân-tay ~68 byte mỗi 2s để biết có gì mới
112
+ ```
113
+
114
+ OpenClaw Zalo Connect là channel/runtime Zalo duy nhất trong production. Zalo Mod
115
+ không đăng nhập Zalo riêng, không patch private `dist`, và không sở hữu transport thứ hai.
116
+ Kiến trúc kỹ thuật và bridge contract nằm trong thư mục nội bộ `docs_dev/`,
117
+ được Git bỏ qua và không phát hành công khai.
118
+
119
+ ---
120
+
121
+ ## 🔐 Dữ liệu & bảo mật
122
+
123
+ Gói phát hành dùng mã nguồn rõ để người dùng và ClawHub có thể kiểm tra đầy đủ.
124
+
125
+ - **Dữ liệu local:** chỉ đọc cấu hình OpenClaw và dữ liệu Zalo Mod trong project; chỉ ghi thiết lập plugin, audit, memory/lịch sử và một mã cài đặt ngẫu nhiên 16 ký tự được lưu bền vững.
126
+ - **Lịch sử chat và liên hệ:** khung chat và CRM lưu tin nhắn cùng thông tin liên hệ vào `context.db` **nằm trong project OpenClaw của bạn** — chính máy đang chạy bot. Không có gì được tải lên, máy chủ bản quyền không hề nhận. Xoá file đó là mất sạch dữ liệu. Riêng chỉ báo "đang soạn tin" không bao giờ ghi xuống đĩa.
127
+ - **Kết nối Zalo:** dùng bridge của OpenClaw Zalo Connect đã cài trên cùng máy. Zalo Mod không thu thập cookie đăng nhập Zalo và không tạo phiên Zalo thứ hai.
128
+ - **Máy chủ bản quyền:** chỉ gửi mã cài đặt ngẫu nhiên cùng trạng thái license/order tới `https://zalo-mod-server.monkeytech.io.vn` để cấp 30 ngày Pro, kích hoạt đơn hàng và làm mới entitlement có chữ ký. Không gửi hostname, thông tin phần cứng, cookie trình duyệt, lịch sử chat hay thông tin đăng nhập Zalo.
129
+ - **Tóm tắt AI:** chỉ khi người dùng bật/chạy tính năng tóm tắt, phần text liên quan mới được gửi tới endpoint tương thích OpenAI/9Router mà chính Owner đã cấu hình trong OpenClaw; plugin không dùng endpoint bí mật khác.
130
+ - **Dashboard:** mặc định chỉ nghe tại `127.0.0.1`. Trong Docker, plugin nghe trên interface nội bộ của container để ánh xạ `127.0.0.1:PORT:PORT` phía máy chủ truy cập được; OpenClaw Setup tự tạo ánh xạ chỉ-localhost này. Nếu tự cấu hình `dashboardHost` ngoài localhost, plugin vẫn yêu cầu `dashboardToken` dài tối thiểu 24 ký tự.
131
+ - **Đã bỏ khỏi phạm vi:** gói không chứa Facebook Crawler và không đọc, lưu hay chuyển tiếp cookie Facebook/cookie trình duyệt.
132
+ - **Telemetry:** plugin không có analytics hoặc telemetry nền.
133
+
134
+ ---
135
+
136
+ ## 📦 Cài đặt
137
+
138
+ ### 1. Docker (khuyến nghị — dùng với openclaw-setup)
139
+
140
+ ```powershell
141
+ # Cài bản OpenClaw Zalo Connect đã ghim trước, sau đó cài Zalo Mod
142
+ docker exec openclaw-bot openclaw plugins install "https://github.com/tuanminhhole/openclaw-zalo-connect.git#v3.0.0"
143
+ docker exec openclaw-bot openclaw plugins install clawhub:openclaw-zalo-mod --force
144
+ docker restart openclaw-bot
145
+ ```
146
+
147
+ ### 2. Native (không Docker)
148
+
149
+ ```bash
150
+ openclaw plugins install "https://github.com/tuanminhhole/openclaw-zalo-connect.git#v3.0.0"
151
+ openclaw plugins install openclaw-zalo-mod
152
+ openclaw gateway restart
153
+ ```
154
+
155
+ ### 3. Cài thủ công từ source
156
+
157
+ ```powershell
158
+ # Copy source vào thư mục extensions
159
+ xcopy /E /I openclaw-zalo-mod "%OPENCLAW_HOME%\extensions\zalo-mod"
160
+
161
+ # Hoặc trên Linux
162
+ cp -r openclaw-zalo-mod ~/.openclaw/extensions/zalo-mod
163
+
164
+ # Restart gateway
165
+ openclaw gateway restart
166
+ ```
167
+
168
+ ### 4. Patch nhanh khi phát triển (Docker)
169
+
170
+ ```powershell
171
+ # Copy file đã sửa vào volume
172
+ Copy-Item -Path "D:\openclaw-zalo-mod\index.js" -Destination "E:\final\.openclaw\extensions\zalo-mod\index.js" -Force
173
+
174
+ # Fix quyền (Windows bind mount tạo quyền 777 — OpenClaw sẽ từ chối load)
175
+ docker exec openclaw-bot chmod 644 /root/project/.openclaw/extensions/zalo-mod/index.js
176
+
177
+ # Restart
178
+ docker restart openclaw-bot
179
+ ```
180
+
181
+ ---
182
+
183
+ ## ⚙️ Cấu hình ban đầu
184
+
185
+ ### Bước 1: Xác nhận plugin đã load
186
+
187
+ Kiểm tra log sau khi restart:
188
+
189
+ ```
190
+ [gateway] ... plugins: ..., zalo-connect, zalo-mod, ...
191
+ [openclaw-zalo-mod] bridge backend: zalo-connect-service connected=true
192
+ [openclaw-zalo-mod] live group policy replayed: N/N
193
+ [plugins] [openclaw-zalo-mod] loaded — bot="Williams" owner=... groups=N
194
+ ```
195
+
196
+ ### Bước 2: Nhận quyền Owner
197
+
198
+ Mở **Zalo Mod Dashboard → Cài đặt**, copy **Device ID**, rồi gửi DM riêng cho bot:
199
+
200
+ ```
201
+ i'm owner <DEVICE_ID>
202
+ ```
203
+
204
+ Device ID chứng minh bạn có quyền truy cập máy chủ, tránh người lạ tự nhận Owner. Chỉ cần xác nhận một lần; bot sẽ ghi `ownerId` vào config và khóa quyền sở hữu.
205
+
206
+ ### Bước 3: Đăng ký Group
207
+
208
+ Vào group cần quản lý, gửi lệnh (thay `botname` theo tên bot của bạn):
209
+
210
+ ```
211
+ /bot-rules groupid
212
+ ```
213
+
214
+ Bot sẽ quét session, lấy `creatorId` + `adminIds` từ Zalo API, rồi tự ghi vào config.
215
+
216
+ ---
217
+
218
+ ## 📋 Danh sách lệnh đầy đủ
219
+
220
+ > **Prefix lệnh:** `/{tên-bot}-` — ví dụ bot tên `Williams` → prefix là `/williams-`
221
+
222
+ ### 👤 Mọi người (trong group)
223
+
224
+ | Lệnh | Mô tả |
225
+ | ---------------------- | --------------------- |
226
+ | `/{botname}-noi-quy` | Xem nội quy nhóm |
227
+ | `/{botname}-menu` | Danh sách lệnh |
228
+ | `/{botname}-huong-dan` | Hướng dẫn sử dụng bot |
229
+ | `/{botname}-report` | Báo cáo vi phạm |
230
+
231
+ ### 🔧 Admin (trong group)
232
+
233
+ | Lệnh | Mô tả |
234
+ | ------------------------------- | ----------------- |
235
+ | `/{botname}-mute` | Tắt bot hoàn toàn |
236
+ | `/{botname}-unmute` | Bật lại bot |
237
+ | `/{botname}-warn @name [lý do]` | Cảnh cáo member |
238
+ | `/{botname}-note [text]` | Ghi chú admin |
239
+ | `/{botname}-memory [note]` | Lưu memory digest |
240
+
241
+ ### 👑 Owner — trong group
242
+
243
+ | Lệnh | Mô tả |
244
+ | ---------------------------- | ------------------------------------------ |
245
+ | `/bot-rules` | Xem panel sub-lệnh |
246
+ | `/bot-rules status` | Cấu hình group hiện tại |
247
+ | `/bot-rules groupid` | Thêm group + lấy adminIds/creatorId từ ZCA |
248
+ | `/bot-rules silent-on/off` | Bật/tắt silent mode |
249
+ | `/bot-rules welcome-on/off` | Bật/tắt chào member mới |
250
+ | `/bot-rules tracking-on/off` | Bật/tắt ghi lịch sử |
251
+
252
+ ### 🔐 Owner — qua DM riêng
253
+
254
+ | Lệnh | Mô tả |
255
+ | -------------------------------------- | ------------------------ |
256
+ | `/bot-rules mute <groupId> on/off` | Mute/unmute group cụ thể |
257
+ | `/bot-rules mute all on/off` | Mute/unmute tất cả |
258
+ | `/bot-rules silent <groupId> on/off` | Silent group cụ thể |
259
+ | `/bot-rules welcome <groupId> on/off` | Welcome group cụ thể |
260
+ | `/bot-rules tracking <groupId> on/off` | Tracking group cụ thể |
261
+ | `/bot-rules dm-add <userId>` | Thêm vào DM whitelist |
262
+ | `/bot-rules groupid-list` | Danh sách tất cả groups |
263
+ | `/bot-ownerid` | Xem owner ID hiện tại |
264
+
265
+ ---
266
+
267
+ ## 🛑 Anti-Spam
268
+
269
+ | Loại | Phát hiện |
270
+ | --------------- | ---------------------------------------------- |
271
+ | **Repeat Spam** | Cùng tin nhắn gửi N lần trong khoảng thời gian |
272
+ | **Link Spam** | URL rút gọn hoặc link affiliate đáng ngờ |
273
+ | **Emoji Flood** | 5+ emoji liên tiếp |
274
+
275
+ Cấu hình trong `openclaw.json`:
276
+
277
+ ```json
278
+ "spamRepeatN": 3,
279
+ "spamWindowSeconds": 300
280
+ ```
281
+
282
+ ---
283
+
284
+ ## 🔇 Mute vs Silent
285
+
286
+ | | Mute | Silent |
287
+ | -------------- | ---------------- | ------------------ |
288
+ | Bot im lặng | Hoàn toàn | Chỉ không tự reply |
289
+ | Slash commands | ❌ (chỉ /unmute) | ✅ |
290
+ | @mention | ❌ | ✅ |
291
+ | Welcome | ❌ | ✅ |
292
+
293
+ ---
294
+
295
+ ## 🔧 Yêu cầu
296
+
297
+ - OpenClaw `>= 2026.5.7`
298
+ - Plugin/channel `zalo-connect` đã được cấu hình và xác thực
299
+ - OpenClaw Zalo Connect bridge service v2 (có live group policy)
300
+ - Node.js `>= 22`
301
+
302
+ ---
303
+
304
+ ## 📄 License
305
+
306
+ MIT — see [LICENSE](./LICENSE)
package/bvbank.jpg ADDED
Binary file