telega

Types

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

Functions

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

Handles all messages.

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

Handles messages from inline keyboard callback.

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

Handles a specific command.

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

Handles multiple commands.

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

Handles messages that match the given Hears.

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

Handles text messages.

pub fn handle_update(
  telega: Telega(a),
  update: Update,
) -> 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 wait_any(
  ctx ctx: Context(a),
  continue continue: fn(Context(a)) -> Result(a, String),
) -> Result(a, String)

Stops bot message handling and waits for any message.

pub fn wait_callback_query(
  ctx ctx: Context(a),
  filter filter: CallbackQueryFilter,
  continue continue: fn(Context(a), String, String) ->
    Result(a, String),
) -> Result(a, String)
pub fn wait_command(
  ctx ctx: Context(a),
  command command: String,
  continue continue: fn(Context(a), Command) -> Result(a, String),
) -> Result(a, String)
pub fn wait_commands(
  ctx ctx: Context(a),
  commands commands: List(String),
  continue continue: fn(Context(a), Command) -> Result(a, String),
) -> Result(a, String)
pub fn wait_hears(
  ctx ctx: Context(a),
  hears hears: Hears,
  continue continue: fn(Context(a), String) -> Result(a, String),
) -> Result(a, String)
pub fn wait_text(
  ctx ctx: Context(a),
  continue continue: fn(Context(a), String) -> Result(a, String),
) -> Result(a, String)
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),
) -> TelegaBuilder(a)

Construct a session settings.

Search Document