Template Hook

Populate template message variables dynamically

Template hook will likely be your best buddie in your conversation flows.

The engine uses the {{ mustache }} templating engine (like Python Jinja) to populate the dynamic variables. It is used to dynamically create a conversation message body.

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

"PAYMENT_ORDER":
  type: text
  template: "rest:/gpay/order"
  message:
   - "Thank you {{ user }}."
   - ""
   - "Your Avon order has been processed with reference: {{ reference }}"
   - "for {{ currency }} {{ amount }}"
  routes:
    "re:.*": "HOME_MENU"

The tagged template hook should return a render-payload matching each variable in the defined template

@RestController
class OrderController {
    @PostMapping("/order")
    public Object orderDetailsTemplate(@RequestBody HookArgsRest args) {
      // .. process business logic
      // .. get order details from db or a service
      // .. return a render-payload of Map matching template variables

      args.setTemplateDynamicBody(
        new TemplateDynamicBody(
            null,
            null,
            Map.of(
                    "user", args.getChannelUser().name(),
                    "reference", "order-#1234",
                    "currency", "USD",
                    "amount", 20.50
            )
        ));

    return args;
    }
}