NAME
Mojar::Message::Telegram - Send messages via Telegram.
SYNOPSIS
use Mojar::Message::Telegram;
my $msg = Mojar::Message::Telegram->new(message => ..., recipient => ...);
# Synchronous
$msg->send(
message => q{Don't you love the bot API? \N{U+2714} },
recipient => '111222333',
);
# Asynchronous
my @error;
$sms->send(
message => q{Fire and forget; with a reminder},
recipient => '111222333',
sub { $error[0] = $_[1] }
);
DESCRIPTION
Sends simple messages via Telegram. You need to know the chat_id
of each recipient, and they must have initiated some interaction with your bot beforehand.
ATTRIBUTES
address
$msg->address; # defaults to api.telegram.org $msg->address('somewhere.web.telegram.org');
token
$msg->token('123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11');
ua
$msg->ua($this_agent); my $ua = $msg->ua;
The user agent persists in an attribute of the object and you can supply your own at creation time.
METHODS
- new
-
$msg = Mojar::Message::Telegram->new(token => ...);
Constructor for the Telegram agent.
- send
-
$msg->send(message => q{...}, recipient => $recipient);
Supports method chaining, and will bail-out at the first failure if no callback is given. Supports asynchronous calls when provided a callback as the final argument.
$msg->send(message => q{...}, recipient => ..., sub { my ($agent, $error) = @_; ... }); $sms->send(message => $m, recipient => $r, sub { ++$error_count if $_[1] });
You can also send messages without triggering a notification by including the
quiet =
1> parameter.
REFERENCE
https://core.telegram.org/bots/api shows the Bot API.
CONFIGURATION AND ENVIRONMENT
You need to create an account following https://core.telegram.org/bots.
SUPPORT
See Mojar.