ExPipedriveWeb.Incoming.Handler (ex_pipedrive_web v0.1.1)

Copy Markdown View Source

Plug router for incoming Pipedrive webhook POSTs.

Normalizes Pipedrive payloads into ExPipedrive.Webhook.Event structs and delivers them to an optional ExPipedrive.Webhook.Handler module. The host application owns fan-out (Registry, PubSub, etc.) — this package does not start any OTP processes for webhooks.

Example

forward "/webhooks", to: ExPipedriveWeb.Incoming.Handler,
  init_opts: [handler: MyApp.PipedriveWebhookHandler,
              auth_fn: fn -> [username: "pipedrive", password: secret] end]

See https://pipedrive.readme.io/docs/guide-for-webhooks for event types and payload shapes. :auth_fn is optional; when present it can be a zero-arity function returning Plug.BasicAuth options or those options directly.

Compatibility

on_event: fn {:updated_deal, payload} -> ... end remains supported for deal and person update events. New integrations should configure :handler and implement ExPipedrive.Webhook.Handler.

ExPipedrive.Incoming.Handler is a compatibility alias for this module.

Summary

Functions

Callback implementation for Plug.call/2.

Delivers a normalized webhook event to the configured handler.

Callback implementation for Plug.init/1.

Normalizes a Pipedrive webhook payload into an Event.

Functions

call(conn, opts)

Callback implementation for Plug.call/2.

deliver_event(event, opts)

Delivers a normalized webhook event to the configured handler.

:handler is preferred. :on_event receives the historical tuple shape for deal/person update events when no handler is configured.

init(opts)

Callback implementation for Plug.init/1.

normalize_event(payload)

@spec normalize_event(map()) :: ExPipedrive.Webhook.Event.t() | nil

Normalizes a Pipedrive webhook payload into an Event.

process_event(payload)

transform_event(arg1, payload)