Introduction
Supercharge your template
Hooks supercharge the WCE engines. It makes it possible to hook custom, additional functionality during message processing.
You want to send a Slack notification when user confirms their order? Add a hook.
How about to dynamically populate a message with some dynamic variables? Add a hook!
How hooks are processed
- Imagine user starts your chatbot for the first time.
- The engine checks for the current stage in the session (no stages found at this stage), and takes the start menu that you configure.
- It evaluates this current template hooks and processes all
PRE-HOOK
s on it. - It processes & renders the template and send to user. (a lot more happens under the hood)
- When a user respond to that message via WhatsApp, the engine lookup the template in the session (it's likely our first template saved in session)
- The engine marks this as current template and processes all
POST-HOOKS
on it
The process repeats on and on 🔁
There a number of supported hooks that you can define in your template.
Below are some of the "hooks" and the other "fields" you can define in your template
- type - the type of message to render
- prop
- on-receive
- on-generate
- validator
- middleware
- template
- params
- message
- routes and much more
You can probably guess what other hooks do by their names.
Hooks are categorized into POST
or PRE
hooks
Pre Hooks
These are processed BEFORE the message is rendered and send to the user on WhatsApp.
In the order which they are processed
These include
- params
- template
- on-generate