Lightweight PHP wrapper library for Telegram Bot API
Bot API version: v7.10 (September 6, 2024) - Snapshot Link
- Minimal, Doesn't get in your way
- Fully documented, Employs identical names for methods and classes as those found in the official API
- Uses Guzzle as the HTTP client
- Provides type hints for IDE autocompletion
- TODO: Complete implementation of all methods and classes
- TODO: Concurrent (bulk) requests: Has been experimentally implemented for some methods
- TODO: Async requests
- TODO: Provide helper utilities (e.g. For formatting messages using HTML or Markdown) and builtin checks (e.g. Making sure the message text's length does not exceed 4096 chars)
Litegram is still in early development stages so expect bugs and non-backward compatible changes.
Use Github Issues for comments, bug reports and questions.
composer require amirrh6/litegram
require_once './vendor/autoload.php';
// --- --- --- --- --- --- ---
$token = '0123456789:...';
// --- --- --- --- --- --- ---
use Litegram\TelegramMethods;
try {
// If the request doesn't fail, an object of type Litegram\User will be returned
$res = TelegramMethods::getMe(token: $token);
var_dump('Result:', $res);
} catch (\Throwable $th) {
var_dump('Exception:', $th);
}
This file provides usage example for some primary methods.
Over a year ago, during my free time between university classes, I started working on another Telegram bot. I wanted to challenge myself by creating my own wrapper library for it. Although the bot project was eventually abandoned, I decided to revive the wrapper library, and here we are today.
* Make sure you view this section on Github rather than Packagist as it doesn't display checkmarks correctly.
Getting updates (4/4 methods implemented, 2/2 classes implemented):
Available types (34/139 classes implemented + 10 union types):
- User
- Chat
- ChatFullInfo
- Message
- MessageId
- InaccessibleMessage
- MaybeInaccessibleMessage : InaccessibleMessage | Message
- MessageEntity
- TextQuote
- ExternalReplyInfo
- ReplyParameters
- MessageOrigin
- PhotoSize
- Animation
- Audio
- Document
- Story
- Video
- VideoNote
- Voice
- PaidMediaInfo
- PaidMedia
- Contact
- Dice
- PollOption
- InputPollOption
- PollAnswer
- Poll
- Location
- Venue
- WebAppData
- ProximityAlertTriggered
- MessageAutoDeleteTimerChanged
- ChatBoostAdded
- BackgroundFill
- BackgroundFillSolid
- BackgroundFillGradient
- BackgroundFillFreeformGradient
- BackgroundType
- BackgroundTypeFill
- BackgroundTypeWallpaper
- BackgroundTypePattern
- BackgroundTypeChatTheme
- ChatBackground
- ForumTopicCreated
- ForumTopicClosed
- ForumTopicEdited
- ForumTopicReopened
- GeneralForumTopicHidden
- GeneralForumTopicUnhidden
- SharedUser
- UsersShared
- ChatShared
- WriteAccessAllowed
- VideoChatScheduled
- VideoChatStarted
- VideoChatEnded
- VideoChatParticipantsInvited
- GiveawayCreated
- Giveaway
- GiveawayWinners
- GiveawayCompleted
- LinkPreviewOptions
- UserProfilePhotos
- File
- WebAppInfo
- ReplyKeyboardMarkup
- KeyboardButton
- KeyboardButtonRequestUsers
- KeyboardButtonRequestChat
- KeyboardButtonPollType
- ReplyKeyboardRemove
- InlineKeyboardMarkup
- InlineKeyboardButton
- LoginUrl
- SwitchInlineQueryChosenChat
- CallbackQuery
- ForceReply
- ChatPhoto
- ChatInviteLink
- ChatAdministratorRights
- ChatMemberUpdated
- ChatMember
- ChatJoinRequest
- ChatPermissions
- Birthdate
- BusinessIntro
- BusinessLocation
- BusinessOpeningHoursInterval
- BusinessOpeningHours
- ChatLocation
- ReactionType
- ReactionCount
- MessageReactionUpdated
- MessageReactionCountUpdated
- ForumTopic
- BotCommand
- BotCommandScope
- BotShortDescription
- MenuButton
- ChatBoostSource
- ChatBoost
- ChatBoostUpdated
- ChatBoostRemoved
- UserChatBoosts
- BusinessConnection
- BusinessMessagesDeleted
- ResponseParameters
- InputMedia
- InputFile
- InputPaidMedia
Available methods (7/85 methods implemented):
- getMe
- logOut
- close
- sendMessage
- forwardMessage
- forwardMessages
- copyMessage *
- copyMessages
- sendPhoto
- sendAudio
- sendDocument
- sendVideo
- sendAnimation
- sendVoice
- sendVideoNote
- sendPaidMedia
- sendMediaGroup
- sendLocation
- sendVenue
- sendContact
- sendPoll
- sendDice
- sendChatAction
- setMessageReaction
- getUserProfilePhotos
- getFile
- banChatMember
- unbanChatMember
- restrictChatMember
- promoteChatMember
- setChatAdministratorCustomTitle
- banChatSenderChat
- unbanChatSenderChat
- setChatPermissions
- exportChatInviteLink
- createChatInviteLink
- editChatInviteLink
- createChatSubscriptionInviteLink
- editChatSubscriptionInviteLink
- revokeChatInviteLink
- approveChatJoinRequest
- declineChatJoinRequest
- setChatPhoto
- deleteChatPhoto
- setChatTitle
- setChatDescription
- pinChatMessage
- unpinChatMessage
- unpinAllChatMessages
- leaveChat
- getChat
- getChatAdministrators
- getChatMemberCount
- getChatMember
- setChatStickerSet
- deleteChatStickerSet
- getForumTopicIconStickers
- createForumTopic
- editForumTopic
- closeForumTopic
- reopenForumTopic
- deleteForumTopic
- unpinAllForumTopicMessages
- editGeneralForumTopic
- closeGeneralForumTopic
- reopenGeneralForumTopic
- hideGeneralForumTopic
- unhideGeneralForumTopic
- unpinAllGeneralForumTopicMessages
- answerCallbackQuery
- getUserChatBoosts
- getBusinessConnection
- setMyCommands
- deleteMyCommands
- getMyCommands
- setMyName
- getMyName
- setMyDescription
- getMyDescription
- setMyShortDescription
- getMyShortDescription
- setChatMenuButton
- getChatMenuButton
- setMyDefaultAdministratorRights
- getMyDefaultAdministratorRights
* Experimental bulk (concurrent) version is available. These methods are named like this: copyMessage()
---> _bulkCopyMessage()
Updating messages (1/9 methods implemented):
- editMessageText
- editMessageCaption
- editMessageMedia
- editMessageLiveLocation
- stopMessageLiveLocation
- editMessageReplyMarkup
- stopPoll
- deleteMessage
- deleteMessages
Stickers (0/16 methods implemented, 0/4 classes implemented):
- Sticker
- StickerSet
- MaskPosition
- InputSticker
- sendSticker
- getStickerSet
- getCustomEmojiStickers
- uploadStickerFile
- createNewStickerSet
- addStickerToSet
- setStickerPositionInSet
- deleteStickerFromSet
- replaceStickerInSet
- setStickerEmojiList
- setStickerKeywords
- setStickerMaskPosition
- setStickerSetTitle
- setStickerSetThumbnail
- setCustomEmojiStickerSetThumbnail
- deleteStickerSet
Inline mode (0/2 methods implemented, 3/29 classes implemented + 2 union types):
- InlineQuery
- answerInlineQuery
- InlineQueryResultsButton
- InlineQueryResult
- InputMessageContent
- ChosenInlineResult
- answerWebAppQuery
- SentWebAppMessage
Payments (0/6 methods implemented, 3/19 classes implemented + 2 union types):
- sendInvoice
- createInvoiceLink
- answerShippingQuery
- answerPreCheckoutQuery
- getStarTransactions
- refundStarPayment
- LabeledPrice
- Invoice
- ShippingAddress
- OrderInfo
- ShippingOption
- SuccessfulPayment
- RefundedPayment
- ShippingQuery
- PreCheckoutQuery
- PaidMediaPurchased
- RevenueWithdrawalState
- TransactionPartner
- StarTransaction
- StarTransactions
Telegram Passport (0/1 methods implemented, 0/13 classes implemented + 1 union type):
- PassportData
- PassportFile
- EncryptedPassportElement
- EncryptedCredentials
- setPassportDataErrors
- PassportElementError
Games (0/3 methods implemented, 0/3 classes implemented):