Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Toggle table of contents sidebar

# MessageReactionHandler

class telegram.ext.MessageReactionHandler(callback, chat_id=None, chat_username=None, user_id=None, user_username=None, message_reaction_types=1, block=True)

  Bases: `telegram.ext.BaseHandler`

  Handler class to handle Telegram updates that contain a message reaction.

  Note

  The following rules apply to both `username` and the `chat_id` param groups, respectively:

  > - If none of them are passed, the handler does not filter the update for that specific

  >     attribute.

  > - If a chat ID or a username is passed, the updates will be filtered with that

  >     specific attribute.

  > - If a chat ID and a username are passed, an update containing any of them will be

  >     filtered.

  > - `telegram.MessageReactionUpdated.actor_chat` is not considered for `user_id` and `user_username` filtering.

  Warning

  When setting `block` to `False`, you cannot rely on adding custom attributes to `telegram.ext.CallbackContext`. See its docs for more info.

  Available In

  `telegram.ext.Application.handlers`

  Added in version 20.8.

  Parameters:

    - callback (coroutine function) –

      The callback function for this handler. Will be called when `check_update()` has determined that an update should be processed by this handler. Callback signature:

          async def callback(update: Update, context: CallbackContext)

      The return value of the callback is usually ignored except for the special case of `telegram.ext.ConversationHandler`.

    - message_reaction_types (`int`, optional) – Pass one of `MESSAGE_REACTION_UPDATED`, `MESSAGE_REACTION_COUNT_UPDATED` or `MESSAGE_REACTION` to specify if this handler should handle only updates with `telegram.Update.message_reaction`, `telegram.Update.message_reaction_count` or both. Defaults to `MESSAGE_REACTION`.

    - chat_id (`int` | Collection[`int`], optional) – Filters reactions to allow only those which happen in the specified chat ID(s).

    - chat_username (`str` | Collection[`str`], optional) – Filters reactions to allow only those which happen in the specified username(s).

    - user_id (`int` | Collection[`int`], optional) – Filters reactions to allow only those which are set by the specified chat ID(s) (this can be the chat itself in the case of anonymous users, see the `telegram.MessageReactionUpdated.actor_chat`).

    - user_username (`str` | Collection[`str`], optional) – Filters reactions to allow only those which are set by the specified username(s) (this can be the chat itself in the case of anonymous users, see the `telegram.MessageReactionUpdated.actor_chat`).

    - block (`bool`, optional) –

      Determines whether the return value of the callback should be awaited before processing the next handler in `telegram.ext.Application.process_update()`. Defaults to `True`.

      See also

      Concurrency

  callback

    The callback function for this handler.

    Type:

      coroutine function

  message_reaction_types

    Optional. Specifies if this handler should handle only updates with `telegram.Update.message_reaction`, `telegram.Update.message_reaction_count` or both.

    Type:

      `int`

  block

    Determines whether the callback will run in a blocking way.

    Type:

      `bool`

  MESSAGE_REACTION = 1

    Used as a constant to handle both `telegram.Update.message_reaction` and `telegram.Update.message_reaction_count`.

    Type:

      `int`

  MESSAGE_REACTION_COUNT_UPDATED = 0

    Used as a constant to handle only `telegram.Update.message_reaction_count`.

    Type:

      `int`

  MESSAGE_REACTION_UPDATED = -1

    Used as a constant to handle only `telegram.Update.message_reaction`.

    Type:

      `int`

  check_update(update)

    Determines whether an update should be passed to this handler’s `callback`.

    Parameters:

      update (`telegram.Update` | `object`) – Incoming update.

    Returns:

      `bool`