{"id":47874633,"url":"https://github.com/alec-c4/action_hooks","last_synced_at":"2026-04-04T01:09:37.285Z","repository":{"id":341435754,"uuid":"1170143103","full_name":"alec-c4/action_hooks","owner":"alec-c4","description":"ActionHooks is a Ruby on Rails engine designed to securely handle incoming webhooks.","archived":false,"fork":false,"pushed_at":"2026-03-30T08:10:48.000Z","size":142,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-03-30T10:14:23.186Z","etag":null,"topics":["api","gem","ruby","ruby-on-rails","webhook","webhooks"],"latest_commit_sha":null,"homepage":"https://alec-c4.com","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alec-c4.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"alec-c4"}},"created_at":"2026-03-01T19:04:52.000Z","updated_at":"2026-03-30T08:10:49.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/alec-c4/action_hooks","commit_stats":null,"previous_names":["alec-c4/action_hooks"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/alec-c4/action_hooks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alec-c4%2Faction_hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alec-c4%2Faction_hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alec-c4%2Faction_hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alec-c4%2Faction_hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alec-c4","download_url":"https://codeload.github.com/alec-c4/action_hooks/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alec-c4%2Faction_hooks/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31353832,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-03T08:03:20.796Z","status":"ssl_error","status_checked_at":"2026-04-03T08:00:37.834Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","gem","ruby","ruby-on-rails","webhook","webhooks"],"created_at":"2026-04-04T01:09:36.610Z","updated_at":"2026-04-04T01:09:37.252Z","avatar_url":"https://github.com/alec-c4.png","language":"Ruby","funding_links":["https://github.com/sponsors/alec-c4"],"categories":[],"sub_categories":[],"readme":"# ActionHooks\n\nActionHooks is a Ruby on Rails engine designed to securely handle incoming webhooks. It standardizes the process of receiving webhooks from various third-party services (like Stripe, GitHub, etc.) by:\n\n1. **Persisting Webhooks:** Saving all incoming requests to the database (`webhook_requests` table) with their payload, source, and processing state before any business logic is executed.\n2. **Security \u0026 Verification:** Verifying the authenticity of the webhook via signature validation logic and optionally restricting access by IP address.\n3. **Asynchronous Processing:** Automatically dispatching the saved webhook to a configured background worker (`ActiveJob`) for asynchronous processing.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem \"action_hooks\"\n```\n\nAnd then execute:\n\n```bash\n$ bundle install\n```\n\nAfter installing the gem, you need to run the installation generator. This will create the necessary database migration for the `webhook_requests` table and an initializer file.\n\n```bash\n$ rails generate action_hooks:install\n```\n\nRun the database migrations:\n\n```bash\n$ rails db:migrate\n```\n\n## Usage\n\n### 1. Configuration\n\nConfigure your webhook sources in the generated initializer (`config/initializers/action_hooks.rb`). Each source represents a third-party service sending webhooks to your application. ActionHooks automatically mounts a catch-all route `POST /webhooks/:source`, so configuring a source is enough to start receiving requests.\n\n```ruby\n# config/initializers/action_hooks.rb\nActionHooks.configure do |config|\n  config.add_source(:stripe) do |source|\n    # The ActiveJob worker class that will process the webhook\n    source.worker = \"StripeWebhookJob\"\n\n    # Lambda to verify the signature of the incoming request\n    source.verify_signature = -\u003e(request) do\n      payload = request.body.read\n      sig_header = request.env['HTTP_STRIPE_SIGNATURE']\n      # Example using Stripe's library:\n      # Stripe::Webhook::Signature.verify_header(payload, sig_header, ENV['STRIPE_WEBHOOK_SECRET'])\n      true\n    end\n\n    # Optional: Restrict incoming requests to specific IP addresses/hosts\n    # source.allowed_hosts = [\"127.0.0.1\", \"10.0.0.1\"] # Also aliased as `allowed_ips`\n  end\nend\n```\n\n### 2. Generating a Job\n\nBy default, an incoming webhook is authenticated, persisted, and handed over to a background job. You can easily generate a job template for your source:\n\n```bash\n$ rails generate action_hooks:webhook stripe\n```\n\nThis will create `app/jobs/stripe_webhook_job.rb`. The background job will receive the ID of the saved `ActionHooks::WebhookRequest` record:\n\n```ruby\n# app/jobs/stripe_webhook_job.rb\nclass StripeWebhookJob \u003c ApplicationJob\n  queue_as :default\n\n  def perform(webhook_request_id)\n    webhook_request = ActionHooks::WebhookRequest.find(webhook_request_id)\n    payload = webhook_request.payload\n\n    case payload[\"type\"]\n    when \"payment_intent.succeeded\"\n      # handle payment\n    end\n\n    webhook_request.processed!\n  rescue =\u003e e\n    webhook_request.failed!\n    raise e\n  end\nend\n```\n\n### 3. Custom Controller (Optional)\n\nIf your webhook processing requires complex synchronous logic before placing the job into the queue, you can generate a custom controller using the `--controller` flag:\n\n```bash\n$ rails generate action_hooks:webhook stripe --controller\n```\n\nThis generates:\n\n- A job: `app/jobs/stripe_webhook_job.rb` (unless `--skip-job` is provided)\n- A controller: `app/controllers/webhooks/stripe_controller.rb`\n- A specific route mapping in `config/routes.rb`\n\nYour custom controller will inherit from `ActionHooks::WebhookController`. The parent controller handles persistence, IP checks, and signature verification, while your controller can focus just on the business logic inside the `process_webhook` hook:\n\n```ruby\n# app/controllers/webhooks/stripe_controller.rb\nclass Webhooks::StripeController \u003c ActionHooks::WebhookController\n  private\n\n  def webhook_source_name\n    :stripe\n  end\n\n  def process_webhook(webhook_request)\n    # Business logic here.\n    # The default behavior inside `process_webhook` is to enqueue the configured background job.\n  end\nend\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/alec-c4/action_hooks.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falec-c4%2Faction_hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falec-c4%2Faction_hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falec-c4%2Faction_hooks/lists"}