Перейти к содержанию

Messages

Methods for sending and managing messages.

send_message

Send a text message.

await bot.send_message(
    chat_id=chat_id,
    text="Hello, World!",
    parse_mode="HTML",  # or "Markdown"
    disable_web_page_preview=True
)

send_photo

Send a photo.

# From file
with open("photo.jpg", "rb") as f:
    await bot.send_photo(
        chat_id=chat_id,
        photo=f,
        caption="Beautiful photo!"
    )

# By file_id or URL
await bot.send_photo(
    chat_id=chat_id,
    photo="FILE_ID_or_URL"
)

send_document

Send a document.

with open("document.pdf", "rb") as f:
    await bot.send_document(
        chat_id=chat_id,
        document=f,
        caption="Here's the document"
    )

send_video

Send a video.

with open("video.mp4", "rb") as f:
    await bot.send_video(
        chat_id=chat_id,
        video=f,
        duration=60,
        caption="Check this out!",
        supports_streaming=True
    )

send_audio

Send an audio file.

with open("audio.mp3", "rb") as f:
    await bot.send_audio(
        chat_id=chat_id,
        audio=f,
        title="Song Title",
        performer="Artist"
    )

send_voice

Send a voice message.

with open("voice.ogg", "rb") as f:
    await bot.send_voice(
        chat_id=chat_id,
        voice=f,
        duration=30
    )

send_sticker

Send a sticker.

await bot.send_sticker(
    chat_id=chat_id,
    sticker="STICKER_FILE_ID"
)

send_animation

Send an animation (GIF).

with open("animation.gif", "rb") as f:
    await bot.send_animation(
        chat_id=chat_id,
        animation=f,
        caption="Funny GIF!"
    )

send_location

Send a location.

await bot.send_location(
    chat_id=chat_id,
    latitude=55.7558,
    longitude=37.6173,
    horizontal_accuracy=10
)

send_venue

Send a venue.

await bot.send_venue(
    chat_id=chat_id,
    latitude=55.7558,
    longitude=37.6173,
    title="Red Square",
    address="Moscow, Russia"
)

send_contact

Send a contact.

await bot.send_contact(
    chat_id=chat_id,
    phone_number="+1234567890",
    first_name="John",
    last_name="Doe"
)

send_poll

Send a poll.

# Regular poll
await bot.send_poll(
    chat_id=chat_id,
    question="What's your favorite color?",
    options=["Red", "Green", "Blue"],
    is_anonymous=False,
    allows_multiple_answers=True
)

# Quiz poll
await bot.send_poll(
    chat_id=chat_id,
    question="Capital of France?",
    options=["London", "Paris", "Berlin"],
    type="quiz",
    correct_option_id=1
)

edit_message_text

Edit message text.

await bot.edit_message_text(
    chat_id=chat_id,
    message_id=message_id,
    text="Updated text!",
    reply_markup=new_keyboard
)

# For inline messages
await bot.edit_message_text(
    inline_message_id=inline_id,
    text="Updated!"
)

edit_message_caption

Edit message caption.

await bot.edit_message_caption(
    chat_id=chat_id,
    message_id=message_id,
    caption="New caption"
)

edit_message_media

Edit message media.

from aiomax import types

new_media = types.InputMediaPhoto(
    media="NEW_FILE_ID",
    caption="New caption"
)

await bot.edit_message_media(
    chat_id=chat_id,
    message_id=message_id,
    media=new_media
)

delete_message

Delete a message.

await bot.delete_message(
    chat_id=chat_id,
    message_id=message_id
)

See Also