WebhookPlug and WebhookHandler behaviour for handling inbound events. It’s published as surge_api on Hex and supports Elixir 1.14 and newer.
This page covers installing the package, configuring the client for Phoenix, sending your first request, handling errors, and wiring webhook routes with either the plug or the behaviour.
Install and authenticate
Add to yourmix.exs:
mix.exs
config/runtime.exs
Your first request
Using the default client (reads from application config):Retrieving a message
Error handling
The SDK returns tagged tuples:Webhook handling
WebhookPlug for Phoenix
The SDK includesSurge.WebhookPlug that handles signature verification and event parsing. Add it to your endpoint.ex before Plug.Parsers:
lib/my_app_web/endpoint.ex
WebhookHandler behaviour
Implement theSurge.WebhookHandler behaviour to process events. The callback receives a Surge.Events.Event struct with an atom type and a data field:
:ok or {:ok, term} for success, or :error or {:error, reason} to signal a failure (which returns HTTP 400 to Surge).
Manual signature verification
The Elixir SDK currently consumes the older
surge-signature header (format t=<ts>,v1=<hex>) with a different signed-payload composition than the Standard Webhooks spec used by Python / TypeScript / Ruby. Migrating to Standard Webhooks (webhook-signature) this week — this Note will be removed once the migration ships. See Signature validation for both formats.Surge.WebhookPlug, verify signatures with Surge.Webhook.construct_event/3:
signature_header is the value of the surge-signature HTTP header, formatted as t=timestamp,v1=hex_signature.