Current section
Files
Jump to
Current section
Files
lib/teac/event_sub/conduit_event.ex
defmodule Teac.EventSub.ConduitEvent do
@moduledoc """
Parses `conduit.shard.disabled` EventSub events into typed structs.
Call `from_event/2` with the subscription type and raw event map.
"""
alias Teac.EventSub.Transport
defmodule ShardDisabled do
@moduledoc "A conduit shard was disabled (`conduit.shard.disabled`)."
@type t :: %__MODULE__{
conduit_id: String.t(),
shard_id: String.t(),
status: String.t(),
transport: Transport.t() | nil
}
defstruct [:conduit_id, :shard_id, :status, :transport]
end
@type t :: ShardDisabled.t()
@doc """
Parses a raw conduit event map into the appropriate struct based on subscription type.
"""
@spec from_event(String.t(), map()) :: t()
def from_event("conduit.shard.disabled", event) do
%ShardDisabled{
conduit_id: event["conduit_id"],
shard_id: event["shard_id"],
status: event["status"],
transport: Transport.from_map(event["transport"])
}
end
end