Last active
July 18, 2023 09:21
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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