Skip to content

Commit 4c6667b

Browse files
committed
docs
1 parent 4972e52 commit 4c6667b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

docs/handler_plugins.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,31 @@
22

33
This document provides in-depth information about handler plugins and how you can create your own to extend the functionality of the Hooks framework for your own deployment.
44

5+
## Writing a Handler Plugin
6+
7+
Handler plugins are Ruby classes that extend the `Hooks::Plugins::Handlers::Base` class. They are used to process webhook payloads and can do anything you want. They follow a very simple interface that allows you to define a `call` method that takes three parameters: `payload`, `headers`, and `config`. The `call` method should return a hash with the response data. The hash that this method returns will be sent back to the webhook sender as a JSON response.
8+
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+
- `headers`: A Hash of HTTP headers that were sent with the webhook request.
11+
- `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+
```ruby
14+
# example file path: plugins/handlers/example.rb
15+
class Example < Hooks::Plugins::Handlers::Base
16+
# Process a webhook payload
17+
#
18+
# @param payload [Hash, String] webhook payload
19+
# @param headers [Hash<String, String>] HTTP headers
20+
# @param config [Hash] Endpoint configuration
21+
# @return [Hash] Response data
22+
def call(payload:, headers:, config:)
23+
return {
24+
status: "success"
25+
}
26+
end
27+
end
28+
```
29+
530
## Built-in Features
631

732
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

Comments
 (0)