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: README.md
+8-6Lines changed: 8 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,9 +50,11 @@ Here is a very high-level overview of how Hooks works:
50
50
```yaml
51
51
# file: config/endpoints/hello.yml
52
52
path: /hello
53
-
handler: MyCustomHandler # This is a custom handler plugin you would define in the plugins/handlers directory
53
+
handler: my_custom_handler # This is a custom handler plugin you would define in the plugins/handlers directory (snake_case)
54
54
```
55
55
56
+
> Note: If your handler's class name is `MyCustomHandler`, you would define it in the `plugins/handlers/my_custom_handler.rb` file. The `handler` field in the endpoint configuration file should be the snake_case version of the class name. So if your handler class is `MyCustomHandler`, you would use `my_custom_handler` in the endpoint configuration file.
57
+
56
58
3. Now create a corresponding handler plugin in the `plugins/handlers` directory. Here is an example of a simple handler plugin:
57
59
58
60
```ruby
@@ -64,7 +66,7 @@ Here is a very high-level overview of how Hooks works:
64
66
# For this example, we will just return a success message
65
67
{
66
68
status: "success",
67
-
handler: "MyCustomHandler",
69
+
handler: "my_custom_handler",
68
70
payload_received: payload,
69
71
timestamp: Time.now.utc.iso8601
70
72
}
@@ -208,16 +210,16 @@ Endpoint configurations are defined in the `config/endpoints` directory. Each en
208
210
```yaml
209
211
# file: config/endpoints/hello.yml
210
212
path: /hello # becomes /webhooks/hello based on the root_path in hooks.yml
211
-
handler: HelloHandler # This is a custom handler plugin you would define in the plugins/handlers
213
+
handler: hello_handler # This is a custom handler plugin you would define in the plugins/handlers
212
214
```
213
215
214
216
```yaml
215
217
# file: config/endpoints/goodbye.yml
216
218
path: /goodbye # becomes /webhooks/goodbye based on the root_path in hooks.yml
217
-
handler: GoodbyeHandler # This is another custom handler plugin you would define in the plugins/handlers
219
+
handler: goodbye_handler # This is another custom handler plugin you would define in the plugins/handlers
218
220
219
221
auth:
220
-
type: Goodbye # This is a custom authentication plugin you would define in the plugins/auth
222
+
type: goodbye # This is a custom authentication plugin you would define in the plugins/auth
221
223
secret_env_key: GOODBYE_API_KEY # the name of the environment variable containing the secret
222
224
header: Authorization
223
225
@@ -255,7 +257,7 @@ class GoodbyeHandler < Hooks::Plugins::Handlers::Base
Copy file name to clipboardExpand all lines: docs/handler_plugins.md
+15Lines changed: 15 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,7 @@ Handler plugins are Ruby classes that extend the `Hooks::Plugins::Handlers::Base
8
8
9
9
-`payload`: The webhook payload, which can be a Hash or a String. This is the data that the webhook sender sends to your endpoint.
10
10
-`headers`: A Hash of HTTP headers that were sent with the webhook request.
11
+
-`env`: A modified Rack environment that contains a lot of context about the request. This includes information about the request method, path, query parameters, and more. See [`rack_env_builder.rb`](../lib/hooks/app/rack_env_builder.rb) for the complete list of available keys.
11
12
-`config`: A Hash containing 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.
12
13
13
14
```ruby
@@ -28,6 +29,20 @@ class Example < Hooks::Plugins::Handlers::Base
28
29
end
29
30
```
30
31
32
+
After you write your own handler, it can be referenced in endpoint configuration files like so:
33
+
34
+
```yaml
35
+
# example file path: config/endpoints/example.yml
36
+
path: /example_webhook
37
+
handler: example # this is the name of the handler plugin class
38
+
```
39
+
40
+
It should be noted that the `handler:` key in the endpoint configuration file should match the name of the handler plugin class, but in lowercase and snake case. For example, if your handler plugin class is named `ExampleHandler`, the `handler:` key in the endpoint configuration file should be `example_handler`. Here are some more examples:
41
+
42
+
- `ExampleHandler`-> `example_handler`
43
+
- `MyCustomHandler`-> `my_custom_handler`
44
+
- `Cool2Handler`-> `cool_2_handler`
45
+
31
46
### `payload` Parameter
32
47
33
48
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.
0 commit comments