ExLine.Webhook (ExLine v0.1.0)

Copy Markdown View Source

Parse incoming LINE webhook payloads into event structs.

parse/1 is total — it never raises. This is required for forward compatibility: LINE adds new event/message types, enum values, and fields without notice, and the server must keep working (dev guidelines). Accordingly:

  • an unrecognized event/message type degrades to ExLine.Webhook.Event.Unknown / ExLine.Webhook.Message.Unknown (mirroring the official SDKs),
  • unknown fields are ignored (the original payload is kept in each struct's raw),
  • a single malformed event degrades to Event.Unknown rather than failing the batch.

Verify the signature first with ExLine.Webhook.Signature / ExLine.Webhook.Plug.

Example

body |> Jason.decode!() |> ExLine.Webhook.parse() |> Enum.each(&MyRouter.call/1)

Ref: https://developers.line.biz/en/reference/messaging-api/#webhook-event-objects

Summary

Functions

Parses a decoded webhook request (%{"events" => [...]}) or a list of raw events into a list of event structs.

Parses a single raw event map into an event struct. Never raises — anything it can't model becomes an Event.Unknown.

Types

Functions

parse(events)

@spec parse(map() | [map()]) :: [event()]

Parses a decoded webhook request (%{"events" => [...]}) or a list of raw events into a list of event structs.

parse_event(raw)

@spec parse_event(map()) :: event()

Parses a single raw event map into an event struct. Never raises — anything it can't model becomes an Event.Unknown.