-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathecho_bot.py
More file actions
59 lines (43 loc) · 1.39 KB
/
Copy pathecho_bot.py
File metadata and controls
59 lines (43 loc) · 1.39 KB
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
58
59
"""A minimal echo bot.
export BALE_TOKEN=123456:xxxxxxxx
python examples/echo_bot.py
"""
from __future__ import annotations
import asyncio
import logging
import os
from baleio import Bot, Dispatcher, F
from baleio.filters import CommandStart
from baleio.types import Message
from baleio.utils import InlineKeyboardBuilder
dp = Dispatcher()
@dp.message(CommandStart())
async def start(message: Message) -> None:
kb = (
InlineKeyboardBuilder()
.button("سلام بده 👋", callback_data="hi")
.button("درباره", callback_data="about")
.adjust(2)
.as_markup()
)
await message.answer(
f"سلام {message.from_user.first_name}! به baleio خوش اومدی.",
reply_markup=kb,
)
@dp.callback_query(F.data == "hi")
async def say_hi(callback) -> None:
await callback.answer("سلام! 🌟", show_alert=True)
@dp.callback_query(F.data == "about")
async def about(callback) -> None:
await callback.answer()
await callback.message.answer("این بات با کتابخانه baleio ساخته شده.")
@dp.message(F.text)
async def echo(message: Message) -> None:
await message.answer(message.text)
async def main() -> None:
logging.basicConfig(level=logging.INFO)
token = os.environ["BALE_TOKEN"]
bot = Bot(token)
await dp.start_polling(bot)
if __name__ == "__main__":
asyncio.run(main())