How to use the aiogram.api.types.Message 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_stop_message_live_location.py View on Github external
async def test_method(self, bot: MockedBot):
        prepare_result = bot.add_result_for(StopMessageLiveLocation, ok=True, result=True)

        response: Union[Message, bool] = await StopMessageLiveLocation(
            inline_message_id="inline message id"
        )
        request: Request = bot.get_request()
        assert request.method == "stopMessageLiveLocation"
        assert response == prepare_result.result
github aiogram / aiogram / tests / test_api / test_methods / test_edit_message_caption.py View on Github external
async def test_method(self, bot: MockedBot):
        prepare_result = bot.add_result_for(
            EditMessageCaption,
            ok=True,
            result=Message(
                message_id=42,
                date=datetime.datetime.now(),
                text="text",
                chat=Chat(id=42, type="private"),
            ),
        )

        response: Union[Message, bool] = await EditMessageCaption()
        request: Request = bot.get_request()
        assert request.method == "editMessageCaption"
        assert response == prepare_result.result
github aiogram / aiogram / tests / test_dispatcher / test_filters / test_command.py View on Github external
                Message(
                    message_id=42,
                    date=datetime.datetime.now(),
                    text="/test",
                    chat=Chat(id=42, type="private"),
                    from_user=User(id=42, is_bot=False, first_name="Test"),
                ),
                True,
            ],
        ],
    )
    async def test_call(self, message: Message, result: bool, bot: MockedBot):
        command = Command(commands=["test"])
        assert bool(await command(message=message, bot=bot)) is result
github aiogram / aiogram / tests / test_api / test_methods / test_edit_message_text.py View on Github external
async def test_bot_method(self, bot: MockedBot):
        prepare_result = bot.add_result_for(EditMessageText, ok=True, result=True)

        response: Union[Message, bool] = await bot.edit_message_text(
            chat_id=42, inline_message_id="inline message id", text="text"
        )
        request: Request = bot.get_request()
        assert request.method == "editMessageText"
        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 / tests / test_api / test_methods / test_send_invoice.py View on Github external
async def test_bot_method(self, bot: MockedBot):
        prepare_result = bot.add_result_for(
            SendInvoice,
            ok=True,
            result=Message(
                message_id=42,
                date=datetime.datetime.now(),
                invoice=Invoice(
                    title="test",
                    description="test",
                    start_parameter="brilliant",
                    currency="BTC",
                    total_amount=1,
                ),
                chat=Chat(id=42, type="private"),
            ),
        )

        response: Message = await bot.send_invoice(
            chat_id=42,
            title="test",
github aiogram / aiogram / aiogram / api / methods / send_sticker.py View on Github external
from typing import Any, Dict, Optional, Union

from ..types import (
    ForceReply,
    InlineKeyboardMarkup,
    InputFile,
    Message,
    ReplyKeyboardMarkup,
    ReplyKeyboardRemove,
)
from .base import Request, TelegramMethod, prepare_file


class SendSticker(TelegramMethod[Message]):
    """
    Use this method to send static .WEBP or animated .TGS stickers. On success, the sent Message
    is returned.

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

    __returning__ = Message

    chat_id: Union[int, str]
    """Unique identifier for the target chat or username of the target channel (in the format
    @channelusername)"""
    sticker: Union[InputFile, str]
    """Sticker to send. Pass a file_id as String to send a file that exists on the Telegram
    servers (recommended), pass an HTTP URL as a String for Telegram to get a .webp file from
    the Internet, or upload a new one using multipart/form-data."""
github aiogram / aiogram / aiogram / api / methods / forward_message.py View on Github external
from typing import Any, Dict, Optional, Union

from ..types import Message
from .base import Request, TelegramMethod


class ForwardMessage(TelegramMethod[Message]):
    """
    Use this method to forward messages of any kind. On success, the sent Message is returned.

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

    __returning__ = Message

    chat_id: Union[int, str]
    """Unique identifier for the target chat or username of the target channel (in the format
    @channelusername)"""
    from_chat_id: Union[int, str]
    """Unique identifier for the chat where the original message was sent (or channel username in
    the format @channelusername)"""
    message_id: int
    """Message identifier in the chat specified in from_chat_id"""
github aiogram / aiogram / aiogram / api / methods / edit_message_text.py View on Github external
from typing import Any, Dict, Optional, Union

from ..types import InlineKeyboardMarkup, Message
from .base import Request, TelegramMethod


class EditMessageText(TelegramMethod[Union[Message, bool]]):
    """
    Use this method to edit text and game messages. On success, if edited message is sent by the
    bot, the edited Message is returned, otherwise True is returned.

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

    __returning__ = Union[Message, bool]

    text: str
    """New text of the message"""
    chat_id: Optional[Union[int, str]] = None
    """Required if inline_message_id is not specified. Unique identifier for the target chat or
    username of the target channel (in the format @channelusername)"""
    message_id: Optional[int] = None
    """Required if inline_message_id is not specified. Identifier of the message to edit"""
github aiogram / aiogram / aiogram / api / methods / send_audio.py View on Github external
from typing import Any, Dict, Optional, Union

from ..types import (
    ForceReply,
    InlineKeyboardMarkup,
    InputFile,
    Message,
    ReplyKeyboardMarkup,
    ReplyKeyboardRemove,
)
from .base import Request, TelegramMethod, prepare_file


class SendAudio(TelegramMethod[Message]):
    """
    Use this method to send audio files, if you want Telegram clients to display them in the music
    player. Your audio must be in the .MP3 or .M4A format. On success, the sent Message is
    returned. Bots can currently send audio files of up to 50 MB in size, this limit may be
    changed in the future.
    For sending voice messages, use the sendVoice method instead.

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

    __returning__ = Message

    chat_id: Union[int, str]
    """Unique identifier for the target chat or username of the target channel (in the format
    @channelusername)"""
    audio: Union[InputFile, str]