Skip to content

Instantly share code, notes, and snippets.

@oktober13
Last active July 18, 2023 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oktober13/bdaf70bf8d5074a653da47a9c114d0ea to your computer and use it in GitHub Desktop.
Save oktober13/bdaf70bf8d5074a653da47a9c114d0ea to your computer and use it in GitHub Desktop.
A template for sending various types of messages, such as text, photos, and documents.
import logging
from aiogram import Bot, Dispatcher, types
API_TOKEN = 'your_token'
logging.basicConfig(level=logging.INFO)
bot = Bot(token=API_TOKEN)
dp = Dispatcher(bot)
async def send_message(chat_id: int, text: str):
await bot.send_message(chat_id, text)
async def send_photo(chat_id: int, photo_url: str, caption: str = ''):
await bot.send_photo(chat_id, photo=photo_url, caption=caption)
async def send_document(chat_id: int, document_url: str, caption: str = ''):
await bot.send_document(chat_id, document=document_url, caption=caption)
if __name__ == '__main__':
# Usage example:
# await send_message(chat_id, "Hello, this is a text message.")
# await send_photo(chat_id, "https://example.com/photo.jpg", "Description of the photo.")
# await send_document(chat_id, "https://example.com/document.pdf", "Description of the document.")
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment