diff --git a/pyrogram/filters.py b/pyrogram/filters.py index b52dfe601d..b3ae701b9d 100644 --- a/pyrogram/filters.py +++ b/pyrogram/filters.py @@ -819,6 +819,33 @@ async def func(flt, client: pyrogram.Client, message: Message): ) +# endregion + + +# region cq_data_filter +def cq_data(data: Union[str, List[str]]): + """Filter callback query updates that match a given string or list of strings. + + Can be applied to handlers that receive :obj:`~pyrogram.types.CallbackQuery` updates. + + Parameters: + data (``str`` | ``List[str]``): + The data or list of data strings to match against the callback query. + + Returns: + :obj:`callable`: A filter function that matches callback query updates based on the provided data. + """ + + async def func(_, __, callback_query: CallbackQuery): + if isinstance(data, str): + return callback_query.data == data + elif isinstance(data, list): + return callback_query.data in data + else: + return False + return filters.create(func) + + # endregion def regex(pattern: Union[str, Pattern], flags: int = 0):