From 3e177648e2696f1542f2b120110b7cfbe7840aaa Mon Sep 17 00:00:00 2001 From: Oleg A Date: Fri, 25 Jun 2021 22:39:16 +0300 Subject: [PATCH] feat: custom placeholders --- aiogram/types/force_reply.py | 25 +++++++++++-------------- aiogram/types/reply_keyboard.py | 17 +++++++++++++---- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/aiogram/types/force_reply.py b/aiogram/types/force_reply.py index 97ec16c6..d6b4f19f 100644 --- a/aiogram/types/force_reply.py +++ b/aiogram/types/force_reply.py @@ -6,31 +6,28 @@ from . import fields class ForceReply(base.TelegramObject): """ - Upon receiving a message with this object, - Telegram clients will display a reply interface to the user - (act as if the user has selected the bot‘s message and tapped ’Reply'). - This can be extremely useful if you want to create user-friendly step-by-step + Upon receiving a message with this object, Telegram clients will + display a reply interface to the user (act as if the user has + selected the bot's message and tapped 'Reply'). This can be + extremely useful if you want to create user-friendly step-by-step interfaces without having to sacrifice privacy mode. - Example: A poll bot for groups runs in privacy mode - (only receives commands, replies to its messages and mentions). - There could be two ways to create a new poll - - The last option is definitely more attractive. - And if you use ForceReply in your bot‘s questions, it will receive the user’s answers even - if it only receives replies, commands and mentions — without any extra work for the user. - https://core.telegram.org/bots/api#forcereply """ force_reply: base.Boolean = fields.Field(default=True) + input_field_placeholder: base.String = fields.Field() selective: base.Boolean = fields.Field() @classmethod - def create(cls, selective: typing.Optional[base.Boolean] = None): + def create(cls, + input_field_placeholder: typing.Optional[base.String] = None, + selective: typing.Optional[base.Boolean] = None, + ) -> 'ForceReply': """ Create new force reply :param selective: + :param input_field_placeholder: :return: """ - return cls(selective=selective) + return cls(selective=selective, input_field_placeholder=input_field_placeholder) diff --git a/aiogram/types/reply_keyboard.py b/aiogram/types/reply_keyboard.py index ffe07ae1..e648e036 100644 --- a/aiogram/types/reply_keyboard.py +++ b/aiogram/types/reply_keyboard.py @@ -18,23 +18,32 @@ class KeyboardButtonPollType(base.TelegramObject): class ReplyKeyboardMarkup(base.TelegramObject): """ - This object represents a custom keyboard with reply options (see Introduction to bots for details and examples). + This object represents a custom keyboard with reply options + (see https://core.telegram.org/bots#keyboards to bots for details + and examples). https://core.telegram.org/bots/api#replykeyboardmarkup """ keyboard: 'typing.List[typing.List[KeyboardButton]]' = fields.ListOfLists(base='KeyboardButton', default=[]) resize_keyboard: base.Boolean = fields.Field() one_time_keyboard: base.Boolean = fields.Field() + input_field_placeholder: base.String = fields.Field() selective: base.Boolean = fields.Field() def __init__(self, keyboard: 'typing.List[typing.List[KeyboardButton]]' = None, resize_keyboard: base.Boolean = None, one_time_keyboard: base.Boolean = None, + input_field_placeholder: base.String = None, selective: base.Boolean = None, row_width: base.Integer = 3): - super(ReplyKeyboardMarkup, self).__init__(keyboard=keyboard, resize_keyboard=resize_keyboard, - one_time_keyboard=one_time_keyboard, selective=selective, - conf={'row_width': row_width}) + super().__init__( + keyboard=keyboard, + resize_keyboard=resize_keyboard, + one_time_keyboard=one_time_keyboard, + input_field_placeholder=input_field_placeholder, + selective=selective, + conf={'row_width': row_width}, + ) @property def row_width(self):