├── Lesson1.py
├── Lesson2.py
└── README.md
/Lesson1.py:
--------------------------------------------------------------------------------
1 | from aiogram import Bot, Dispatcher, executor, types
2 | import pyqrcode
3 |
4 | bot = Bot(token='your_bot_token')
5 | dp = Dispatcher(bot)
6 |
7 | @dp.message_handler(commands=['start', 'help'])
8 | async def welcome(message: types.Message):
9 | await message.reply("Hello! Im Gunther Bot, Please follow my YT channel")
10 |
11 | @dp.message_handler(commands=['logo'])
12 | async def logo(message: types.Message):
13 | await message.answer_photo('https://avatars.githubusercontent.com/u/62240649?v=4')
14 |
15 | @dp.message_handler()
16 | async def qr(message: types.Message):
17 | text = pyqrcode.create(message.text)
18 | text.png('code.png', scale=5)
19 | await bot.send_photo(chat_id=message.chat.id, photo=open('code.png', 'rb'))
20 |
21 |
22 | if __name__ == '__main__':
23 | executor.start_polling(dp)
24 |
--------------------------------------------------------------------------------
/Lesson2.py:
--------------------------------------------------------------------------------
1 | from aiogram import Bot, Dispatcher, executor, types
2 | from aiogram.types import ReplyKeyboardMarkup, ReplyKeyboardRemove, KeyboardButton
3 | from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton
4 | from random import randint
5 |
6 | bot = Bot(token='your_token')
7 | dp = Dispatcher(bot)
8 |
9 | button1 = InlineKeyboardButton(text="👋 button1", callback_data="randomvalue_of10")
10 | button2 = InlineKeyboardButton(text="💋 button2", callback_data="randomvalue_of100")
11 | keyboard_inline = InlineKeyboardMarkup().add(button1, button2)
12 |
13 | keyboard1 = ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=True).add("👋 Hello!", "💋 Youtube")
14 |
15 |
16 | @dp.message_handler(commands=['random'])
17 | async def random_answer(message: types.Message):
18 | await message.reply("Select a range:", reply_markup=keyboard_inline)
19 |
20 |
21 | @dp.message_handler(commands=['start', 'help'])
22 | async def welcome(message: types.Message):
23 | await message.reply("Hello! Im Gunther Bot, Please follow my YT channel", reply_markup=keyboard1)
24 |
25 |
26 | @dp.callback_query_handler(text=["randomvalue_of10", "randomvalue_of100"])
27 | async def random_value(call: types.CallbackQuery):
28 | if call.data == "randomvalue_of10":
29 | await call.message.answer(randint(1, 10))
30 | if call.data == "randomvalue_of100":
31 | await call.message.answer(randint(1, 100))
32 | await call.answer()
33 |
34 |
35 | @dp.message_handler()
36 | async def kb_answer(message: types.Message):
37 | if message.text == '👋 Hello!':
38 | await message.reply("Hi! How are you?")
39 | elif message.text == '💋 Youtube':
40 | await message.reply("https://youtube.com/gunthersuper")
41 | else:
42 | await message.reply(f"Your message is: {message.text}")
43 |
44 |
45 | executor.start_polling(dp)
46 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # aiogram-lessons
2 | aiogram telegram bots tutorials by Gunther
3 |
4 | Check the video on the Gunthers channel: https://www.youtube.com/GuntherSuper
5 |
6 | Lesson1:
7 | 1. How to make your own Telegram bot
8 | 2. Installing Python and Pycharm
9 | 3. Making an echo bot
10 | 4. Sending images from the web and from a local drive
11 | 5. Simple bot with `pyqrcode` package
12 |
13 | Lesson2:
14 | 1. Reply Keyboards
15 | 2. Inline Keyboards, callbacks
16 |
--------------------------------------------------------------------------------