QuotaCheap Playbook
OpenClaw Hooks: event-driven automation cho Gateway mà không biến prompt thành middleware
Hướng dẫn OpenClaw Hooks cho production: HOOK.md, handler.ts, event types, command/lifecycle/message hooks, internal hooks vs webhooks, plugin hooks và Quo…
Hooks là scripts chạy khi Gateway có event. Dùng đúng chỗ, chúng giúp operator tự động hóa lifecycle; dùng sai chỗ, chúng thành policy layer giả rất khó debug.
Playbook tiếng Việt về OpenClaw Hooks: internal hooks vs webhooks, khi dùng HOOK.md, khi dùng typed plugin hooks, event types, handler structure, event.messages, lifecycle constraints, Gateway startup/shutdown, security và QuotaCheap usage/cost visibility.
Có một kiểu automation rất dễ làm sai: bạn muốn “mỗi lần agent reset thì lưu snapshot”, “mỗi lần message gửi xong thì log lại”, “mỗi lần Gateway restart thì báo operator”, hoặc “trước compaction thì ghi telemetry”.
Nhiều builder sẽ nhét logic đó vào prompt.
Prompt không phải middleware.
Prompt là thứ model đọc và có thể hiểu lệch.
Nếu automation cần chạy theo event của Gateway, hãy dùng hook đúng nghĩa.
OpenClaw Hooks là scripts nhỏ chạy khi có event bên trong Gateway.
Chúng phù hợp với operator managed side effects và command/lifecycle automation.
Nhưng hooks cũng có ranh giới: nếu bạn cần block tool, rewrite prompt, cancel outbound message, hoặc làm ordered runtime policy, docs nói nên dùng typed plugin hooks qua api.on ...
thay vì internal hooks file based.
Bài này giải thích cách nghĩ production về OpenClaw Hooks: chọn đúng surface, event types, cấu trúc hook, handler, reply behavior, lifecycle constraints, security, và chỗ QuotaCheap nên đứng trong bức tranh automation.
Hooks là event driven automation trong Gateway OpenClaw docs định nghĩa hooks là scripts nhỏ chạy khi có thứ gì đó xảy ra bên trong Gateway.
Chúng có thể được discover từ directories và inspect bằng openclaw hooks.
Gateway chỉ load internal hooks sau khi bạn enable hooks hoặc configure ít nhất một hook entry, hook pack, legacy handler, hoặc extra hook directory.
Quick start từ docs: Điểm cần nhớ: hooks chạy ở lớp Gateway event, không phải model conversation.
Vì vậy chúng phù hợp để tự động hóa quanh runtime, không phải thay model suy nghĩ.
Internal hooks khác webhooks Docs phân biệt rõ: Internal hooks : chạy bên trong Gateway khi agent events fire, ví dụ /new, /reset, /stop, lifecycle events.
Webhooks : external HTTP endpoints cho hệ thống khác trigger work vào OpenClaw.
Đừng gọi mọi thứ là webhook cho sang.
Internal hook là reaction nội bộ của Gateway.
Webhook là cửa HTTP từ bên ngoài.
Ví dụ: User gõ /reset, bạn muốn lưu state trước/sau reset internal hook.
GitHub/Stripe/CRM gọi HTTP endpoint để kích hoạt agent webhook.
Scheduled job đánh thức agent đúng giờ cron.
Plugin muốn chặn outbound message theo policy typed plugin hook.