1# An API wrapper for Bale written in Python
2# Copyright (c) 2022-2024
3# Kian Ahmadian <devs@python-bale-bot.ir>
4# All rights reserved.
5#
6# This software is licensed under the GNU General Public License v2.0.
7# See the accompanying LICENSE file for details.
8#
9# You should have received a copy of the GNU General Public License v2.0
10# along with this program. If not, see <https://www.gnu.org/licenses/gpl-2.0.html>.
11
12from bale import Bot, CallbackQuery, Message, InlineKeyboardMarkup, InlineKeyboardButton, MenuKeyboardMarkup, MenuKeyboardButton
13from bale.handlers import MessageHandler, CommandHandler, CallbackQueryHandler
14from bale.checks import Text, Data
15
16client = Bot(token="Your Token")
17
18@client.listen('on_ready')
19async def on_ready_handler():
20 print(client.user, "is Ready!")
21
22@client.handle(CommandHandler('start'))
23async def start_command(message: Message):
24 reply_markup = InlineKeyboardMarkup()
25 reply_markup.add(InlineKeyboardButton(text="what is python-bale-bot?", callback_data="help"))
26 reply_markup.add(InlineKeyboardButton(text="package site", url="https://python-bale-bot.ir"), row=2)
27 reply_markup.add(InlineKeyboardButton(text="package changelog", url="https://python-bale-bot.ir/changelog"), row=2)
28 return await message.reply(
29 f"*Hi {message.author.mention or message.author.first_name}, Welcome to python-bale-bot bot*",
30 components=reply_markup
31 )
32
33
34@client.handle(CallbackQueryHandler(Data("help")))
35async def on_callback(callback: CallbackQuery):
36 return await callback.message.reply(
37 "*python-bale-bot* is a Python library for building bots on the Bale messenger platform. "
38 "Bale is a messaging app that provides a secure and private messaging experience for users. "
39 "The python-bale-bot library provides a simple and easy-to-use interface for building bots on the Bale platform, "
40 "allowing developers to create bots that can send and receive messages, handle events, "
41 "and perform various actions on behalf of users."
42 )
43
44@client.handle(CommandHandler('keyboard'))
45async def keyboard_command(message: Message):
46 return await message.reply(
47 f"Hi {message.author.mention or message.author.first_name}, Welcome to python-bale-bot bot",
48 components=MenuKeyboardMarkup().add(MenuKeyboardButton('site')).add(MenuKeyboardButton('github'))
49 )
50
51@client.handle(MessageHandler(Text(['site', 'github'])))
52async def menu_keyboard(message: Message):
53 await message.reply(
54 "https://python-bale-bot.ir"
55 if message.text == 'site' else
56 "https://python-bale-bot.ir/github",
57 components=MenuKeyboardMarkup() # to remove menu keyboards
58 )
59
60client.run()