Webhooks

Webhooks are user-defined HTTP callbacks. They are triggered by database model (an object representing a table of data) lifecycle events (created, updated, saved and deleted).

Webhooks can be defined in Admin > Webhooks.

Expressions

Expressions can be used in the condition, the URL and the request body.

Attributes

Database model attribute names can be determined by inspecting the database schema (table column names) and model definitions.

  • Attributes can be embedded in an expression using two pairs of curly brackets ({{}}).
  • Attributes can change their value during an event. The previous value is accessible by appending _original to the attribute name.
  • Subattributes can be accessed with the . operator.

Examples: {{ id }}, {{ user.name }}, {{ thread.board.name }} and {{ thread.board_original.name }}.

Filters

Filters can be applied to an expression using the pipe operator (|). Some filters have arguments that can be passed within parentheses (). Examples: {{ name | upper }}, {{ name | lower | capitalize }} and {{ name | truncate(5) }}.

The following filters are available:

  • truncate
  • lower
  • upper
  • capitalize
  • divide
  • default
  • unix.

Condition

The condition is a series of boolean and relational expressions that are evaluated to determine whether to trigger the webhook. In addition to the expressions above, the condition supports expressions with the following operators:

  • relational operators equals == and NOT equals !=
  • logical operators AND && and || OR.

TIP

The logical AND operator takes precedence. That is, AND expressions are evaluated before OR expressions.

Examples

Send new forum posts to Discord

{
    "embeds": [
        {
            "title": "{{ thread.topic }}",
            "url": "https://example.com/forums/posts/{{ pid }}",
            "description": "{{ content | truncate(150) }}",
            "timestamp": "{{ timestamp }}Z",
            "footer": {
                "text": "Posted by {{ user.name }}",
                "icon_url": "{{ user.avatar }}"
            }
        }
    ]
}

Log Garry's Mod server map changes to Discord

{
    "embeds": [
        {
            "title": "{{ name }}",
            "description": "Now playing {{ metadata.game.mode }} in `{{ metadata.map.name }}`",
            "thumbnail": {
                "url": "https://example.com/api/loadingscreens/mapicons/{{ metadata.map.name }}"
            }
        }
    ]
}

Log payments to Discord

{
    "embeds": [
        {
            "title": "Payment received",
            "url": "https://example.com/users/{{ user.id }}/purchases",
            "description": "{{ total | divide(100) }} {{ currency | upper }} using {{ processor | capitalize }}",
            "footer": {
                "text": "Paid by {{ user.name }}",
                "icon_url": "{{ user.avatar }}"
            }
        }
    ]
}