telega

Types

An optional string to compare to X-Telegram-Bot-Api-Secret-Token

pub type Bot {
  Bot(config: Config, handlers: List(Handler))
}

Constructors

  • Bot(config: Config, handlers: List(Handler))
pub type Command {
  Command(text: String, command: String, payload: Option(String))
}

Constructors

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

    Arguments

    • payload

      The command arguments, if any.

Command handlers context.

pub type CommandContext {
  CommandContext(ctx: Context, command: Command)
}

Constructors

  • CommandContext(ctx: Context, command: Command)
pub opaque type Config

Handlers context.

pub type Context {
  Context(message: Message, bot: Bot)
}

Constructors

  • Context(message: Message, bot: Bot)
pub type Handler {
  HandleAll(handler: fn(Context) -> Result(Nil, Nil))
  HandleCommand(
    command: String,
    handler: fn(CommandContext) -> Result(Nil, Nil),
  )
  HandleCommands(
    commands: List(String),
    handler: fn(CommandContext) -> Result(Nil, Nil),
  )
  HandleText(handler: fn(TextContext) -> Result(Nil, Nil))
}

Constructors

  • HandleAll(handler: fn(Context) -> Result(Nil, Nil))

    Handle all messages.

  • HandleCommand(
      command: String,
      handler: fn(CommandContext) -> Result(Nil, Nil),
    )

    Handle a specific command.

  • HandleCommands(
      commands: List(String),
      handler: fn(CommandContext) -> Result(Nil, Nil),
    )

    Handle multiple commands.

  • HandleText(handler: fn(TextContext) -> Result(Nil, Nil))

    Handle text messages.

pub type TextContext {
  TextContext(ctx: Context, text: String)
}

Constructors

  • TextContext(ctx: Context, text: String)

Functions

pub fn add_handler(bot: Bot, handler: Handler) -> Bot

Add a handler to the bot.

pub fn delete_my_commands(
  ctx: Context,
  parameters parameters: Option(BotCommandParameters),
) -> Result(Bool, String)

Use this method to delete the list of the bot’s commands for the given scope and user language. After deletion, higher level commands will be shown to affected users.

pub fn get_my_commands(
  ctx: Context,
  parameters parameters: Option(BotCommandParameters),
) -> Result(List(BotCommand), String)

Use this method to get the current list of the bot’s commands for the given scope and user language.

pub fn handle_update(bot: Bot, message: Message) -> Nil

Handle an update from the Telegram API.

pub fn is_secret_token_valid(bot: Bot, token: String) -> Bool

Check if a token is the secret token for the bot.

pub fn is_webhook_path(bot: Bot, path: String) -> Bool

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

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

Creates a new Bot with the given options.

pub fn reply(
  ctx ctx: Context,
  text text: String,
) -> Result(Message, String)

Use this method to send text messages.

pub fn send_dice(
  ctx: Context,
  parameters parameters: Option(SendDiceParameters),
) -> Result(Message, String)

Use this method to send an animated emoji that will display a random value.

pub fn set_my_commands(
  ctx ctx: Context,
  commands commands: List(BotCommand),
  parameters parameters: Option(BotCommandParameters),
) -> Result(Bool, String)

Use this method to change the list of the bot’s commands. See commands documentation for more details about bot commands. Returns True on success.

pub fn set_webhook(bot: Bot) -> Result(Bool, String)

Set the webhook URL using setWebhook API.

Search Document