NAME
Telebot::Plugin::Telegram - Telegram API plugin
SYNOPSIS
# {
# message => 'Telebot::Handler::Message',
# poll => 'My::Bot::Handler::Poll',
# }
my $handlers = $app->tg->handlers();
# 'Telebot::Handler::Message'
my $message_handler = $app->tg->handler('message');
# 'z8HcRt7Z6wj3E7bwk2pOZx4s'
my $token = $app->tg->gentoken();
# 'https://api.telegram.org/botTOKEN/getMe'
my $url = $app->tg->url('getMe');
# Requests to API
my $response = $app->tg->request(getMe => {});
my $response = $app->tg->request(sendMessage => {
chat_id => 777,
text => 'Hello, Telegram',
});
# c('message', 'poll')
my $allowed_updates = $app->tg->allowed_updates;
# c({
# command => 'start',
# bot => 'megabot',
# }, {
# command => 'stop',
# bot => undef,
# })
$app->tg->extract_commands(
'Please /start@megabot and /stop',
[{
type => 'command',
offset => 7,
length => 14,
}, {
type => 'command',
offset => 26,
length => 5,
}]
);
DESCRIPTION
Telebot::Plugin::Telegram - plugin for working with Telegram API.
HELPERS
Telebot::Plugin::Telegram implements the following helpers.
tg->handlers
Returns hash of registered handlers of update and it's parts. Key - update or name of update field, value - name of handler module.
tg->handler
Returns name of handler module for update or update part.
tg->gentoken
Returns generated token (random string from alphabet symbols and digits)
tg->url
Returns URL for requesting Telegram API method
tg->request
Performs request to Telegram API
tg->allowed_updates
Return Mojo::Collection of allowed updates (set of updates which Telegram sends to bot's webhook).
tg->extract_commands
Extract from text bot commands and return them as Mojo::Collection
tg->config
Returns config of plugin.
METHODS
Telebot::Plugin::Telegram inherits all methods from Mojolicious::Plugin and implements the following new ones.
register
my $tg = $plugin->register(Mojolicious->new);
Register plugin in Mojolicious application and define helpers.
COPYRIGHT AND LICENSE
Copyright (C) 2022, Igor Lobanov. This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.
SEE ALSO
https://github.com/igorlobanov/telebot, Mojolicious::Guides, https://mojolicious.org, https://core.telegram.org/bots/api.