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.
-
The command arguments, if any.
pub type CommandContext {
CommandContext(message: Message, bot: Bot, command: Command)
}
Constructors
-
CommandContext(message: Message, bot: Bot, command: Command)
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(
handler: fn(CommandContext) -> Result(Nil, Nil),
command: String,
)
HandleCommands(
handler: fn(CommandContext) -> Result(Nil, Nil),
commands: List(String),
)
HandleText(handler: fn(Context) -> Result(Nil, Nil))
}
Constructors
-
HandleAll(handler: fn(Context) -> Result(Nil, Nil))
Handle all messages.
-
HandleCommand( handler: fn(CommandContext) -> Result(Nil, Nil), command: String, )
Handle a specific command.
-
HandleCommands( handler: fn(CommandContext) -> Result(Nil, Nil), commands: List(String), )
Handle multiple commands.
-
HandleText(handler: fn(Context) -> Result(Nil, Nil))
Handle text messages.
Functions
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: Context, text: String) -> Result(Message, Nil)
Use this method to send text messages.
pub fn set_webhook(bot: Bot) -> Result(Bool, String)
Set the webhook URL using setWebhook API.