40 lines
1020 B
Python
40 lines
1020 B
Python
from io import BytesIO
|
|
from os import environ
|
|
|
|
import dotenv
|
|
from aiogram import Bot, Dispatcher, executor, types
|
|
from httpx import AsyncClient
|
|
|
|
dotenv.load_dotenv()
|
|
bot = Bot(token=environ["TG_TOKEN"])
|
|
dp = Dispatcher(bot)
|
|
|
|
|
|
@dp.message_handler(commands=["start"])
|
|
async def start(mes: types.Message) -> None:
|
|
await mes.reply(
|
|
f"Привет {mes.from_user.get_mention()}",
|
|
parse_mode="MarkdownV2",
|
|
)
|
|
|
|
|
|
@dp.message_handler(commands=["send_pic"])
|
|
async def send_pic(mes: types.Message) -> None:
|
|
async with AsyncClient() as client:
|
|
response = await client.get(
|
|
"https://loremflickr.com/320/240/dog",
|
|
follow_redirects=True,
|
|
)
|
|
photo = BytesIO(response.content)
|
|
photo.name = "dog.jpg"
|
|
await mes.reply_photo(photo, "Here you go")
|
|
|
|
|
|
@dp.message_handler(content_types=types.ContentTypes.TEXT)
|
|
async def message_handler(mes: types.Message) -> None:
|
|
await bot.send_message(mes.chat.id, mes.text)
|
|
print(mes.text)
|
|
|
|
|
|
executor.start_polling(dp)
|