telega
Types
pub opaque type TelegaBuilder(session, error)
Values
pub fn get_api_config(
telega: Telega(session, error),
) -> client.TelegramClient
Helper to get the config for API requests.
pub fn handle_all(
bot builder: TelegaBuilder(session, error),
handler handler: fn(bot.Context(session, error), update.Update) -> Result(
bot.Context(session, error),
error,
),
) -> TelegaBuilder(session, error)
Handles all messages.
pub fn handle_audio(
bot builder: TelegaBuilder(session, error),
handler handler: fn(bot.Context(session, error), model.Audio) -> Result(
bot.Context(session, error),
error,
),
) -> TelegaBuilder(session, error)
Handles audio messages.
pub fn handle_callback_query(
bot builder: TelegaBuilder(session, error),
filter filter: bot.CallbackQueryFilter,
handler handler: fn(bot.Context(session, error), String, String) -> Result(
bot.Context(session, error),
error,
),
) -> TelegaBuilder(session, error)
Handles messages from inline keyboard callback.
See conversation
pub fn handle_chat_member(
bot builder: TelegaBuilder(session, error),
handler handler: fn(
bot.Context(session, error),
model.ChatMemberUpdated,
) -> Result(bot.Context(session, error), error),
) -> TelegaBuilder(session, error)
Handles chat member update (when user joins/leaves a group). The bot must be an administrator in the chat and must explicitly specify “chat_member” in the list of allowed_updates
to receive these updates.
pub fn handle_command(
bot builder: TelegaBuilder(session, error),
command command: String,
handler handler: fn(bot.Context(session, error), update.Command) -> Result(
bot.Context(session, error),
error,
),
) -> TelegaBuilder(session, error)
Handles a specific command.
pub fn handle_commands(
bot builder: TelegaBuilder(session, error),
commands commands: List(String),
handler handler: fn(bot.Context(session, error), update.Command) -> Result(
bot.Context(session, error),
error,
),
) -> TelegaBuilder(session, error)
Handles multiple commands.
pub fn handle_hears(
bot builder: TelegaBuilder(session, error),
hears hears: bot.Hears,
handler handler: fn(bot.Context(session, error), String) -> Result(
bot.Context(session, error),
error,
),
) -> TelegaBuilder(session, error)
Handles messages that match the given Hears
.
pub fn handle_message(
bot builder: TelegaBuilder(session, error),
handler handler: fn(bot.Context(session, error), model.Message) -> Result(
bot.Context(session, error),
error,
),
) -> TelegaBuilder(session, error)
Handles any message.
pub fn handle_photos(
bot builder: TelegaBuilder(session, error),
handler handler: fn(
bot.Context(session, error),
List(model.PhotoSize),
) -> Result(bot.Context(session, error), error),
) -> TelegaBuilder(session, error)
Handles photo messages.
pub fn handle_text(
bot builder: TelegaBuilder(session, error),
handler handler: fn(bot.Context(session, error), String) -> Result(
bot.Context(session, error),
error,
),
) -> TelegaBuilder(session, error)
Handles text messages.
pub fn handle_update(
telega: Telega(session, error),
raw_update: model.Update,
) -> Result(Bool, error.TelegaError)
Handle an update from the Telegram API.
pub fn handle_video(
bot builder: TelegaBuilder(session, error),
handler handler: fn(bot.Context(session, error), model.Video) -> Result(
bot.Context(session, error),
error,
),
) -> TelegaBuilder(session, error)
Handles video messages.
pub fn handle_voice(
bot builder: TelegaBuilder(session, error),
handler handler: fn(bot.Context(session, error), model.Voice) -> Result(
bot.Context(session, error),
error,
),
) -> TelegaBuilder(session, error)
Handles voice messages.
pub fn handle_web_app_data(
bot builder: TelegaBuilder(session, error),
handler handler: fn(
bot.Context(session, error),
model.WebAppData,
) -> Result(bot.Context(session, error), error),
) -> TelegaBuilder(session, error)
Handles web app data messages.
pub fn init(
builder: TelegaBuilder(session, error),
) -> Result(Telega(session, error), error.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, error),
) -> Result(Telega(Nil, error), error.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(session, error),
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(session, error),
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: bot.Context(session, error),
prefix prefix: String,
handler handler: fn() -> Result(
bot.Context(session, error),
error,
),
) -> Result(bot.Context(session, error), error)
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.Option(String),
) -> TelegaBuilder(a, b)
Create a new Telega instance.
pub fn set_allowed_updates(
builder: TelegaBuilder(session, error),
allowed_updates: List(String),
) -> TelegaBuilder(session, error)
Set the allowed updates as set webhook parameter.
pub fn set_api_client(
builder: TelegaBuilder(session, error),
api_client: client.TelegramClient,
) -> TelegaBuilder(session, error)
Pass custom api client to the builder.
Useful if you want set custom fetch function or pass your api client options
pub fn set_certificate(
builder: TelegaBuilder(session, error),
certificate: model.File,
) -> TelegaBuilder(session, error)
Set the certificate as set webhook parameter.
pub fn set_drop_pending_updates(
builder: TelegaBuilder(session, error),
drop_pending_updates: Bool,
) -> TelegaBuilder(session, error)
Set the drop pending updates flag as set webhook parameter.
pub fn set_ip_address(
builder: TelegaBuilder(session, error),
ip_address: String,
) -> TelegaBuilder(session, error)
Set the ip address as set webhook parameter.
pub fn set_max_connections(
builder: TelegaBuilder(session, error),
max_connections: Int,
) -> TelegaBuilder(session, error)
Set the max connections as set webhook parameter.
pub fn wait_any(
ctx ctx: bot.Context(session, error),
or handle_else: option.Option(bot.Handler(session, error)),
timeout timeout: option.Option(Int),
continue handler: fn(bot.Context(session, error), update.Update) -> Result(
bot.Context(session, error),
error,
),
) -> Result(bot.Context(session, error), error)
Stops bot message handling from current chat and waits for any message.
See conversation
pub fn wait_audio(
ctx ctx: bot.Context(session, error),
or handle_else: option.Option(bot.Handler(session, error)),
timeout timeout: option.Option(Int),
continue continue: fn(bot.Context(session, error), model.Audio) -> Result(
bot.Context(session, error),
error,
),
) -> Result(bot.Context(session, error), error)
Stops bot message handling from current chat and waits for an audio message.
See conversation
pub fn wait_callback_query(
ctx ctx: bot.Context(session, error),
filter filter: bot.CallbackQueryFilter,
or handle_else: option.Option(bot.Handler(session, error)),
timeout timeout: option.Option(Int),
continue continue: fn(
bot.Context(session, error),
String,
String,
) -> Result(bot.Context(session, error), error),
) -> Result(bot.Context(session, error), error)
Wait for a callback query and continue with the given function.
See conversation
pub fn wait_command(
ctx ctx: bot.Context(session, error),
command command: String,
or handle_else: option.Option(bot.Handler(session, error)),
timeout timeout: option.Option(Int),
continue continue: fn(
bot.Context(session, error),
update.Command,
) -> Result(bot.Context(session, error), error),
) -> Result(bot.Context(session, error), error)
Stops bot message handling from current chat and waits for a specific command.
See conversation
pub fn wait_commands(
ctx ctx: bot.Context(session, error),
commands commands: List(String),
or handle_else: option.Option(bot.Handler(session, error)),
timeout timeout: option.Option(Int),
continue continue: fn(
bot.Context(session, error),
update.Command,
) -> Result(bot.Context(session, error), error),
) -> Result(bot.Context(session, error), error)
Stops bot message handling from current chat and waits for a specific command.
See conversation
pub fn wait_hears(
ctx ctx: bot.Context(session, error),
hears hears: bot.Hears,
or handle_else: option.Option(bot.Handler(session, error)),
timeout timeout: option.Option(Int),
continue continue: fn(bot.Context(session, error), String) -> Result(
bot.Context(session, error),
error,
),
) -> Result(bot.Context(session, error), error)
Stops bot message handling from current chat and waits for a message that matches the given Hears
.
See conversation
pub fn wait_message(
ctx ctx: bot.Context(session, error),
or handle_else: option.Option(bot.Handler(session, error)),
timeout timeout: option.Option(Int),
continue continue: fn(
bot.Context(session, error),
model.Message,
) -> Result(bot.Context(session, error), error),
) -> Result(bot.Context(session, error), error)
Stops bot message handling from current chat and waits for any message.
See conversation
pub fn wait_photos(
ctx ctx: bot.Context(session, error),
or handle_else: option.Option(bot.Handler(session, error)),
timeout timeout: option.Option(Int),
continue continue: fn(
bot.Context(session, error),
List(model.PhotoSize),
) -> Result(bot.Context(session, error), error),
) -> Result(bot.Context(session, error), error)
Stops bot message handling from current chat and waits for a photo message.
See conversation
pub fn wait_text(
ctx ctx: bot.Context(session, error),
or handle_else: option.Option(bot.Handler(session, error)),
timeout timeout: option.Option(Int),
continue continue: fn(bot.Context(session, error), String) -> Result(
bot.Context(session, error),
error,
),
) -> Result(bot.Context(session, error), error)
Stops bot message handling from current chat and waits for a text message.
See conversation
pub fn wait_video(
ctx ctx: bot.Context(session, error),
or handle_else: option.Option(bot.Handler(session, error)),
timeout timeout: option.Option(Int),
continue continue: fn(bot.Context(session, error), model.Video) -> Result(
bot.Context(session, error),
error,
),
) -> Result(bot.Context(session, error), error)
Stops bot message handling from current chat and waits for a video message.
See conversation
pub fn wait_voice(
ctx ctx: bot.Context(session, error),
or handle_else: option.Option(bot.Handler(session, error)),
timeout timeout: option.Option(Int),
continue continue: fn(bot.Context(session, error), model.Voice) -> Result(
bot.Context(session, error),
error,
),
) -> Result(bot.Context(session, error), error)
Stops bot message handling from current chat and waits for a voice message.
See conversation
pub fn wait_web_app_data(
ctx ctx: bot.Context(session, error),
or handle_else: option.Option(bot.Handler(session, error)),
timeout timeout: option.Option(Int),
continue continue: fn(
bot.Context(session, error),
model.WebAppData,
) -> Result(bot.Context(session, error), error),
) -> Result(bot.Context(session, error), error)
Stops bot message handling from current chat and waits for a web app data message.
See conversation
pub fn with_catch_handler(
builder builder: TelegaBuilder(session, error),
catch_handler catch_handler: fn(
bot.Context(session, error),
error,
) -> Result(Nil, error),
) -> TelegaBuilder(session, error)
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(session, error),
persist_session persist_session: fn(String, session) -> Result(
session,
error,
),
get_session get_session: fn(String) -> Result(
option.Option(session),
error,
),
default_session default_session: fn() -> session,
) -> TelegaBuilder(session, error)
Construct a session settings.