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

  1. Imagine user starts your chatbot for the first time.
  2. The engine checks for the current stage in the session (no stages found at this stage), and takes the start menu that you configure.
  3. It evaluates this current template hooks and processes all PRE-HOOKs on it.
  4. It processes & renders the template and send to user. (a lot more happens under the hood)
  5. 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)
  6. 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

Post Hooks

These hooks are processed AFTER the user responds to a message.

In the order which they are processed

  • params
  • validator
  • on-receive
  • middleware
  • prop

Hooks processing

Hooks are processing *reflectively (using Reflection API) (more on this later)

Let's look into this more in the next section