Introduction
Supercharge your template
Hooks supercharge the JAWCE engine. 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 this in the session (no stages found at this stage), and takes the first menu configured in the
properties
file as the first template. - 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 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 hooks that you can define in your template, the engine will do its best to handle the rest.
Below are some of the "hooks" and the other "fields" or "attributes" you can define in your templates
- type - 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 does by their name.
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