Getting Started

Hooks

Advanced

Miscellaneous

Creating Hooks

Supercharge your template with hooks

Hooks are nothing more than regular Java classes or your normal REST API endpoints.

Java hooks takes advantage of JAVA Reflection API

You can mix both approaches anyway you want. Java classes will only work if you extend the engine (more in the Advanced section).

Since JAWCE attempts to run as a standalone engine, you can as well have all your hooks as REST endpoints to your system backend.

All hooks should accept a child of DefaultHookArg model as a request body or as a constructor argument.

DefaultHookArg has 2 subclasses which are HookArgs for Java classes hooks and HookArgsRest for REST based hooks.

All REST API based hooks should be a POST request that accepts and returns a HookArgsRest model.

All Java classes based hooks should have a constructor which takes HookArgs model as a parameter.

Hook model

Hook Model: HookArgs
public record WaCurrentUser(
    String name,        // default user display name
    String waId,        // mobile number
    String msgId,
    ) {}

public record TemplateDynamicBody(
    WebhookResponseMessageType type,        // for dynamic template message type
    Map<String, Object> payload,            // used for `flow` type - initial flow data
    Map<String, Object> renderPayload       // dynamic template data
    ) {}

// main model
public class HookArgs {
    private WaCurrentUser channelUser;
    private String userInput;                           // user input from whatsapp
    private String flow;                                // flow name for flow template type
    private Map<String, Object> additionalData;         // mainly for dynamic routing
    private TemplateDynamicBody templateDynamicBody;
    private Map<String, Object> methodArgs;             // provided static params defined on template
}

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