Business Logic 🚀

Supercharge your template

Hooks supercharge the WCE engines. It makes it possible to hook custom, additional functionality during message processing.

All chatbot business logic is defined in the corresponding hook.

Hooks processing

Hooks that uses dotted path are processed using reflection API

Learn more about Java Reflection

Learn more about Python Reflection

These are normal functions / methods that you define. Any hook must take a single argument HookArg object.

Session manager attribute gives you access to the engine session instance.

Learn more about session manager methods here

Hook model

The Hook model contains all the necessary data you can use in your business logic

Hooks are classified as PRE & POST hooks - it can be processed before a message is sent to user or processed after a message is received from a user.

Hooks are normal functions or method, you will learn more under hooks section.

Supported hooks

POST

  • on-receive processed after a message is received from a user. Main point of business logic after user sends a message. Use cases include: send email after user confirms order, process an order, validate user input etc.
  • middleware processed after on-receive is processed. Meant for any business logic processed mid-flight
  • router is processed last and it by-pass the routes defined on the template. Its used to dynamically compute the next stage to go to (redirecting).

PRE

  • template used for dynamically populating a dynamic data on the template. Use cases: dynamically populate a button template, button label or template text
  • on-generate processed after template hook is processed. Meant for any business logic processed mid-flight before a message is shown to user

Let's look at each hook and how its business logic is defined.

JAWCE also supports RESTFul based hooks. Only JAWCE supports both reflective and restful based hooks

frappe-pywce also supports script based hooks with limited support. These have a similar approach to Frappe API Server Scripts.