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
This Plug makes it easy to listen to Github webhook requests in your Elixir
and Phoenix apps and trigger actions.
Features:
Configurable HTTP endpoint
Verifies authenticity using webhook secret
Responses are handled for you - just write business logic
Installation
Add gh_webhook_plug to your list of dependencies in mix.exs:
defdepsdo[{:gh_webhook_plug,"~> 0.0.5"}]end
Usage
Inside a phoenix app, add this line in the Endpoint module:
defmoduleMyApp.Endpointdo# Add this line above Plug.Parsers plug:plugGhWebhookPlug,secret: "secret",path: "/github_webhook",action: {MyApp.GithubWebhook,:handle}# Rest of the plugsend
Now you can write the handler like this:
defmoduleMyApp.GithubWebhookdodefhandle(conn,payload)do# Handle webhook payload here# Return value of this function is ignoredendend
Configuration
Add this to your configuration file (config/config.exs):
config:gh_webhook_plug,# Secret set in webhook settings page of the Github repositorysecret: "foobar",# Path that will be intercepted by GhWebhookPlugpath: "/api/github_webhook",# Module and function that will be used to handle the webhook payloadaction: {MyApp.GithubWebhook,:handle}
These configurations can also be set via options to the plug as shown in the
example in the Usage section.
License
MIT
About
An Elixir Plug library that makes it easy to setup Github webhooks. Secret verification comes free.