Please Subscribe To My YouTube Channel Subscribe Now!

Add callback to Inline buttons in Pyrogram

Please wait 0 seconds...
Scroll Down and click on Go to Link for destination
Congrats! Link is Generated

Add Callback to Inline Buttons

In Pyrogram, callback queries allow your bot to respond to button clicks without sending a new message. Instead, it edits the existing message. This tutorial will guide you on how to set up callback buttons in Pyrogram.

Follow the below steps to add inline keyboard buttons in Pyrogram.

1. Create your Script file for responses.

class text(object):

  START = """your_start_message"""

  ABOUT = """📜 Check About:

Library: Pyrogram 📚  
Language: Python 🐍  
Server: Koyeb 🌐  
Build Status: V1.3 🚀  
Source Code: Available (Free) 💻"""
  
  HELP = """your_help_text"""

2. Create a new file name "callback.py" and paste the following code

from pyrogram import Client
from pyrogram.types import CallbackQuery, InlineKeyboardButton, InlineKeyboardMarkup
from Script import text

@Client.on_callback_query()
async def callback_query_handler(client, query: CallbackQuery):
    if query.data == "start":
        await query.message.edit_text(
            text.START.format(query.from_user.mention),
            disable_web_page_preview=True,
            reply_markup=InlineKeyboardMarkup([
                [InlineKeyboardButton("About", callback_data="about"),
                 InlineKeyboardButton("Help", callback_data="help")],
                [InlineKeyboardButton("Developer", url="https://telegram.me/TechifyRahul")]
            ])
        )

    elif query.data == "help":
        await query.message.edit_text(
            text.HELP,
            disable_web_page_preview=True,
            reply_markup=InlineKeyboardMarkup([
                [InlineKeyboardButton("Updates", url="https://telegram.me/Techifybots"),
                 InlineKeyboardButton("Support", url="https://telegram.me/TechifySupport")],
                [InlineKeyboardButton("Back", callback_data="start"),
                 InlineKeyboardButton("Close", callback_data="close")]
            ])
        )

    elif query.data == "about":
        await query.message.edit_text(
            text.ABOUT,
            disable_web_page_preview=True,
            reply_markup=InlineKeyboardMarkup([
                [InlineKeyboardButton("💥 Repo", url="https://github.com/TechifyBots/AI-Bot"),
                 InlineKeyboardButton("👨‍💻 Owner", url="https://telegram.me/TechifyRahul")],
                [InlineKeyboardButton("Back", callback_data="start"),
                 InlineKeyboardButton("Close", callback_data="close")]
            ])
        )

    elif query.data == "close":
        await query.message.delete()

Note:You can add or remove data according to your needs.

Important

If you still face any issues, then click on the below button.

Copying the post and using it without permission is strictly prohibited.

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.