telega

Types

pub type Command {
  Command(text: String, command: String, payload: Option(String))
}

Constructors

  • Command(text: String, command: String, payload: Option(String))

    Represents a command message.

    Arguments

    • text

      Whole command message

    • command

      Command name without the leading slash

    • payload

      The command arguments, if any.

pub opaque type Handler(session)
pub opaque type SessionSettings(session)
pub opaque type Telega(session)
pub opaque type TelegaBuilder(session)

Functions

pub fn handle_all(
  builder: TelegaBuilder(a),
  handler: fn(Context(a)) -> Result(a, String),
) -> TelegaBuilder(a)

Handles all messages.

pub fn handle_command(
  builder: TelegaBuilder(a),
  command: String,
  handler: fn(Context(a), Command) -> Result(a, String),
) -> TelegaBuilder(a)

Handles a specific command.

pub fn handle_commands(
  builder: TelegaBuilder(a),
  commands: List(String),
  handler: fn(Context(a), Command) -> Result(a, String),
) -> TelegaBuilder(a)

Handles multiple commands.

pub fn handle_text(
  builder: TelegaBuilder(a),
  handler: fn(Context(a), String) -> Result(a, String),
) -> TelegaBuilder(a)

Handles text messages.

pub fn handle_update(
  telega: Telega(a),
  message: Message,
) -> Result(Nil, String)

Handle an update from the Telegram API.

pub fn init(
  builder: TelegaBuilder(a),
) -> Result(Telega(a), String)

Initialize a Telega instance. This function should be called after all handlers are added. It will set the webhook and start the Registry.

pub fn init_nil_session(
  builder: TelegaBuilder(Nil),
) -> Result(Telega(Nil), String)

Initialize a Telega instance with a Nil session. Usefulwhen you don’t need to persist the session.

pub fn is_secret_token_valid(
  telega: Telega(a),
  token: String,
) -> Bool

Check if a secret token is valid.

Usefull if you plan to implement own adapter.

pub fn is_webhook_path(telega: Telega(a), path: String) -> Bool

Check if a path is the webhook path for the bot.

Usefull if you plan to implement own adapter.

pub fn log_context(
  ctx: Context(a),
  prefix: String,
  handler: fn() -> Result(a, String),
) -> Result(a, String)

Log the message and error message if the handler fails.

pub fn new(
  token token: String,
  url server_url: String,
  webhook_path webhook_path: String,
  secret_token secret_token: Option(String),
) -> TelegaBuilder(a)

Create a new Telega instance.

pub fn with_session_settings(
  builder: TelegaBuilder(a),
  persist_session persist_session: fn(String, a) ->
    Result(a, String),
  get_session get_session: fn(String) -> Result(a, String),
  get_session_key get_session_key: fn(Message) -> String,
) -> TelegaBuilder(a)

Construct a session settings.

Search Document