You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/handler_plugins.md
+60Lines changed: 60 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,66 @@ class Example < Hooks::Plugins::Handlers::Base
27
27
end
28
28
```
29
29
30
+
### `payload` Parameter
31
+
32
+
The `payload` parameter can be a Hash or a String. If the payload is a String, it will be parsed as JSON. If it is a Hash, it will be passed directly to the handler. The payload can contain any data that the webhook sender wants to send.
33
+
34
+
By default, the payload is parsed as JSON (if it can be) and then symbolized. This means that the keys in the payload will be converted to symbols. You can disable this auto-symbolization of the payload by setting the environment variable `HOOKS_SYMBOLIZE_PAYLOAD` to `false` or by setting the `symbolize_payload` option to `false` in the global configuration file.
35
+
36
+
**TL;DR**: The payload is almost always a Hash with symbolized keys, regardless of whether the original payload was a Hash or a JSON String.
37
+
38
+
For example, if the client sends the following JSON payload:
39
+
40
+
```json
41
+
{
42
+
"hello": "world",
43
+
"foo": ["bar", "baz"],
44
+
"truthy": true,
45
+
"coffee": {"is": "good"}
46
+
}
47
+
```
48
+
49
+
It will be parsed and passed to the handler as:
50
+
51
+
```ruby
52
+
{
53
+
hello:"world",
54
+
foo: ["bar", "baz"],
55
+
truthy:true,
56
+
coffee: {is:"good"}
57
+
}
58
+
```
59
+
60
+
### `headers` Parameter
61
+
62
+
The `headers` parameter is a Hash that contains the HTTP headers that were sent with the webhook request. It includes standard headers like `host`, `user-agent`, `accept`, and any custom headers that the webhook sender may have included.
63
+
64
+
Here is an example of what the `headers` parameter might look like:
"Authorization" => "Bearer <TOKEN>"# a careful reminder that headers *can* contain sensitive information!
79
+
}
80
+
```
81
+
82
+
It should be noted that the `headers` parameter is a Hash with **String keys** (not symbols). They are also normalized (lowercased and trimmed) to ensure consistency.
83
+
84
+
You can disable this normalization by either setting the environment variable `HOOKS_NORMALIZE_HEADERS` to `false` or by setting the `normalize_headers` option to `false` in the global configuration file.
85
+
86
+
### `config` Parameter
87
+
88
+
The `config` parameter is a Hash (symbolized) that contains the endpoint configuration. This can include any additional settings or parameters that you want to use in your handler. Most of the time, this won't be used, but sometimes endpoint configs add `opts` that can be useful for the handler.
89
+
30
90
## Built-in Features
31
91
32
92
This section goes into details on the built-in features that exist in all handler plugins that extend the `Hooks::Plugins::Handlers::Base` class.
0 commit comments