Getting Started

Hooks

Advanced

Miscellaneous

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

  1. Imagine user starts your chatbot for the first time.
  2. 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.
  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 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 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

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 supports both RESTful based hooks and Java classes (using Reflection API) (more on this later)

Let's look into this more in the next section