-
Notifications
You must be signed in to change notification settings - Fork 0
/
tg_bot.py
57 lines (44 loc) · 1.7 KB
/
tg_bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import asyncio
import logging
import sys
from aiogram import Bot, Dispatcher, types
from aiogram.enums import ParseMode
from aiogram.filters import CommandStart
from aiogram.types import Message, InlineKeyboardButton, InlineKeyboardMarkup
from aiogram.utils.markdown import hbold
from aiogram.types.web_app_info import WebAppInfo
from conf import TELEGRAM_TOKEN
dp = Dispatcher()
ikb_donate = InlineKeyboardMarkup(
row_width=1, inline_keyboard=[
[InlineKeyboardButton(
text='Донат',
web_app=WebAppInfo(url='https://127.0.0.1:8000'))]]
)
@dp.message(CommandStart())
async def command_start_handler(message: Message) -> None:
"""
This handler receives messages with `/start` command
"""
await message.answer(f"Hello, {hbold(message.from_user.full_name)}!",
reply_markup=ikb_donate)
@dp.message()
async def echo_handler(message: types.Message) -> None:
"""
Handler will forward receive a message back to the sender
By default, message handler will handle all message types (like a text, photo, sticker etc.)
"""
try:
# Send a copy of the received message
await message.send_copy(chat_id=message.chat.id)
except TypeError:
# But not all the types is supported to be copied so need to handle it
await message.answer("Nice try!")
async def main() -> None:
# Initialize Bot instance with a default parse mode which will be passed to all API calls
bot = Bot(TELEGRAM_TOKEN, parse_mode=ParseMode.HTML)
# And the run events dispatching
await dp.start_polling(bot)
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
asyncio.run(main())