tgram package

Subpackages

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.StopPropagation[source]

Bases: Exception

exception tgram.errors.StrException(msg: str)[source]

Bases: Exception

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

class tgram.filters.Filter(filter_: Callable | Coroutine)[source]

Bases: object

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.filters.sender(ids: str | int | List[str | int]) Filter[source]

Filter messages coming from one or more sender chat

tgram.filters.user(ids: str | int | List[str | int]) Filter[source]

Filter messages coming from one or more users

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.sync.async_to_sync(obj, name)[source]
tgram.sync.wrap(source)[source]

tgram.tgbot module

class tgram.tgbot.Dispatcher[source]

Bases: object

handler_worker(lock: Lock)[source]
run_for_updates(skip_updates: bool = None) None[source]
class tgram.tgbot.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'] | 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)[source]

Bases: TelegramBotMethods, Decorators, Dispatcher

add_handler(handler: Handler, group: int = 0) None[source]
customize(old: type, new: type) Literal[True][source]
load_plugins() None[source]
remove_handler(handler: Handler, group: int = 0) None[source]

tgram.utils module

class tgram.utils.DecodedFileId[source]

Bases: TypedDict

dc_id: int
file_id: str
file_type: str
file_type_int: int
class tgram.utils.Json[source]

Bases: dict

class tgram.utils.Mention(name: str, user_id: int)[source]

Bases: object

property html: str
property markdown: 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.add_surrogates(text: str) str[source]
tgram.utils.b64_decode(s: str) bytes[source]
tgram.utils.compose(bots: List[TgBot])[source]
tgram.utils.convert_input_media(x: List[tgram.types.InputMedia | tgram.types.InputPaidMedia])[source]
tgram.utils.decode_file_id(file_id: str) DecodedFileId[source]
tgram.utils.get_file_name(obj)[source]
tgram.utils.get_file_path(file)[source]
tgram.utils.html_unparse(text: str, entities: List[MessageEntity]) str[source]
tgram.utils.markdown_unparse(text: str, entities: List[MessageEntity])[source]
tgram.utils.remove_surrogates(text: str) str[source]
tgram.utils.rle_decode(s: bytes) bytes[source]

Module contents

exception tgram.StopPropagation[source]

Bases: Exception

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'] | 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)[source]

Bases: TelegramBotMethods, Decorators, Dispatcher

add_handler(handler: Handler, group: int = 0) None[source]
customize(old: type, new: type) Literal[True][source]
load_plugins() None[source]
remove_handler(handler: Handler, group: int = 0) None[source]
tgram.compose(bots: List[TgBot])[source]