telegram.ext.messagehandler module

This module contains the MessageHandler class

class telegram.ext.messagehandler.MessageHandler(filters, callback, allow_edited=False, pass_update_queue=False, pass_job_queue=False, pass_user_data=False, pass_chat_data=False, message_updates=True, channel_post_updates=True, edited_updates=False)

Bases: telegram.ext.handler.Handler

Handler class to handle telegram messages. Messages are Telegram Updates that do not contain a command. They might contain text, media or status updates.

Parameters:
  • filters (telegram.ext.BaseFilter) – A filter inheriting from telegram.ext.filters.BaseFilter. Standard filters can be found in telegram.ext.filters.Filters. Filters can be combined using bitwise operators (& for and, | for or).
  • callback (function) – A function that takes bot, update as positional arguments. It will be called when the check_update has determined that an update should be processed by this handler.
  • pass_update_queue (optional[bool]) – If the handler should be passed the update queue as a keyword argument called update_queue. It can be used to insert updates. Default is False
  • pass_user_data (optional[bool]) – If set to True, a keyword argument called user_data will be passed to the callback function. It will be a dict you can use to keep any data related to the user that sent the update. For each update of the same user, it will be the same dict. Default is False.
  • pass_chat_data (optional[bool]) – If set to True, a keyword argument called chat_data will be passed to the callback function. It will be a dict you can use to keep any data related to the chat that the update was sent in. For each update in the same chat, it will be the same dict. Default is False.
  • message_updates (Optional[bool]) – Should “normal” message updates be handled? Default is True.
  • allow_edited (Optional[bool]) – If the handler should also accept edited messages. Default is False - Deprecated. use edited updates instead.
  • channel_post_updates (Optional[bool]) – Should channel posts updates be handled? Default is True.
  • edited_updates (Optional[bool]) – Should “edited” message updates be handled? Default is False.
check_update(update)
handle_update(update, dispatcher)