Update Handlers¶
Handlers are used to instruct Pyrofork about which kind of updates you’d like to handle with your callback functions. For a much more convenient way of registering callback functions have a look at Decorators instead.
from pyrogram import Client
from pyrogram.handlers import MessageHandler
app = Client("my_account")
def dump(client, message):
    print(message)
app.add_handler(MessageHandler(dump))
app.run()
Contents
Index¶
Details¶
- class pyrogram.handlers.BotBusinessConnectHandler¶
 The Bot Business Connection handler class. Used to handle new bot business connection. It is intended to be used with
add_handler()For a nicer way to register this handler, have a look at the
on_bot_business_connect()decorator.- Parameters:¶
 callback (
Callable) – Pass a function that will be called when a new Stories arrives. It takes (client, story) as positional arguments (look at the section below for a detailed description).filters (
Filters) – Pass one or more filters to allow only a subset of stories to be passed in your callback function.
- Other Parameters:¶
 client (
Client) – The Client itself, useful when you want to call other API methods inside the story handler.bot_connection (
BotBusinessConnection) – Information about the received Bot Business Connection.
- class pyrogram.handlers.MessageHandler¶
 The Message handler class. Used to handle new messages. It is intended to be used with
add_handler()For a nicer way to register this handler, have a look at the
on_message()decorator.- Parameters:¶
 callback (
Callable) – Pass a function that will be called when a new Message arrives. It takes (client, message) as positional arguments (look at the section below for a detailed description).filters (
Filters) – Pass one or more filters to allow only a subset of messages to be passed in your callback function.
- Other Parameters:¶
 
- class pyrogram.handlers.BotBusinessMessageHandler¶
 The Bot Business Message handler class. Used to handle new bot business messages. It is intended to be used with
add_handler()For a nicer way to register this handler, have a look at the
on_bot_business_message()decorator.- Parameters:¶
 callback (
Callable) – Pass a function that will be called when a new Message arrives. It takes (client, message) as positional arguments (look at the section below for a detailed description).filters (
Filters) – Pass one or more filters to allow only a subset of messages to be passed in your callback function.
- Other Parameters:¶
 
- class pyrogram.handlers.EditedMessageHandler¶
 - The EditedMessage handler class. Used to handle edited messages.
 It is intended to be used with
add_handler()
For a nicer way to register this handler, have a look at the
on_edited_message()decorator.- Parameters:¶
 callback (
Callable) – Pass a function that will be called when a new edited message arrives. It takes (client, message) as positional arguments (look at the section below for a detailed description).filters (
Filters) – Pass one or more filters to allow only a subset of messages to be passed in your callback function.
- Other Parameters:¶
 
- class pyrogram.handlers.EditedBotBusinessMessageHandler¶
 - The EditedBotBusinessMessageHandler handler class. Used to handle edited bot business messages.
 It is intended to be used with
add_handler()
For a nicer way to register this handler, have a look at the
on_edited_bot_business_message()decorator.- Parameters:¶
 callback (
Callable) – Pass a function that will be called when a new edited message arrives. It takes (client, message) as positional arguments (look at the section below for a detailed description).filters (
Filters) – Pass one or more filters to allow only a subset of messages to be passed in your callback function.
- Other Parameters:¶
 
- class pyrogram.handlers.DeletedMessagesHandler¶
 The deleted messages handler class. Used to handle deleted messages coming from any chat (private, group, channel). It is intended to be used with
add_handler()For a nicer way to register this handler, have a look at the
on_deleted_messages()decorator.- Parameters:¶
 callback (
Callable) – Pass a function that will be called when one or more messages have been deleted. It takes (client, messages) as positional arguments (look at the section below for a detailed description).filters (
Filters) – Pass one or more filters to allow only a subset of messages to be passed in your callback function.
- Other Parameters:¶
 
- class pyrogram.handlers.DeletedBotBusinessMessagesHandler¶
 The deleted bot business messages handler class. Used to handle deleted messages coming from any chat (private, group, channel). It is intended to be used with
add_handler()For a nicer way to register this handler, have a look at the
on_deleted_bot_business_messages()decorator.- Parameters:¶
 callback (
Callable) – Pass a function that will be called when one or more messages have been deleted. It takes (client, messages) as positional arguments (look at the section below for a detailed description).filters (
Filters) – Pass one or more filters to allow only a subset of messages to be passed in your callback function.
- Other Parameters:¶
 
- class pyrogram.handlers.CallbackQueryHandler¶
 The CallbackQuery handler class. Used to handle callback queries coming from inline buttons. It is intended to be used with
add_handler()For a nicer way to register this handler, have a look at the
on_callback_query()decorator.- Parameters:¶
 callback (
Callable) – Pass a function that will be called when a new CallbackQuery arrives. It takes (client, callback_query) as positional arguments (look at the section below for a detailed description).filters (
Filters) – Pass one or more filters to allow only a subset of callback queries to be passed in your callback function.
- Other Parameters:¶
 client (
Client) – The Client itself, useful when you want to call other API methods inside the message handler.callback_query (
CallbackQuery) – The received callback query.
- class pyrogram.handlers.ShippingQueryHandler¶
 The ShippingQueryHandler handler class. Used to handle shipping queries coming only from invoice buttons with flexible price.
It is intended to be used with
add_handler()For a nicer way to register this handler, have a look at the
on_shipping_query()decorator.- Parameters:¶
 callback (
Callable) – Pass a function that will be called when a new PreCheckoutQuery arrives. It takes (client, shipping_query) as positional arguments (look at the section below for a detailed description).filters (
Filters) – Pass one or more filters to allow only a subset of callback queries to be passed in your callback function.
- Other Parameters:¶
 client (
Client) – The Client itself, useful when you want to call other API methods inside the message handler.shipping_query (
ShippingQuery) – New incoming shipping query. Only for invoices with flexible price.
- class pyrogram.handlers.PreCheckoutQueryHandler¶
 The PreCheckoutQueryHandler handler class. Used to handle pre-checkout queries coming from buy buttons. It is intended to be used with
add_handler()For a nicer way to register this handler, have a look at the
on_pre_checkout_query()decorator.- Parameters:¶
 callback (
Callable) – Pass a function that will be called when a new PreCheckoutQuery arrives. It takes (client, pre_checkout_query) as positional arguments (look at the section below for a detailed description).filters (
Filters) – Pass one or more filters to allow only a subset of callback queries to be passed in your callback function.
- Other Parameters:¶
 client (
Client) – The Client itself, useful when you want to call other API methods inside the message handler.pre_checkout_query (
PreCheckoutQuery) – New incoming pre-checkout query. Contains full information about checkout.
- class pyrogram.handlers.MessageReactionUpdatedHandler¶
 The MessageReactionUpdated handler class. Used to handle changes in the reaction of a message.
It is intended to be used with
add_handler().For a nicer way to register this handler, have a look at the
on_message_reaction_updated()decorator.- Parameters:¶
 callback (
Callable) – Pass a function that will be called when a new MessageReactionUpdated event arrives. It takes (client, message_reaction_updated) as positional arguments (look at the section below for a detailed description).filters (
Filters) – Pass one or more filters to allow only a subset of updates to be passed in your callback function.
- Other Parameters:¶
 client (
Client) – The Client itself, useful when you want to call other API methods inside the handler.message_reaction_updated (
MessageReactionUpdated) – The received message reaction update.
- class pyrogram.handlers.MessageReactionCountUpdatedHandler¶
 The MessageReactionCountUpdated handler class. Used to handle changes in the anonymous reaction of a message.
It is intended to be used with
add_handler().For a nicer way to register this handler, have a look at the
on_message_reaction_count_updated()decorator.- Parameters:¶
 callback (
Callable) – Pass a function that will be called when a new MessageReactionCountUpdated event arrives. It takes (client, message_reaction_count_updated) as positional arguments (look at the section below for a detailed description).filters (
Filters) – Pass one or more filters to allow only a subset of updates to be passed in your callback function.
- Other Parameters:¶
 client (
Client) – The Client itself, useful when you want to call other API methods inside the handler.message_reaction_count_updated (
MessageReactionCountUpdated) – The received message reaction count update.
- class pyrogram.handlers.InlineQueryHandler¶
 The InlineQuery handler class. Used to handle inline queries. It is intended to be used with
add_handler()For a nicer way to register this handler, have a look at the
on_inline_query()decorator.- Parameters:¶
 callback (
Callable) – Pass a function that will be called when a new InlineQuery arrives. It takes (client, inline_query) as positional arguments (look at the section below for a detailed description).filters (
Filters) – Pass one or more filters to allow only a subset of inline queries to be passed in your callback function.
- Other Parameters:¶
 client (
Client) – The Client itself, useful when you want to call other API methods inside the inline query handler.inline_query (
InlineQuery) – The received inline query.
- class pyrogram.handlers.ChosenInlineResultHandler¶
 The ChosenInlineResultHandler handler class. Used to handle chosen inline results coming from inline queries. It is intended to be used with
add_handler()For a nicer way to register this handler, have a look at the
on_chosen_inline_result()decorator.- Parameters:¶
 callback (
Callable) – Pass a function that will be called when a new chosen inline result arrives. It takes (client, chosen_inline_result) as positional arguments (look at the section below for a detailed description).filters (
Filters) – Pass one or more filters to allow only a subset of chosen inline results to be passed in your callback function.
- Other Parameters:¶
 client (
Client) – The Client itself, useful when you want to call other API methods inside the message handler.chosen_inline_result (
ChosenInlineResult) – The received chosen inline result.
- class pyrogram.handlers.ChatMemberUpdatedHandler¶
 The ChatMemberUpdated handler class. Used to handle changes in the status of a chat member. It is intended to be used with
add_handler().For a nicer way to register this handler, have a look at the
on_chat_member_updated()decorator.- Parameters:¶
 callback (
Callable) – Pass a function that will be called when a new ChatMemberUpdated event arrives. It takes (client, chat_member_updated) as positional arguments (look at the section below for a detailed description).filters (
Filters) – Pass one or more filters to allow only a subset of updates to be passed in your callback function.
- Other Parameters:¶
 client (
Client) – The Client itself, useful when you want to call other API methods inside the handler.chat_member_updated (
ChatMemberUpdated) – The received chat member update.
- class pyrogram.handlers.UserStatusHandler¶
 The UserStatus handler class. Used to handle user status updates (user going online or offline). It is intended to be used with
add_handler().For a nicer way to register this handler, have a look at the
on_user_status()decorator.- Parameters:¶
 callback (
Callable) – Pass a function that will be called when a new user status update arrives. It takes (client, user) as positional arguments (look at the section below for a detailed description).filters (
Filters) – Pass one or more filters to allow only a subset of users to be passed in your callback function.
- Other Parameters:¶
 
- class pyrogram.handlers.StoryHandler¶
 The Story handler class. Used to handle new stories. It is intended to be used with
add_handler()For a nicer way to register this handler, have a look at the
on_story()decorator.- Parameters:¶
 callback (
Callable) – Pass a function that will be called when a new Stories arrives. It takes (client, story) as positional arguments (look at the section below for a detailed description).filters (
Filters) – Pass one or more filters to allow only a subset of stories to be passed in your callback function.
- Other Parameters:¶
 
- class pyrogram.handlers.PollHandler¶
 The Poll handler class. Used to handle polls updates.
It is intended to be used with
add_handler()For a nicer way to register this handler, have a look at the
on_poll()decorator.- Parameters:¶
 callback (
Callable) – Pass a function that will be called when a new poll update arrives. It takes (client, poll) as positional arguments (look at the section below for a detailed description).filters (
Filters) – Pass one or more filters to allow only a subset of polls to be passed in your callback function.
- Other Parameters:¶
 
- class pyrogram.handlers.DisconnectHandler¶
 The Disconnect handler class. Used to handle disconnections. It is intended to be used with
add_handler()For a nicer way to register this handler, have a look at the
on_disconnect()decorator.- Parameters:¶
 callback (
Callable) – Pass a function that will be called when a disconnection occurs. It takes (client) as positional argument (look at the section below for a detailed description).- Other Parameters:¶
 client (
Client) – The Client itself. Useful, for example, when you want to change the proxy before a new connection is established.
- class pyrogram.handlers.RawUpdateHandler¶
 The Raw Update handler class. Used to handle raw updates. It is intended to be used with
add_handler()For a nicer way to register this handler, have a look at the
on_raw_update()decorator.- Parameters:¶
 callback (
Callable) – A function that will be called when a new update is received from the server. It takes (client, update, users, chats) as positional arguments (look at the section below for a detailed description).filters (
Filters) – Pass one or more filters to allow only a subset of callback queries to be passed in your callback function.
- Other Parameters:¶
 client (
Client) – The Client itself, useful when you want to call other API methods inside the update handler.update (
Update) – The received update, which can be one of the many single Updates listed in theUpdatebase type.users (
dict) – Dictionary of allUsermentioned in the update. You can access extra info about the user (such as first_name, last_name, etc…) by using the IDs you find in the update argument (e.g.: users[1768841572]).chats (
dict) – Dictionary of allChatandChannelmentioned in the update. You can access extra info about the chat (such as title, participants_count, etc…) by using the IDs you find in the update argument (e.g.: chats[1701277281]).
Note
The following Empty or Forbidden types may exist inside the users and chats dictionaries. They mean you have been blocked by the user or banned from the group/channel.
- class pyrogram.handlers.ErrorHandler¶
 The Error handler class. Used to handle errors. It is intended to be used with
add_handler()For a nicer way to register this handler, have a look at the
on_error()decorator.- Parameters:¶
 callback (
Callable) – Pass a function that will be called when a new Error arrives. It takes (client, error) as positional arguments (look at the section below for a detailed description).exceptions (
Exception| Iterable ofException, optional) – Pass one or more exception classes to allow only a subset of errors to be passed in your callback function.
- Other Parameters:¶
 client (
Client) – The Client itself, useful when you want to call other API methods inside the error handler.update (
Update) – The update that caused the error.error (
Exception) – The error that was raised.