NAME

Perlgram - Comprehensive Perl interface to the Telegram Bot API

VERSION

Version 0.02

SYNOPSIS

use Perlgram;
my $bot = Perlgram->new(token => 'YOUR_BOT_TOKEN');
my $user = $bot->getMe();
print "Bot username: $user->{username}\n";

# Send a message with a reply keyboard
$bot->sendMessage(
    chat_id => 123456789,
    text    => 'Choose an option',
    reply_markup => {
        keyboard => [[{ text => 'Option 1' }], [{ text => 'Option 2' }]],
        one_time_keyboard => JSON::true,
    },
);

DESCRIPTION

Perlgram is a Perl module for interacting with the Telegram Bot API. It supports all major API methods, including messaging, inline queries, payments, stickers, and games. The module can operate in webhook (real-time updates via HTTPS) or CLI (polling via getUpdates) modes, making it suitable for both production and development environments.

This module is designed to be CPAN-compliant and can be installed via cpan or cpanm. It includes scripts for running bots and examples for quick setup.

METHODS

See the Telegram Bot API documentation (https://core.telegram.org/bots/api) for parameter details.

new(token => $token, [api_url => $url])

Creates a new bot instance. Requires a bot token from @BotFather.

getMe, logOut, close

General bot methods.

getUpdates, setWebhook, deleteWebhook, getWebhookInfo

Update-related methods.

sendMessage, sendPhoto, sendAudio, sendDocument, sendVideo, sendAnimation, sendVoice, sendVideoNote, sendMediaGroup, sendLocation, sendVenue, sendContact, sendPoll, sendDice, sendChatAction

Messaging methods.

answerInlineQuery, answerWebAppQuery

Inline mode methods.

editMessageText, editMessageCaption, editMessageMedia, editMessageReplyMarkup, stopPoll, deleteMessage

Message editing methods.

banChatMember, unbanChatMember, restrictChatMember, promoteChatMember, setChatPermissions, exportChatInviteLink, getChat, getChatAdministrators

Chat management methods.

answerCallbackQuery

Callback query handling.

sendInvoice, answerShippingQuery, answerPreCheckoutQuery

Payment methods.

sendSticker, getStickerSet, createNewStickerSet

Sticker methods.

sendGame, setGameScore, getGameHighScores

Game methods.

setMyCommands, getMyCommands

Bot command methods.

DEPENDENCIES

  • LWP::UserAgent

  • JSON

  • Mojolicious (for webhook mode)

  • Log::Log4perl

INSTALLATION

To install via CPAN:

cpan Perlgram

Or, clone from GitHub and build manually:

git clone https://github.com/AmiRCandy/Perlgram.git
cd Perlgram
perl Makefile.PL
make
make test
make install

AUTHOR

AmiRCandy, <amirhosen.1385.cmo@gmail.com>

BUGS

Please report bugs to the GitHub issue tracker: https://github.com/AmiRCandy/Perlgram/issues

LICENSE

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.

SEE ALSO

https://core.telegram.org/bots/api, Perlgram::Webhook, Perlgram::CLI