Behaviour for handling Twitch EventSub WebSocket events.
Example
defmodule MyApp.TwitchHandler do
@behaviour Teac.WssClient.Handler
@impl true
def handle_event(%{"type" => "channel.follow"} = _subscription, event, state) do
IO.inspect(event, label: "new follower")
{:ok, state}
end
def handle_event(_subscription, _event, state), do: {:ok, state}
@impl true
def handle_revocation(%{"type" => type, "status" => reason} = _subscription, state) do
IO.puts("Subscription #{type} revoked: #{reason}")
state
end
endThen start the client:
Teac.WssClient.start_link(client, handler: MyApp.TwitchHandler)
Summary
Callbacks
Called when a notification arrives for a subscribed event.
Called when Twitch revokes a subscription.
Callbacks
@callback handle_event( subscription :: map(), event :: map(), state :: term() ) :: {:ok, term()} | {:error, term()}
Called when a notification arrives for a subscribed event.
subscription is the full payload.subscription object from the Twitch frame,
containing "id", "type", "version", "cost", "condition", and "created_at".
event is the payload.event object specific to the subscription type.
Return {:ok, new_state} to update handler state, or {:error, reason} to
log the error and keep the previous state.
Called when Twitch revokes a subscription.
subscription is the full payload.subscription object, containing "id",
"type", "version", "status" (the revocation reason), and "condition".
The return value is ignored — implement for side effects (logging, alerting, etc.).