Class: DefaultHandler

Inherits:
Hooks::Plugins::Handlers::Base show all
Defined in:
lib/hooks/plugins/handlers/default.rb

Overview

Default webhook handler implementation

This handler provides a basic webhook processing implementation that can be used as a fallback when no custom handler is configured for an endpoint. It demonstrates the standard handler interface and provides basic logging functionality.

Examples:

Usage in endpoint configuration

handler:
  type: DefaultHandler

See Also:

Instance Method Summary collapse

Methods inherited from Hooks::Plugins::Handlers::Base

#error!

Methods included from Hooks::Core::ComponentAccess

#failbot, #log, #method_missing, #respond_to_missing?, #stats

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Hooks::Core::ComponentAccess

Instance Method Details

#call(payload:, headers:, env:, config:) ⇒ Hash

Process a webhook request with basic acknowledgment

Provides a simple webhook processing implementation that logs the request and returns a standard acknowledgment response. This is useful for testing webhook endpoints or as a placeholder during development.

Examples:

Basic usage

handler = DefaultHandler.new
response = handler.call(
  payload: { "event" => "push" },
  headers: { "Content-Type" => "application/json" },
  env: { "REQUEST_METHOD" => "POST", "hooks.request_id" => "12345" },
  config: { opts: {} }
)
# => { message: "webhook processed successfully", handler: "DefaultHandler", timestamp: "..." }

Parameters:

  • payload (Hash, String)

    The webhook payload (parsed JSON or raw string)

  • headers (Hash<String, String>)

    HTTP headers from the webhook request

  • env (Hash)

    Rack environment (contains the request context, headers, config, etc - very rich context)

  • config (Hash)

    Endpoint configuration containing handler options

Options Hash (config:):

  • :opts (Hash)

    Additional handler-specific configuration options

Returns:

  • (Hash)

    Response indicating successful processing



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/hooks/plugins/handlers/default.rb', line 37

def call(payload:, headers:, env:, config:)

  log.info("🔔 Default handler invoked for webhook 🔔")

  # do some basic processing
  if payload
    log.debug("received payload: #{payload.inspect}")
  end

  if env
    log.debug("default handler got a request with the following request_id: #{env['hooks.request_id']}")
  end

  {
    message: "webhook processed successfully",
    handler: "DefaultHandler",
    timestamp: Time.now.utc.iso8601
  }
end