Skip to content

Commit

Permalink
add plugins example
Browse files Browse the repository at this point in the history
  • Loading branch information
z44d committed Jul 14, 2024
1 parent ebab462 commit 3f0af3a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions examples/smart_plugins/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import logging
from tgram import TgBot

logging.basicConfig(level=logging.DEBUG)

bot = TgBot("API_TOKEN_HERE", parse_mode="Markdown", plugins="./plugins")

bot.run_for_updates()
7 changes: 7 additions & 0 deletions examples/smart_plugins/plugins/callback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from tgram import TgBot, filters
from tgram.types import CallbackQuery


@TgBot.on_callback_query(filters.regex("^fine$"))
def callback(bot: TgBot, query: CallbackQuery) -> bool:
return query.answer("Good to know!", show_alert=True)
13 changes: 13 additions & 0 deletions examples/smart_plugins/plugins/start.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from tgram import TgBot, filters

from tgram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton


@TgBot.on_message(filters.command("start") & filters.private)
async def on_start_message(bot: TgBot, m: Message) -> Message:
return await m.reply_text(
f"Hi {m.from_user.mention}!, How are you today?",
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("I'm fine", callback_data="fine")]]
),
)

0 comments on commit 3f0af3a

Please sign in to comment.