Skip to main content

Templates

Templates in Hookah define the body payloads that will be sent to your target webhooks.

Template files must be placed inside the configured TEMPLATES_PATH directory, and use Go's standard templating language.

When a webhook is triggered, Hookah will load the specified template file (defined in the hook's body field) and render it using the original webhook payload.

Accessing Payload Data

Inside a template, you can reference fields from the incoming request body using dot notation:

{{ .some.path }}

For example, if the incoming webhook payload includes:

{
"user": {
"name": "Jane Doe"
}
}

You can access name inside the template like this:

{{ .user.name }}

Built-in Template Functions

Hookah enriches the template engine with several helpful functions:

FunctionDescription
nowReturns the current time.
formatFormats a time.Time object using Go's time layout. Example: {{ format now "2006-01-02" }}
parseTimeParses a string into a time.Time using the given layout. Example: {{ parseTime "2023-01-01" "2006-01-02" }}
pastTenseForms the past tense of a word. Example: {{ pastTense "open" }}opened
lowerConverts a string to lowercase. Example: {{ lower "HELLO" }}hello
upperConverts a string to uppercase. Example: {{ upper "hello" }}HELLO
titleConverts a string to title case. Example: {{ title "hello world" }}HELLO WORLD
trimRemoves leading and trailing whitespace. Example: {{ trim " hello " }}hello
containsChecks if a string contains a substring. Example: {{ contains "hello world" "world" }}true
replaceReplaces all occurrences of a substring. Example: {{ replace "hello world" "world" "Go" }}hello Go
defaultReturns a fallback value if the field is missing or empty. Example: {{ default .user.name "Guest" }}

Important Notes

  • Templates must generate valid JSON after rendering, as they are directly sent in outgoing HTTP requests.
  • If a template cannot be rendered properly (syntax errors, missing fields, etc.), the webhook call will fail for that hook.
  • It's good practice to use default functions when referencing optional fields to avoid empty or invalid JSON output.