Hotline.Type behaviour (Hotline v0.2.1)

Copy Markdown View Source

Macro for Telegram API type structs with automatic parsing.

Usage:

defmodule Hotline.Types.User do
  use Hotline.Type

  defstruct [:id, :is_bot, :first_name]

  @type t :: %__MODULE__{
          id: integer(),
          is_bot: boolean(),
          first_name: String.t()
        }
end

The parse/1 function converts a raw map (with string keys) into the struct, dropping unknown fields and applying nested type parsing via parse_nested/1.

Override parse_nested/1 to return a map of %{field_atom => parser_fn} for fields that contain nested Hotline types.

Summary

Callbacks

parse(arg1)

@callback parse(map() | nil) :: struct() | nil

parse_nested(map)

@callback parse_nested(map()) :: map()