tgram package¶
Subpackages¶
- tgram.bound package
- Submodules
- tgram.bound.callback_query module
- tgram.bound.message module
MessageB
MessageB.copy()
MessageB.delete()
MessageB.download()
MessageB.edit()
MessageB.edit_caption()
MessageB.edit_live_location()
MessageB.edit_media()
MessageB.edit_reply_markup()
MessageB.edit_text()
MessageB.file_id
MessageB.forward()
MessageB.id
MessageB.link
MessageB.media
MessageB.react()
MessageB.reply()
MessageB.reply_animation()
MessageB.reply_audio()
MessageB.reply_chat_action()
MessageB.reply_contact()
MessageB.reply_dice()
MessageB.reply_document()
MessageB.reply_game()
MessageB.reply_invoice()
MessageB.reply_location()
MessageB.reply_media_from_file_id()
MessageB.reply_media_group()
MessageB.reply_paid_media()
MessageB.reply_photo()
MessageB.reply_sticker()
MessageB.reply_text()
MessageB.reply_video()
MessageB.reply_video_note()
MessageB.reply_voice()
MessageB.sender_user
MessageB.service
MessageB.user
- tgram.bound.user module
- Module contents
CallbackB
ChatB
ChatJoinRequestB
ChatMemberUpdatedB
ChosenInlineResultB
InlineQueryB
MessageB
MessageB.copy()
MessageB.delete()
MessageB.download()
MessageB.edit()
MessageB.edit_caption()
MessageB.edit_live_location()
MessageB.edit_media()
MessageB.edit_reply_markup()
MessageB.edit_text()
MessageB.file_id
MessageB.forward()
MessageB.id
MessageB.link
MessageB.media
MessageB.react()
MessageB.reply()
MessageB.reply_animation()
MessageB.reply_audio()
MessageB.reply_chat_action()
MessageB.reply_contact()
MessageB.reply_dice()
MessageB.reply_document()
MessageB.reply_game()
MessageB.reply_invoice()
MessageB.reply_location()
MessageB.reply_media_from_file_id()
MessageB.reply_media_group()
MessageB.reply_paid_media()
MessageB.reply_photo()
MessageB.reply_sticker()
MessageB.reply_text()
MessageB.reply_video()
MessageB.reply_video_note()
MessageB.reply_voice()
MessageB.sender_user
MessageB.service
MessageB.user
PaidMediaPurchasedB
PreCheckoutQueryB
ShippingQueryB
UserB
- tgram.decorators package
- Submodules
- tgram.decorators.on_all module
- tgram.decorators.on_business_connection module
- tgram.decorators.on_business_message module
- tgram.decorators.on_callback_query module
- tgram.decorators.on_channel_post module
- tgram.decorators.on_chat_boost module
- tgram.decorators.on_chat_join_request module
- tgram.decorators.on_chat_member module
- tgram.decorators.on_chosen_inline_result module
- tgram.decorators.on_deleted_business_messages module
- tgram.decorators.on_edited_business_message module
- tgram.decorators.on_edited_channel_post module
- tgram.decorators.on_edited_message module
- tgram.decorators.on_inline_query module
- tgram.decorators.on_message module
- tgram.decorators.on_message_reaction module
- tgram.decorators.on_message_reaction_count module
- tgram.decorators.on_my_chat_member module
- tgram.decorators.on_poll module
- tgram.decorators.on_poll_answer module
- tgram.decorators.on_pre_checkout_query module
- tgram.decorators.on_removed_chat_boost module
- tgram.decorators.on_shipping_query module
- Module contents
- tgram.methods package
- Submodules
- tgram.methods.add_sticker_to_set module
- tgram.methods.answer_callback_query module
- tgram.methods.answer_inline_query module
- tgram.methods.answer_pre_checkout_query module
- tgram.methods.answer_shipping_query module
- tgram.methods.answer_web_app_query module
- tgram.methods.approve_chat_join_request module
- tgram.methods.ask module
- tgram.methods.ban_chat_member module
- tgram.methods.ban_chat_sender_chat module
- tgram.methods.close module
- tgram.methods.close_forum_topic module
- tgram.methods.close_general_forum_topic module
- tgram.methods.copy_message module
- tgram.methods.copy_messages module
- tgram.methods.create_chat_invite_link module
- tgram.methods.create_forum_topic module
- tgram.methods.create_invoice_link module
- tgram.methods.create_new_sticker_set module
- tgram.methods.decline_chat_join_request module
- tgram.methods.delete_chat_photo module
- tgram.methods.delete_chat_sticker_set module
- tgram.methods.delete_forum_topic module
- tgram.methods.delete_message module
- tgram.methods.delete_messages module
- tgram.methods.delete_my_commands module
- tgram.methods.delete_sticker_from_set module
- tgram.methods.delete_sticker_set module
- tgram.methods.delete_webhook module
- tgram.methods.download_file module
- tgram.methods.edit_chat_invite_link module
- tgram.methods.edit_forum_topic module
- tgram.methods.edit_general_forum_topic module
- tgram.methods.edit_message_caption module
- tgram.methods.edit_message_live_location module
- tgram.methods.edit_message_media module
- tgram.methods.edit_message_reply_markup module
- tgram.methods.edit_message_text module
- tgram.methods.export_chat_invite_link module
- tgram.methods.forward_message module
- tgram.methods.forward_messages module
- tgram.methods.get_business_connection module
- tgram.methods.get_chat module
- tgram.methods.get_chat_administrators module
- tgram.methods.get_chat_member module
- tgram.methods.get_chat_member_count module
- tgram.methods.get_chat_menu_button module
- tgram.methods.get_custom_emoji_stickers module
- tgram.methods.get_file module
- tgram.methods.get_file_url module
- tgram.methods.get_forum_topic_icon_stickers module
- tgram.methods.get_game_high_scores module
- tgram.methods.get_me module
- tgram.methods.get_my_commands module
- tgram.methods.get_my_default_administrator_rights module
- tgram.methods.get_my_description module
- tgram.methods.get_my_name module
- tgram.methods.get_my_short_description module
- tgram.methods.get_star_transactions module
- tgram.methods.get_sticker_set module
- tgram.methods.get_updates module
- tgram.methods.get_user_chat_boosts module
- tgram.methods.get_user_profile_photos module
- tgram.methods.get_webhook_info module
- tgram.methods.hide_general_forum_topic module
- tgram.methods.leave_chat module
- tgram.methods.log_out module
- tgram.methods.pin_chat_message module
- tgram.methods.promote_chat_member module
- tgram.methods.refund_star_payment module
- tgram.methods.reopen_forum_topic module
- tgram.methods.reopen_general_forum_topic module
- tgram.methods.replace_sticker_in_set module
- tgram.methods.restrict_chat_member module
- tgram.methods.revoke_chat_invite_link module
- tgram.methods.send_animation module
- tgram.methods.send_audio module
- tgram.methods.send_chat_action module
- tgram.methods.send_contact module
- tgram.methods.send_dice module
- tgram.methods.send_document module
- tgram.methods.send_game module
- tgram.methods.send_invoice module
- tgram.methods.send_location module
- tgram.methods.send_media_from_file_id module
- tgram.methods.send_media_group module
- tgram.methods.send_message module
- tgram.methods.send_paid_media module
- tgram.methods.send_photo module
- tgram.methods.send_poll module
- tgram.methods.send_sticker module
- tgram.methods.send_venue module
- tgram.methods.send_video module
- tgram.methods.send_video_note module
- tgram.methods.send_voice module
- tgram.methods.set_chat_administrator_custom_title module
- tgram.methods.set_chat_description module
- tgram.methods.set_chat_menu_button module
- tgram.methods.set_chat_permissions module
- tgram.methods.set_chat_photo module
- tgram.methods.set_chat_sticker_set module
- tgram.methods.set_chat_title module
- tgram.methods.set_custom_emoji_sticker_set_thumbnail module
- tgram.methods.set_game_score module
- tgram.methods.set_message_reaction module
- tgram.methods.set_my_commands module
- tgram.methods.set_my_default_administrator_rights module
- tgram.methods.set_my_description module
- tgram.methods.set_my_name module
- tgram.methods.set_my_short_description module
- tgram.methods.set_passport_data_errors module
- tgram.methods.set_sticker_emoji_list module
- tgram.methods.set_sticker_keywords module
- tgram.methods.set_sticker_mask_position module
- tgram.methods.set_sticker_position_in_set module
- tgram.methods.set_sticker_set_thumbnail module
- tgram.methods.set_sticker_set_title module
- tgram.methods.set_webhook module
- tgram.methods.stop_message_live_location module
- tgram.methods.stop_poll module
- tgram.methods.unban_chat_member module
- tgram.methods.unban_chat_sender_chat module
- tgram.methods.unhide_general_forum_topic module
- tgram.methods.unpin_all_chat_messages module
- tgram.methods.unpin_all_forum_topic_messages module
- tgram.methods.unpin_all_general_forum_topic_messages module
- tgram.methods.unpin_chat_message module
- tgram.methods.upload_sticker_file module
- Module contents
TelegramBotMethods
TelegramBotMethods.add_sticker_to_set()
TelegramBotMethods.answer_callback_query()
TelegramBotMethods.answer_inline_query()
TelegramBotMethods.answer_pre_checkout_query()
TelegramBotMethods.answer_shipping_query()
TelegramBotMethods.answer_web_app_query()
TelegramBotMethods.approve_chat_join_request()
TelegramBotMethods.ask()
TelegramBotMethods.ban_chat_member()
TelegramBotMethods.ban_chat_sender_chat()
TelegramBotMethods.close()
TelegramBotMethods.close_forum_topic()
TelegramBotMethods.close_general_forum_topic()
TelegramBotMethods.copy_message()
TelegramBotMethods.copy_messages()
TelegramBotMethods.create_chat_invite_link()
TelegramBotMethods.create_chat_subscription_invite_link()
TelegramBotMethods.create_forum_topic()
TelegramBotMethods.create_invoice_link()
TelegramBotMethods.create_new_sticker_set()
TelegramBotMethods.decline_chat_join_request()
TelegramBotMethods.delete_chat_photo()
TelegramBotMethods.delete_chat_sticker_set()
TelegramBotMethods.delete_forum_topic()
TelegramBotMethods.delete_message()
TelegramBotMethods.delete_messages()
TelegramBotMethods.delete_my_commands()
TelegramBotMethods.delete_sticker_from_set()
TelegramBotMethods.delete_sticker_set()
TelegramBotMethods.delete_webhook()
TelegramBotMethods.download_file()
TelegramBotMethods.edit_chat_invite_link()
TelegramBotMethods.edit_chat_subscription_invite_link()
TelegramBotMethods.edit_forum_topic()
TelegramBotMethods.edit_general_forum_topic()
TelegramBotMethods.edit_message_caption()
TelegramBotMethods.edit_message_live_location()
TelegramBotMethods.edit_message_media()
TelegramBotMethods.edit_message_reply_markup()
TelegramBotMethods.edit_message_text()
TelegramBotMethods.edit_user_star_subscription()
TelegramBotMethods.export_chat_invite_link()
TelegramBotMethods.forward_message()
TelegramBotMethods.forward_messages()
TelegramBotMethods.get_available_gifts()
TelegramBotMethods.get_business_connection()
TelegramBotMethods.get_chat()
TelegramBotMethods.get_chat_administrators()
TelegramBotMethods.get_chat_member()
TelegramBotMethods.get_chat_member_count()
TelegramBotMethods.get_chat_menu_button()
TelegramBotMethods.get_custom_emoji_stickers()
TelegramBotMethods.get_file()
TelegramBotMethods.get_file_url()
TelegramBotMethods.get_forum_topic_icon_stickers()
TelegramBotMethods.get_game_high_scores()
TelegramBotMethods.get_me()
TelegramBotMethods.get_my_commands()
TelegramBotMethods.get_my_default_administrator_rights()
TelegramBotMethods.get_my_description()
TelegramBotMethods.get_my_name()
TelegramBotMethods.get_my_short_description()
TelegramBotMethods.get_star_transactions()
TelegramBotMethods.get_sticker_set()
TelegramBotMethods.get_updates()
TelegramBotMethods.get_user_chat_boosts()
TelegramBotMethods.get_user_profile_photos()
TelegramBotMethods.get_webhook_info()
TelegramBotMethods.hide_general_forum_topic()
TelegramBotMethods.leave_chat()
TelegramBotMethods.log_out()
TelegramBotMethods.pin_chat_message()
TelegramBotMethods.promote_chat_member()
TelegramBotMethods.refund_star_payment()
TelegramBotMethods.reopen_forum_topic()
TelegramBotMethods.reopen_general_forum_topic()
TelegramBotMethods.replace_sticker_in_set()
TelegramBotMethods.restrict_chat_member()
TelegramBotMethods.revoke_chat_invite_link()
TelegramBotMethods.run()
TelegramBotMethods.save_prepared_inline_message()
TelegramBotMethods.send_animation()
TelegramBotMethods.send_audio()
TelegramBotMethods.send_chat_action()
TelegramBotMethods.send_contact()
TelegramBotMethods.send_dice()
TelegramBotMethods.send_document()
TelegramBotMethods.send_game()
TelegramBotMethods.send_gift()
TelegramBotMethods.send_invoice()
TelegramBotMethods.send_location()
TelegramBotMethods.send_media_from_file_id()
TelegramBotMethods.send_media_group()
TelegramBotMethods.send_message()
TelegramBotMethods.send_paid_media()
TelegramBotMethods.send_photo()
TelegramBotMethods.send_poll()
TelegramBotMethods.send_sticker()
TelegramBotMethods.send_venue()
TelegramBotMethods.send_video()
TelegramBotMethods.send_video_note()
TelegramBotMethods.send_voice()
TelegramBotMethods.set_chat_administrator_custom_title()
TelegramBotMethods.set_chat_description()
TelegramBotMethods.set_chat_menu_button()
TelegramBotMethods.set_chat_permissions()
TelegramBotMethods.set_chat_photo()
TelegramBotMethods.set_chat_sticker_set()
TelegramBotMethods.set_chat_title()
TelegramBotMethods.set_custom_emoji_sticker_set_thumbnail()
TelegramBotMethods.set_game_score()
TelegramBotMethods.set_message_reaction()
TelegramBotMethods.set_my_commands()
TelegramBotMethods.set_my_default_administrator_rights()
TelegramBotMethods.set_my_description()
TelegramBotMethods.set_my_name()
TelegramBotMethods.set_my_short_description()
TelegramBotMethods.set_passport_data_errors()
TelegramBotMethods.set_sticker_emoji_list()
TelegramBotMethods.set_sticker_keywords()
TelegramBotMethods.set_sticker_mask_position()
TelegramBotMethods.set_sticker_position_in_set()
TelegramBotMethods.set_sticker_set_thumbnail()
TelegramBotMethods.set_sticker_set_title()
TelegramBotMethods.set_user_emoji_status()
TelegramBotMethods.set_webhook()
TelegramBotMethods.stop()
TelegramBotMethods.stop_message_live_location()
TelegramBotMethods.stop_poll()
TelegramBotMethods.unban_chat_member()
TelegramBotMethods.unban_chat_sender_chat()
TelegramBotMethods.unhide_general_forum_topic()
TelegramBotMethods.unpin_all_chat_messages()
TelegramBotMethods.unpin_all_forum_topic_messages()
TelegramBotMethods.unpin_all_general_forum_topic_messages()
TelegramBotMethods.unpin_chat_message()
TelegramBotMethods.unrestrict_chat_member()
TelegramBotMethods.upload_sticker_file()
- tgram.types package
- Submodules
- tgram.types.type_ module
- Module contents
Animation
Audio
BackgroundFill
BackgroundFillFreeformGradient
BackgroundFillGradient
BackgroundFillSolid
BackgroundType
BackgroundTypeChatTheme
BackgroundTypeFill
BackgroundTypePattern
BackgroundTypeWallpaper
Birthdate
BotCommand
BotCommandScope
BotCommandScopeAllChatAdministrators
BotCommandScopeAllGroupChats
BotCommandScopeAllPrivateChats
BotCommandScopeChat
BotCommandScopeChatAdministrators
BotCommandScopeChatMember
BotCommandScopeDefault
BotDescription
BotName
BotShortDescription
BusinessConnection
BusinessIntro
BusinessLocation
BusinessMessagesDeleted
BusinessOpeningHours
BusinessOpeningHoursInterval
CallbackGame
CallbackQuery
Chat
ChatAdministratorRights
ChatBackground
ChatBoost
ChatBoostAdded
ChatBoostRemoved
ChatBoostSource
ChatBoostSourceGiftCode
ChatBoostSourceGiveaway
ChatBoostSourcePremium
ChatBoostUpdated
ChatFullInfo
ChatInviteLink
ChatJoinRequest
ChatLocation
ChatMember
ChatMemberAdministrator
ChatMemberBanned
ChatMemberLeft
ChatMemberMember
ChatMemberOwner
ChatMemberRestricted
ChatMemberUpdated
ChatPermissions
ChatPhoto
ChatShared
ChosenInlineResult
Contact
CopyTextButton
Dice
Document
EncryptedCredentials
EncryptedPassportElement
ExternalReplyInfo
File
ForceReply
ForumTopic
ForumTopicClosed
ForumTopicCreated
ForumTopicEdited
ForumTopicReopened
Game
GameHighScore
GeneralForumTopicHidden
GeneralForumTopicUnhidden
Gift
Gifts
Giveaway
GiveawayCompleted
GiveawayCreated
GiveawayWinners
InaccessibleMessage
InlineKeyboardButton
InlineKeyboardMarkup
InlineQuery
InlineQueryResultArticle
InlineQueryResultAudio
InlineQueryResultCachedAudio
InlineQueryResultCachedDocument
InlineQueryResultCachedGif
InlineQueryResultCachedMpeg4Gif
InlineQueryResultCachedPhoto
InlineQueryResultCachedSticker
InlineQueryResultCachedVideo
InlineQueryResultCachedVoice
InlineQueryResultContact
InlineQueryResultDocument
InlineQueryResultGame
InlineQueryResultGif
InlineQueryResultLocation
InlineQueryResultMpeg4Gif
InlineQueryResultPhoto
InlineQueryResultVenue
InlineQueryResultVideo
InlineQueryResultVoice
InlineQueryResultsButton
InputContactMessageContent
InputInvoiceMessageContent
InputLocationMessageContent
InputMediaAnimation
InputMediaAudio
InputMediaDocument
InputMediaPhoto
InputMediaVideo
InputMessageContent
InputPaidMediaPhoto
InputPaidMediaVideo
InputPollOption
InputSticker
InputTextMessageContent
InputVenueMessageContent
Invoice
KeyboardButton
KeyboardButtonPollType
KeyboardButtonRequestChat
KeyboardButtonRequestUsers
LabeledPrice
LinkPreviewOptions
Listener
Location
LoginUrl
MaskPosition
MenuButton
MenuButtonCommands
MenuButtonDefault
MenuButtonWebApp
Message
MessageAutoDeleteTimerChanged
MessageEntity
MessageId
MessageOriginChannel
MessageOriginChat
MessageOriginHiddenUser
MessageOriginUser
MessageReactionCountUpdated
MessageReactionUpdated
OrderInfo
PaidMediaInfo
PaidMediaPhoto
PaidMediaPreview
PaidMediaPurchased
PaidMediaVideo
PassportData
PassportElementError
PassportElementErrorDataField
PassportElementErrorFile
PassportElementErrorFiles
PassportElementErrorFrontSide
PassportElementErrorReverseSide
PassportElementErrorSelfie
PassportElementErrorTranslationFile
PassportElementErrorTranslationFiles
PassportElementErrorUnspecified
PassportFile
PhotoSize
Poll
PollAnswer
PollOption
PreCheckoutQuery
PreparedInlineMessage
ProximityAlertTriggered
ReactionCount
ReactionTypeCustomEmoji
ReactionTypeEmoji
RefundedPayment
ReplyKeyboardMarkup
ReplyKeyboardRemove
ReplyParameters
ResponseParameters
RevenueWithdrawalStateFailed
RevenueWithdrawalStatePending
RevenueWithdrawalStateSucceeded
SentWebAppMessage
SharedUser
ShippingAddress
ShippingOption
ShippingQuery
StarTransaction
StarTransactions
Sticker
StickerSet
Story
SuccessfulPayment
SwitchInlineQueryChosenChat
TextQuote
TransactionPartnerFragment
TransactionPartnerOther
TransactionPartnerTelegramAds
TransactionPartnerTelegramApi
TransactionPartnerUser
Update
User
UserChatBoosts
UserProfilePhotos
UsersShared
Venue
Video
VideoChatEnded
VideoChatParticipantsInvited
VideoChatScheduled
VideoChatStarted
VideoNote
Voice
WebAppData
WebAppInfo
WebhookInfo
WriteAccessAllowed
Submodules¶
tgram.errors module¶
- exception tgram.errors.APIException(message: str, error_code: int, description: str, parameters: dict | None = None)[source]¶
Bases:
StrException
- exception tgram.errors.BotWasBlocked(*args)[source]¶
Bases:
StrException
- exception tgram.errors.BotWasKicked(*args)[source]¶
Bases:
StrException
- exception tgram.errors.ChatNotFound(*args)[source]¶
Bases:
StrException
- exception tgram.errors.FloodWait(*args)[source]¶
Bases:
StrException
- exception tgram.errors.GroupChatMigrated(*args)[source]¶
Bases:
StrException
- exception tgram.errors.InvalidFileId(*args)[source]¶
Bases:
StrException
- exception tgram.errors.MessageNotModified(*args)[source]¶
Bases:
StrException
- exception tgram.errors.MessageTextEmpty(*args)[source]¶
Bases:
StrException
- exception tgram.errors.MessageUneditable(*args)[source]¶
Bases:
StrException
- exception tgram.errors.TerminatedByOtherLongPollOrWebhook(*args)[source]¶
Bases:
StrException
- exception tgram.errors.UnableSendToBots(*args)[source]¶
Bases:
StrException
- exception tgram.errors.Unauthorized(*args)[source]¶
Bases:
StrException
- exception tgram.errors.UserDeactivated(*args)[source]¶
Bases:
StrException
- exception tgram.errors.UserNotFound(*args)[source]¶
Bases:
StrException
- exception tgram.errors.WebhookIsActive(*args)[source]¶
Bases:
StrException
- exception tgram.errors.WrongParameter(*args)[source]¶
Bases:
StrException
tgram.filters module¶
- tgram.filters.chat(ids: str | int | List[str | int]) Filter [source]¶
Filter messages coming from one or more chats
- tgram.filters.chat_type(types: list | str) Filter [source]¶
Filter updates that match a given chat type.
- tgram.filters.command(commands: str | List[str], prefixes: str | List[str] = '/', case_sensitive: bool = False) Filter [source]¶
Filter commands, i.e.: text messages starting with “/” or any other custom prefix.
- tgram.filters.regex(pattern: str | Pattern, flags: int = 0)[source]¶
Filter updates that match a given regular expression pattern.
tgram.handlers module¶
- class tgram.handlers.Handler(callback: Callable, type: str = 'all', filters: Filter | None = None)[source]¶
Bases:
object
- class tgram.handlers.Handlers[source]¶
Bases:
object
- BUSINESS_CONNECTION = 'business_connection'¶
- BUSINESS_MESSAGE = 'business_message'¶
- CALLBACK_QUERY = 'callback_query'¶
- CHANNEL_POST = 'channel_post'¶
- CHAT_BOOST = 'chat_boost'¶
- CHAT_JOIN_REQUEST = 'chat_join_request'¶
- CHAT_MEMBER = 'chat_member'¶
- CHOSEN_INLINE_RESULT = 'chosen_inline_result'¶
- DELETED_BUSINESS_MESSAGES = 'deleted_business_messages'¶
- EDITED_BUSINESS_MESSAGE = 'edited_business_message'¶
- EDITED_CHANNEL_POST = 'edited_channel_post'¶
- EDITED_MESSAGE = 'edited_message'¶
- INLINE_QUERY = 'inline_query'¶
- MESSAGE = 'message'¶
- MESSAGE_REACTION = 'message_reaction'¶
- MESSAGE_REACTION_COUNT = 'message_reaction_count'¶
- MY_CHAT_MEMBER = 'my_chat_member'¶
- POLL = 'poll'¶
- POLL_ANSWER = 'poll_answer'¶
- PRE_CHECKOUT_QUERY = 'pre_checkout_query'¶
- PURCHASED_PAID_MEDIA = 'purchased_paid_media'¶
- REMOVED_CHAT_BOOST = 'removed_chat_boost'¶
- SHIPPING_QUERY = 'shipping_query'¶
tgram.sync module¶
tgram.tgbot module¶
tgram.utils module¶
- class tgram.utils.Mention(name: str, user_id: int)[source]¶
Bases:
object
- property html: str¶
- property markdown: str¶
- class tgram.utils.ReadableTime[source]¶
Bases:
datetime
- to_formatted_time() str [source]¶
Converts the datetime object into a formatted string.
- Format:
‘YYYY/MM/DD - HH:MM:SS’
- Returns:
A string representation of the datetime object in the specified format.
- Return type:
str
- to_relative_time() str [source]¶
Converts the datetime object into a relative time string, indicating the difference between the current time and the object’s time.
Examples
‘5 minutes ago’
‘2 months 3 days 4 hours 15 minutes left’
‘Just now’
- Returns:
A human-readable string representing the time difference.
- Return type:
str
- class tgram.utils.String(*args)[source]¶
Bases:
str
- property html: str¶
- property markdown: str¶
- put(e: List[MessageEntity] | None = None) String [source]¶
- tgram.utils.convert_input_media(x: List[tgram.types.InputMedia | tgram.types.InputPaidMedia])[source]¶
- tgram.utils.convert_timestamp(timestamp: int | float) ReadableTime [source]¶
Converts a Unix timestamp into a ReadableTime object.
- Parameters:
timestamp (int | float) – A Unix timestamp.
- Returns:
A datetime object with methods to get a human-readable time difference.
- Return type:
- tgram.utils.get_parse_mode(bot: TgBot | None = None, parse_mode: str | None = None) str | None [source]¶
- tgram.utils.html_unparse(text: str, entities: List[MessageEntity]) str [source]¶
- tgram.utils.markdown_unparse(text: str, entities: List[MessageEntity])[source]¶
- tgram.utils.message_origin_parse(d: dict | None = None, me: tgram.TgBot | None = None) tgram.types.MessageOrigin | None [source]¶
- tgram.utils.reaction_type_parse(bot: tgram.TgBot, x: List[dict] | dict | None) tgram.types.ReactionType [source]¶
Module contents¶
- class tgram.TgBot(bot_token: str, api_url: str = 'https://api.telegram.org/', allowed_updates: List[str] = [], link_preview_options: LinkPreviewOptions | None = None, parse_mode: Literal['Markdown', 'MarkdownV2', 'HTML', 'Disable'] | None = None, protect_content: bool | None = None, workers: int | None = None, retry_after: int | bool | None = None, plugins: Path | str | None = None, skip_updates: bool = True, storage_engine: KvsqliteStorage | RedisStorage | Literal['kvsqlite', 'redis'] | None = None, storage_client: Any | None = None)[source]¶
Bases:
TelegramBotMethods
,Decorators
,Dispatcher
A class for creating a Telegram bot with extended functionality and support for various features like custom updates, storage engines, and more.
- Inherits from:
TelegramBotMethods: Provides various methods to interact with Telegram Bot API.
Decorators: Contains decorators to modify bot behavior.
Dispatcher: Manages event handling and dispatching for the bot.
- bot_token¶
The bot token provided by the BotFather.
- Type:
str
- api_url¶
The base API URL to communicate with Telegram servers.
- Type:
str
- allowed_updates¶
List of update types the bot should listen to.
- Type:
List[str]
- link_preview_options¶
Options for link previews in messages.
- parse_mode¶
Default parse mode for formatting messages.
- Type:
tgram.types.ParseMode
- protect_content¶
Whether to protect content from being saved or forwarded.
- Type:
bool
- workers¶
Number of worker threads for handling updates.
- Type:
int
- retry_after¶
Time or condition for retrying failed requests.
- Type:
Union[int, bool]
- plugins¶
Path to the directory containing bot plugins.
- Type:
Union[Path, str]
- skip_updates¶
Whether to skip pending updates on bot startup.
- Type:
bool
- storage¶
Storage engine instance for persisting data.
- Type:
Optional[StorageBase]
- storage_client¶
Client for the storage engine (e.g., Redis or Kvsqlite).
- Type:
Any
- executor¶
Executor for running handler threads.
- Type:
ThreadPoolExecutor
- loop¶
Event loop used by the bot.
- Type:
asyncio.AbstractEventLoop
- is_running¶
Indicates if the bot is currently running.
- Type:
bool
- me¶
The bot’s user profile.
- Type:
- handler_worker_tasks¶
Tasks handling updates processing.
- Type:
List[asyncio.Task]
- locks_list¶
Locks used for synchronization.
- Type:
List[asyncio.Lock]
- updates_queue¶
Queue for managing incoming updates.
- Type:
asyncio.Queue
- groups¶
Groups of handlers categorized by update types.
- Type:
OrderedDict