telega

Types

pub opaque type Telega(session, error)
pub opaque type TelegaBuilder(session, error)

Functions

pub fn get_api_config(telega: Telega(a, b)) -> TelegramClient

Helper to get the config for API requests.

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

Handles all messages.

pub fn handle_callback_query(
  bot builder: TelegaBuilder(a, b),
  filter filter: CallbackQueryFilter,
  handler handler: fn(Context(a, b), String, String) ->
    Result(Context(a, b), b),
) -> TelegaBuilder(a, b)

Handles messages from inline keyboard callback.

See [conversation]

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

Handles a specific command.

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

Handles multiple commands.

pub fn handle_hears(
  bot builder: TelegaBuilder(a, b),
  hears hears: Hears,
  handler handler: fn(Context(a, b), String) ->
    Result(Context(a, b), b),
) -> TelegaBuilder(a, b)

Handles messages that match the given Hears.

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

Handles text messages.

pub fn handle_update(
  telega: Telega(a, b),
  update: Update,
) -> Result(Bool, CallError(c))

Handle an update from the Telegram API.

pub fn init(
  builder: TelegaBuilder(a, b),
) -> Result(Telega(c, d), TelegaError)

Initialize a Telega instance. This function should be called only after all handlers are added to the builder. It will set the webhook and start handling messages.

pub fn init_nil_session(
  builder: TelegaBuilder(Nil, a),
) -> Result(Telega(b, c), TelegaError)

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

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

Check if a secret token is valid.

Useful if you plan to implement own adapter.

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

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

Useful if you plan to implement own adapter.

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

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, b)

Create a new Telega instance.

pub fn set_allowed_updates(
  builder: TelegaBuilder(a, b),
  allowed_updates: List(String),
) -> TelegaBuilder(a, b)

Set the allowed updates as set webhook parameter.

pub fn set_certificate(
  builder: TelegaBuilder(a, b),
  certificate: File,
) -> TelegaBuilder(a, b)

Set the certificate as set webhook parameter.

pub fn set_drop_pending_updates(
  builder: TelegaBuilder(a, b),
  drop_pending_updates: Bool,
) -> TelegaBuilder(a, b)

Set the drop pending updates flag as set webhook parameter.

pub fn set_ip_address(
  builder: TelegaBuilder(a, b),
  ip_address: String,
) -> TelegaBuilder(a, b)

Set the ip address as set webhook parameter.

pub fn set_max_connections(
  builder: TelegaBuilder(a, b),
  max_connections: Int,
) -> TelegaBuilder(a, b)

Set the max connections as set webhook parameter.

pub fn wait_any(
  ctx ctx: Context(a, b),
  continue continue: fn(Context(a, b)) ->
    Result(Context(a, b), b),
) -> Result(Context(a, b), c)

Stops bot message handling from current chat and waits for any message.

See [conversation]

pub fn wait_callback_query(
  ctx ctx: Context(a, b),
  filter filter: CallbackQueryFilter,
  continue continue: fn(Context(a, b), String, String) ->
    Result(Context(a, b), b),
) -> Result(Context(a, b), c)

Wait for a callback query and continue with the given function.

See [conversation]

pub fn wait_command(
  ctx ctx: Context(a, b),
  command command: String,
  continue continue: fn(Context(a, b), Command) ->
    Result(Context(a, b), b),
) -> Result(Context(a, b), c)

Stops bot message handling from current chat and waits for a specific command.

See [conversation]

pub fn wait_commands(
  ctx ctx: Context(a, b),
  commands commands: List(String),
  continue continue: fn(Context(a, b), Command) ->
    Result(Context(a, b), b),
) -> Result(Context(a, b), c)

Stops bot message handling from current chat and waits for a specific command.

See [conversation]

pub fn wait_hears(
  ctx ctx: Context(a, b),
  hears hears: Hears,
  continue continue: fn(Context(a, b), String) ->
    Result(Context(a, b), b),
) -> Result(Context(a, b), c)

Stops bot message handling from current chat and waits for a message that matches the given Hears.

See [conversation]

pub fn wait_text(
  ctx ctx: Context(a, b),
  continue continue: fn(Context(a, b), String) ->
    Result(Context(a, b), b),
) -> Result(Context(a, b), c)

Stops bot message handling from current chat and waits for a text message.

See [conversation]

pub fn with_catch_handler(
  builder builder: TelegaBuilder(a, b),
  catch_handler catch_handler: fn(Context(a, b), b) ->
    Result(Nil, b),
) -> TelegaBuilder(a, b)

Set a catch handler for all handlers.

If handler returns Error, the chat instance will be stopped and the error will be logged The default handler is fn(_) -> Ok(Nil), which will do nothing if handler returns an error

pub fn with_session_settings(
  builder: TelegaBuilder(a, b),
  persist_session persist_session: fn(String, a) -> Result(a, b),
  get_session get_session: fn(String) -> Result(Option(a), b),
  default_session default_session: fn() -> a,
) -> TelegaBuilder(a, b)

Construct a session settings.

Search Document