How to use the aiogram.types function in aiogram

To help you get started, we’ve selected a few aiogram examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aiogram / bot / app / handlers / new_chat_members.py View on Github external
@dp.message_handler(content_types=types.ContentTypes.NEW_CHAT_MEMBERS)
async def new_chat_member(message: types.Message, chat: Chat):
    if not chat.join_filter:
        return False

    if message.date < datetime.datetime.now() - datetime.timedelta(minutes=1):
        logger.warning(
            "Join message {message} in chat {chat} is too old. Skip filtering. (Age: {age})",
            message=message.message_id,
            chat=chat.id,
            age=datetime.datetime.now() - message.date,
        )
        return False

    if message.from_user not in message.new_chat_members:
        logger.opt(lazy=True).info(
            "User {user} add new members to chat {chat}: {new_members}",
github aiogram / aiogram / aiogram / _telegram / types.py View on Github external
link: https://core.telegram.org/bots/api#telegram-passport
"""


class PassportData(pydantic.BaseModel):
    """
    Contains information about Telegram Passport data shared with the bot by the user.

    Source: https://core.telegram.org/bots/api#passportdata
    """

    data: typing.List[types.EncryptedPassportElement]
    """Array with information about documents and other Telegram Passport elements that was shared with the bot"""

    credentials: types.EncryptedCredentials
    """Encrypted credentials required to decrypt the data"""


class PassportFile(pydantic.BaseModel):
    """
    This object represents a file uploaded to Telegram Passport. Currently all Telegram Passport files are in JPEG format when decrypted and don't exceed 10MB.

    Source: https://core.telegram.org/bots/api#passportfile
    """

    file_id: str
    """Unique identifier for this file"""

    file_size: int
    """File size"""
github aiogram / aiogram / aiogram / dispatcher / filters / builtin.py View on Github external
def _get_tags(self, text, entities):
        hashtags = []
        cashtags = []

        for entity in entities:
            if entity.type == types.MessageEntityType.HASHTAG:
                value = entity.get_text(text).lstrip('#')
                hashtags.append(value)

            elif entity.type == types.MessageEntityType.CASHTAG:
                value = entity.get_text(text).lstrip('$')
                cashtags.append(value)

        return hashtags, cashtags
github aiogram / aiogram / aiogram / _telegram / types.py View on Github external
title: typing.Optional[str] = None
    """Title, for supergroups, channels and group chats"""

    username: typing.Optional[str] = None
    """Username, for private chats, supergroups and channels if available"""

    first_name: typing.Optional[str] = None
    """First name of the other party in a private chat"""

    last_name: typing.Optional[str] = None
    """Last name of the other party in a private chat"""

    all_members_are_administrators: typing.Optional[bool] = None
    """True if a group has ‘All Members Are Admins’ enabled."""

    photo: typing.Optional[types.ChatPhoto] = None
    """Chat photo. Returned only in getChat."""

    description: typing.Optional[str] = None
    """Description, for supergroups and channel chats. Returned only in getChat."""

    invite_link: typing.Optional[str] = None
    """Chat invite link, for supergroups and channel chats. Each administrator in a chat generates their own invite links, so the bot must first generate the link using exportChatInviteLink. Returned only in getChat."""

    pinned_message: typing.Optional[types.Message] = None
    """Pinned message, for groups, supergroups and channels. Returned only in getChat."""

    sticker_set_name: typing.Optional[str] = None
    """For supergroups, name of group sticker set. Returned only in getChat."""

    can_set_sticker_set: typing.Optional[bool] = None
    """True, if the bot can change the group sticker set. Returned only in getChat."""
github aiogram / aiogram / aiogram / _telegram / types.py View on Github external
type: str
    """Element type. One of 'personal_details', 'passport', 'driver_license', 'identity_card', 'internal_passport', 'address', 'utility_bill', 'bank_statement', 'rental_agreement', 'passport_registration', 'temporary_registration', 'phone_number', 'email'."""

    data: typing.Optional[str] = None
    """Base64-encoded encrypted Telegram Passport element data provided by the user, available for 'personal_details', 'passport', 'driver_license', 'identity_card', 'internal_passport' and 'address' types. Can be decrypted and verified using the accompanying EncryptedCredentials."""

    phone_number: typing.Optional[str] = None
    """User's verified phone number, available only for 'phone_number' type"""

    email: typing.Optional[str] = None
    """User's verified email address, available only for 'email' type"""

    files: typing.Optional[typing.List[types.PassportFile]] = None
    """Array of encrypted files with documents provided by the user, available for 'utility_bill', 'bank_statement', 'rental_agreement', 'passport_registration' and 'temporary_registration' types. Files can be decrypted and verified using the accompanying EncryptedCredentials."""

    front_side: typing.Optional[types.PassportFile] = None
    """Encrypted file with the front side of the document, provided by the user. Available for 'passport', 'driver_license', 'identity_card' and 'internal_passport'. The file can be decrypted and verified using the accompanying EncryptedCredentials."""

    reverse_side: typing.Optional[types.PassportFile] = None
    """Encrypted file with the reverse side of the document, provided by the user. Available for 'driver_license' and 'identity_card'. The file can be decrypted and verified using the accompanying EncryptedCredentials."""

    selfie: typing.Optional[types.PassportFile] = None
    """Encrypted file with the selfie of the user holding a document, provided by the user; available for 'passport', 'driver_license', 'identity_card' and 'internal_passport'. The file can be decrypted and verified using the accompanying EncryptedCredentials."""

    translation: typing.Optional[typing.List[types.PassportFile]] = None
    """Array of encrypted files with translated versions of documents provided by the user. Available if requested for 'passport', 'driver_license', 'identity_card', 'internal_passport', 'utility_bill', 'bank_statement', 'rental_agreement', 'passport_registration' and 'temporary_registration' types. Files can be decrypted and verified using the accompanying EncryptedCredentials."""

    hash: str
    """Base64-encoded element hash for using in PassportElementErrorUnspecified"""


class EncryptedCredentials(pydantic.BaseModel):
github aiogram / aiogram / aiogram / _telegram / types.py View on Github external
class ShippingOption(pydantic.BaseModel):
    """
    This object represents one shipping option.

    Source: https://core.telegram.org/bots/api#shippingoption
    """

    id: str
    """Shipping option identifier"""

    title: str
    """Option title"""

    prices: typing.List[types.LabeledPrice]
    """List of price portions"""


class SuccessfulPayment(pydantic.BaseModel):
    """
    This object contains basic information about a successful payment.

    Source: https://core.telegram.org/bots/api#successfulpayment
    """

    currency: str
    """Three-letter ISO 4217 currency code"""

    total_amount: int
    """Total price in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies)."""
github aiogram / bot / app / handlers / chat_settings.py View on Github external
async def cq_chat_settings_language(query: types.CallbackQuery, chat: Chat, callback_data: dict):
    logger.info(
        "User {user} wants to change language in chat {chat}",
        user=query.from_user.id,
        chat=chat.id,
    )
    if callback_data["@"] == "chat":
        target_chat_id = int(callback_data["id"])
        chat = await Chat.query.where(Chat.id == target_chat_id).gino.first()
        if not chat:
            return await query.answer(_("Invalid chat"), show_alert=True)
        callback_factory = partial(cb_chat_settings.new, id=chat.id)
    else:
        callback_factory = cb_user_settings.new

    markup = types.InlineKeyboardMarkup()

    for code, language in i18n.AVAILABLE_LANGUAGES.items():
        markup.add(
            types.InlineKeyboardButton(
                language.label, callback_data=callback_factory(property="language", value=code)
            )
        )

    await query.answer(_("Choose chat language"))
    await query.message.edit_reply_markup(markup)
github aiogram / aiogram / examples / inline_keyboard_example.py View on Github external
keyboard_markup = types.InlineKeyboardMarkup(row_width=3)
    # default row_width is 3, so here we can omit it actually
    # kept for clearness

    text_and_data = (
        ('Yes!', 'yes'),
        ('No!', 'no'),
    )
    # in real life for the callback_data the callback data factory should be used
    # here the raw string is used for the simplicity
    row_btns = (types.InlineKeyboardButton(text, callback_data=data) for text, data in text_and_data)

    keyboard_markup.row(*row_btns)
    keyboard_markup.add(
        # url buttons have no callback data
        types.InlineKeyboardButton('aiogram source', url='https://github.com/aiogram/aiogram'),
    )

    await message.reply("Hi!\nDo you love aiogram?", reply_markup=keyboard_markup)
github aiogram / aiogram / examples / regular_keyboard_example.py View on Github external
async def start_cmd_handler(message: types.Message):
    keyboard_markup = types.ReplyKeyboardMarkup(row_width=3)
    # default row_width is 3, so here we can omit it actually
    # kept for clearness

    btns_text = ('Yes!', 'No!')
    keyboard_markup.row(*(types.KeyboardButton(text) for text in btns_text))
    # adds buttons as a new row to the existing keyboard
    # the behaviour doesn't depend on row_width attribute

    more_btns_text = (
        "I don't know",
        "Who am i?",
        "Where am i?",
        "Who is there?",
    )
    keyboard_markup.add(*(types.KeyboardButton(text) for text in more_btns_text))
    # adds buttons. New rows are formed according to row_width parameter