Template Hook
Populate template message variables dynamically
Template hook will likely be your best buddie on 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
"PAYMENT_ORDER":
type: text
template: "rest:http://domain.url/order"
message:
- "Thank you {{ user }}."
- ""
- "Your Avon order has been processed with reference: {{ reference }}"
- "for {{ currency }} {{ amount }}"
routes:
"re:.*": "START_MENU"
The tagged template hook should return a render-payload matching each variable in the defined template
Hook: template
# ...
@app.post("/order")
def order_details(args: HookArgs):
print("Received args: {}".format(args))
# assume order has been processed and saved to DB
order = get_order_by_user(user=args.channelUser.waId)
template = TemplateDynamicBody()
template.renderPayload = {
"user": args.channelUser.name,
"reference": order.get('reference'),
"currency": order.get('currency'),
"amount": order.get('amount')
}
args.templateDynamicBody = template
return args