How to use the aiogram.api.types.Chat 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 / aiogram / tests / test_api / test_methods / test_send_sticker.py View on Github external
async def test_method(self, bot: MockedBot):
        prepare_result = bot.add_result_for(
            SendSticker,
            ok=True,
            result=Message(
                message_id=42,
                date=datetime.datetime.now(),
                sticker=Sticker(file_id="file id", width=42, height=42, is_animated=False),
                chat=Chat(id=42, type="private"),
            ),
        )

        response: Message = await SendSticker(chat_id=42, sticker="file id")
        request: Request = bot.get_request()
        assert request.method == "sendSticker"
        assert response == prepare_result.result
github aiogram / aiogram / tests / test_api / test_methods / test_forward_message.py View on Github external
async def test_bot_method(self, bot: MockedBot):
        prepare_result = bot.add_result_for(
            ForwardMessage,
            ok=True,
            result=Message(
                message_id=42,
                date=datetime.datetime.now(),
                chat=Chat(id=42, title="chat", type="private"),
                text="text",
            ),
        )

        response: Message = await bot.forward_message(chat_id=42, from_chat_id=42, message_id=42)
        request: Request = bot.get_request()
        assert request.method == "forwardMessage"
        # assert request.data == {}
        assert response == prepare_result.result
github aiogram / aiogram / tests / test_dispatcher / test_router.py View on Github external
async def my_handler(event: Any, **kwargs: Any):
            assert event == getattr(update, event_type)
            if has_chat:
                assert Chat.get_current(False)
            if has_user:
                assert User.get_current(False)
            return kwargs
github aiogram / aiogram / tests / test_api / test_methods / test_send_game.py View on Github external
async def test_method(self, bot: MockedBot):
        prepare_result = bot.add_result_for(
            SendGame,
            ok=True,
            result=Message(
                message_id=42,
                date=datetime.datetime.now(),
                game=Game(
                    title="title",
                    description="description",
                    photo=[PhotoSize(file_id="file id", width=42, height=42)],
                ),
                chat=Chat(id=42, type="private"),
            ),
        )

        response: Message = await SendGame(chat_id=42, game_short_name="game")
        request: Request = bot.get_request()
        assert request.method == "sendGame"
        assert response == prepare_result.result
github aiogram / aiogram / tests / test_api / test_methods / test_send_video_note.py View on Github external
async def test_bot_method(self, bot: MockedBot):
        prepare_result = bot.add_result_for(
            SendVideoNote,
            ok=True,
            result=Message(
                message_id=42,
                date=datetime.datetime.now(),
                video_note=VideoNote(file_id="file id", length=0, duration=0),
                chat=Chat(id=42, type="private"),
            ),
        )

        response: Message = await bot.send_video_note(
            chat_id=42, video_note="file id", thumb=BufferedInputFile(b"", "file.png")
        )
        request: Request = bot.get_request()
        assert request.method == "sendVideoNote"
        assert response == prepare_result.result
github aiogram / aiogram / tests / test_api / test_methods / test_send_contact.py View on Github external
async def test_method(self, bot: MockedBot):
        prepare_result = bot.add_result_for(
            SendContact,
            ok=True,
            result=Message(
                message_id=42,
                date=datetime.datetime.now(),
                contact=Contact(phone_number="911", first_name="911"),
                chat=Chat(id=42, type="private"),
            ),
        )

        response: Message = await SendContact(chat_id=42, phone_number="911", first_name="911")
        request: Request = bot.get_request()
        assert request.method == "sendContact"
        assert response == prepare_result.result
github aiogram / aiogram / tests / test_api / test_methods / test_send_venue.py View on Github external
async def test_method(self, bot: MockedBot):
        prepare_result = bot.add_result_for(
            SendVenue,
            ok=True,
            result=Message(
                message_id=42,
                date=datetime.datetime.now(),
                venue=Venue(
                    location=Location(latitude=3.14, longitude=3.14),
                    title="Cupboard Under the Stairs",
                    address="Under the stairs, 4 Privet Drive, "
                    "Little Whinging, Surrey, England, Great Britain",
                ),
                chat=Chat(id=42, type="private"),
            ),
        )

        response: Message = await SendVenue(
            chat_id=42,
            latitude=3.14,
            longitude=3.14,
            title="Cupboard Under the Stairs",
            address="Under the stairs, 4 Privet Drive, "
            "Little Whinging, Surrey, England, Great Britain",
        )
        request: Request = bot.get_request()
        assert request.method == "sendVenue"
        assert response == prepare_result.result
github aiogram / aiogram / tests / test_api / test_methods / test_send_location.py View on Github external
async def test_bot_method(self, bot: MockedBot):
        prepare_result = bot.add_result_for(
            SendLocation,
            ok=True,
            result=Message(
                message_id=42,
                date=datetime.datetime.now(),
                location=Location(longitude=3.14, latitude=3.14),
                chat=Chat(id=42, type="private"),
            ),
        )

        response: Message = await bot.send_location(chat_id=42, latitude=3.14, longitude=3.14)
        request: Request = bot.get_request()
        assert request.method == "sendLocation"
        assert response == prepare_result.result
github aiogram / aiogram / tests / test_api / test_methods / test_send_message.py View on Github external
async def test_bot_method(self, bot: MockedBot):
        prepare_result = bot.add_result_for(
            SendMessage,
            ok=True,
            result=Message(
                message_id=42,
                date=datetime.datetime.now(),
                text="test",
                chat=Chat(id=42, type="private"),
            ),
        )

        response: Message = await bot.send_message(chat_id=42, text="test")
        request: Request = bot.get_request()
        assert request.method == "sendMessage"
        assert response == prepare_result.result
github aiogram / aiogram / aiogram / dispatcher / router.py View on Github external
event = update.shipping_query
        elif update.pre_checkout_query:
            update_type = "pre_checkout_query"
            from_user = update.pre_checkout_query.from_user
            event = update.pre_checkout_query
        elif update.poll:
            update_type = "poll"
            event = update.poll
        else:
            raise SkipHandler

        observer = self.observers[update_type]
        if from_user:
            User.set_current(from_user)
        if chat:
            Chat.set_current(chat)
        async for result in observer.trigger(event, **kwargs):
            return result

        for router in self.sub_routers:
            async for result in router.update_handler.trigger(update, **kwargs):
                return result

        raise SkipHandler