From 3b334227641b6092e8d412e9783d388fcda05fac Mon Sep 17 00:00:00 2001 From: Ali Kamali Date: Wed, 11 Jun 2025 16:54:17 +0330 Subject: [PATCH] update reply markups --- bot/views.py | 1 - component/admin.py | 14 - component/models.py | 6 +- component/serializers.py | 50 +- component/telegram/models.py | 956 ++++++++++++++++++++-------------- component/views.py | 2 +- iam/test/factory.py | 2 +- utils/component_updater.ipynb | 434 ++++++++++----- 8 files changed, 904 insertions(+), 561 deletions(-) diff --git a/bot/views.py b/bot/views.py index 91f2226..eca6b28 100644 --- a/bot/views.py +++ b/bot/views.py @@ -28,7 +28,6 @@ ) from bot.services import generate_code from bot.tasks import deploy_bot -from component.models import Component, InlineKeyboardMarkup from iam.permissions import IsLoginedPermission logger = logging.getLogger(__name__) diff --git a/component/admin.py b/component/admin.py index f9fceaf..1308b60 100644 --- a/component/admin.py +++ b/component/admin.py @@ -3,15 +3,8 @@ from component.models import ( CodeComponent, - ForceReply, - InlineKeyboardButton, - InlineKeyboardMarkup, - Keyboard, - KeyboardButton, Markup, OnMessage, - ReplyKeyboardMarkup, - ReplyKeyboardRemove, SendDocument, SendMessage, SendPhoto, @@ -29,13 +22,6 @@ admin.site.register(SendPhoto) admin.site.register(SendVideo) admin.site.register(SendDocument) -admin.site.register(Keyboard) -admin.site.register(KeyboardButton) -admin.site.register(InlineKeyboardButton) -admin.site.register(InlineKeyboardMarkup) -admin.site.register(ReplyKeyboardMarkup) -admin.site.register(ReplyKeyboardRemove) -admin.site.register(ForceReply) admin.site.register(AddStickerToSet) admin.site.register(CodeComponent) admin.site.register(Markup) diff --git a/component/models.py b/component/models.py index 983e56a..f65ffcb 100644 --- a/component/models.py +++ b/component/models.py @@ -197,7 +197,11 @@ def validate(self) -> None: for row in buttons: assert isinstance(row, list) for button in row: - assert isinstance(button, str) + assert isinstance(button, dict) + assert "value" in button + assert "next_component" in button + assert isinstance(button["value"], str) + assert isinstance(button["next_component"], int) def get_callback_data(self, cell: str) -> str: return f"{self.prent_component.id}-{cell}" diff --git a/component/serializers.py b/component/serializers.py index d105201..aea9527 100644 --- a/component/serializers.py +++ b/component/serializers.py @@ -1,5 +1,6 @@ from django.utils.text import slugify from rest_framework import serializers +from rest_framework.exceptions import ValidationError from component.models import * from component.telegram.serializers import ModelSerializerCustom @@ -79,6 +80,7 @@ class ContentTypeSerializer(serializers.ModelSerializer): path = serializers.SerializerMethodField() component_type = serializers.SerializerMethodField() description = serializers.SerializerMethodField() + reply_markup_supported = serializers.SerializerMethodField() def get_schema(self, obj: ContentType) -> dict: model_class = obj.model_class() @@ -120,6 +122,12 @@ def get_schema(self, obj: ContentType) -> dict: } return schema + def get_reply_markup_supported(self, obj: ContentType) -> bool: + model_class = obj.model_class() + if hasattr(model_class, "reply_markup_supported"): + return model_class().reply_markup_supported + return False + def get_path(self, obj: ContentType) -> str: request = self.context.get("request") # Get the request from context base_url = request.build_absolute_uri("/")[:-1] if request else "" # Get host @@ -139,7 +147,15 @@ def get_component_type(self, obj: ContentType) -> str: class Meta: model = ContentType - fields = ["id", "name", "description", "path", "schema", "component_type"] + fields = [ + "id", + "name", + "description", + "path", + "schema", + "component_type", + "reply_markup_supported", + ] class MarkupSerializer(ModelSerializerCustom): @@ -147,3 +163,35 @@ class Meta: model = Markup fields = "__all__" read_only_fields = ["component_type"] + + def validate_buttons(self, value): + """Validate that buttons follow the correct structure""" + if not isinstance(value, list): + raise ValidationError("Buttons must be a list") + + for row_index, row in enumerate(value): + if not isinstance(row, list): + raise ValidationError(f"Row {row_index} must be a list") + + for button_index, button in enumerate(row): + if not isinstance(button, dict): + raise ValidationError( + f"Button at row {row_index}, column {button_index} must be a dictionary", + ) + + if "value" not in button: + raise ValidationError( + f"Button at row {row_index}, column {button_index} must have a 'value' field", + ) + + if not isinstance(button["value"], str): + raise ValidationError( + f"Button 'value' at row {row_index}, column {button_index} must be a string", + ) + + if not isinstance(button["next_component"], int): + raise ValidationError( + f"Button 'next_component' at row {row_index}, column {button_index} must be an integer", + ) + + return value diff --git a/component/telegram/models.py b/component/telegram/models.py index 556c3ee..7cc753f 100644 --- a/component/telegram/models.py +++ b/component/telegram/models.py @@ -9,114 +9,6 @@ from django.forms.models import model_to_dict -class Keyboard(models.Model): - timestamp = models.DateTimeField(auto_now_add=True) - - class Meta: - pass - - -class InlineKeyboardButton(models.Model): - text = models.CharField(max_length=255, help_text="Text of the button") - url = models.URLField( - null=True, - blank=True, - help_text="Optional. HTTP or tg:// URL to be opened when the button is pressed. Links tg://user?id= can be used to mention a user by their ID without using a username, if this is allowed by their privacy settings.", - ) - callback_data = models.CharField( - max_length=255, - null=True, - blank=True, - help_text="Optional. Data to be sent in a callback query to the bot when the button is pressed, 1-64 bytes", - ) - - -class InlineKeyboardMarkup(Keyboard): - inline_keyboard = models.ManyToManyField( - InlineKeyboardButton, - related_name="inline_keyboards", - help_text="Array of button rows, each represented by an Array of InlineKeyboardButton objects", - ) - - def __str__(self) -> str: - return f"InlineKeyboardMarkup ({self.inline_keyboard.count()} rows)" - - -class KeyboardButton(models.Model): - text = models.CharField(max_length=255, help_text="Text of the button") - request_contact = models.BooleanField( - default=False, - help_text="Optional. If True, the user's phone number will be sent as a contact when the button is pressed. Available in private chats only.", - ) - request_location = models.BooleanField( - default=False, - help_text="Optional. If True, the user's current location will be sent when the button is pressed. Available in private chats only.", - ) - - -class ReplyKeyboardMarkup(Keyboard): - keyboard = models.ManyToManyField( - KeyboardButton, - related_name="reply_keyboards", - help_text="Array of button rows, each represented by an Array of KeyboardButton objects", - ) - is_persistent = models.BooleanField( - default=False, - help_text="Optional. Requests clients to always show the keyboard when the user opens the chat. Defaults to false, in which case the custom keyboard disappears after one use", - ) - resize_keyboard = models.BooleanField( - default=False, - help_text="Requests clients to resize the keyboard vertically for optimal fit", - ) - one_time_keyboard = models.BooleanField( - default=False, - help_text="Requests clients to hide the keyboard as soon as it's been used", - ) - input_field_placeholder = models.CharField( - max_length=255, - help_text="Optional. The placeholder to be shown in the input field when the keyboard is active; 1-64 characters, 0-words", - ) - selective = models.BooleanField( - default=False, - help_text="Optional. Use this parameter if you want to show the keyboard to specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply to a message in the same chat and forum topic, sender of the original message.", - ) - - def __str__(self) -> str: - return f"ReplyKeyboardMarkup ({self.keyboard.count()} rows)" - - -class ReplyKeyboardRemove(Keyboard): - remove_keyboard = models.BooleanField( - default=True, - help_text="Requests clients to remove the custom keyboard (user will not be able to summon this keyboard; if you want to hide the keyboard from sight but keep it accessible, use one_time_keyboard in ReplyKeyboardMarkup)", - ) - selective = models.BooleanField( - default=False, - help_text="Use this parameter if you want to remove the keyboard for specific users only", - ) - - def __str__(self) -> str: - return "ReplyKeyboardRemove" - - -class ForceReply(Keyboard): - force_reply = models.BooleanField( - default=True, - help_text="Shows reply interface to the user, as if they manually selected the bot's message and tapped 'Reply'", - ) - input_field_placeholder = models.CharField( - max_length=64, - help_text="Optional. The placeholder to be shown in the input field when the reply is active; 1-64 characters", - ) - selective = models.BooleanField( - default=False, - help_text="Use this parameter if you want to force reply from specific users only", - ) - - def __str__(self) -> str: - return "ForceReply" - - class Component(models.Model): class ComponentType(models.TextChoices): TELEGRAM = "TELEGRAM", "Telegram API Component" @@ -133,7 +25,6 @@ class ComponentType(models.TextChoices): ) def save(self, *args: list, **kwargs: dict) -> None: - """Automatically sets content type""" if self.pk is None: self.component_content_type = ContentType.objects.get( model=self.__class__.__name__.lower(), @@ -175,7 +66,6 @@ def code_function_name(self) -> str: # -> name of the function in generated cod return f"{self.__class__.__name__.lower()}_{self.pk}" def _get_file_params(self, underlying_object) -> str: - """Extract file parameters from the underlying object.""" file_params = "" for field in underlying_object._meta.get_fields(): if isinstance(field, models.FileField): @@ -187,7 +77,6 @@ def _get_file_params(self, underlying_object) -> str: return file_params def _get_method_name(self, class_name: str) -> str: - """Convert class name to method name format.""" method = "" for c in class_name: if c.isupper(): @@ -196,7 +85,6 @@ def _get_method_name(self, class_name: str) -> str: return method.lstrip("_") def _generate_keyboard_code(self, keyboard) -> list[str]: - """Generate code for keyboard markup.""" if not isinstance(keyboard, InlineKeyboardMarkup): return [] @@ -209,7 +97,6 @@ def _generate_keyboard_code(self, keyboard) -> list[str]: return code def _format_code_component(self, underlying_object) -> list[str]: - """Format code component using black formatter.""" try: import black @@ -228,7 +115,6 @@ def _get_component_params( keyboard, file_params: str, ) -> str: - """Generate parameter string for the component.""" excluded_fields = { "id", "component_ptr", @@ -265,7 +151,6 @@ def _get_component_params( return ", ".join(param_strings) def generate_code(self) -> str: - """Generate code for the telegram component.""" if self.component_type != Component.ComponentType.TELEGRAM: raise NotImplementedError @@ -398,24 +283,15 @@ class SendMessage(Component): blank=True, help_text="Unique identifier of the message effect to be added to the message; for private chats only", ) - content_type = models.ForeignKey( - ContentType, - on_delete=models.CASCADE, - limit_choices_to=Q(model="inlinekeyboardmarkup") - | Q(model="replykeyboardmarkup") - | Q(model="replykeyboardremove") - | Q(model="forcereply"), - null=True, - blank=True, - help_text="Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user", - ) - object_id = models.PositiveIntegerField(null=True, blank=True) - related_to_main = GenericForeignKey("content_type", "object_id") @property def required_fields(self) -> list: return ["chat_id", "text"] + @property + def reply_markup_supported(self) -> bool: + return True + class ForwardMessage(Component): """Use this method to forward messages of any kind. Service messages and messages with protected content can't be forwarded. On success, the sent Message is returned.""" @@ -460,6 +336,10 @@ class ForwardMessage(Component): def required_fields(self) -> list: return ["chat_id", "from_chat_id", "message_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class ForwardMessages(Component): """Use this method to forward multiple messages of any kind. If some of the specified messages can't be found or forwarded, they are skipped. Service messages and messages with protected content can't be forwarded. Album grouping is kept for forwarded messages. On success, an array of MessageId of the sent messages is returned.""" @@ -501,6 +381,10 @@ class ForwardMessages(Component): def required_fields(self) -> list: return ["chat_id", "from_chat_id", "message_ids"] + @property + def reply_markup_supported(self) -> bool: + return False + class CopyMessage(Component): """Use this method to copy messages of any kind. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message. Returns the MessageId of the sent message on success.""" @@ -561,24 +445,15 @@ class CopyMessage(Component): blank=True, help_text="Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance", ) - content_type = models.ForeignKey( - ContentType, - on_delete=models.CASCADE, - limit_choices_to=Q(model="inlinekeyboardmarkup") - | Q(model="replykeyboardmarkup") - | Q(model="replykeyboardremove") - | Q(model="forcereply"), - null=True, - blank=True, - help_text="Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user", - ) - object_id = models.PositiveIntegerField(null=True, blank=True) - related_to_main = GenericForeignKey("content_type", "object_id") @property def required_fields(self) -> list: return ["chat_id", "from_chat_id", "message_id"] + @property + def reply_markup_supported(self) -> bool: + return True + class CopyMessages(Component): """Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessages, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages. On success, an array of MessageId of the sent messages is returned.""" @@ -625,6 +500,10 @@ class CopyMessages(Component): def required_fields(self) -> list: return ["chat_id", "from_chat_id", "message_ids"] + @property + def reply_markup_supported(self) -> bool: + return False + class SendPhoto(Component): """Use this method to send photos. On success, the sent Message is returned.""" @@ -691,24 +570,15 @@ class SendPhoto(Component): blank=True, help_text="Unique identifier of the message effect to be added to the message; for private chats only", ) - content_type = models.ForeignKey( - ContentType, - on_delete=models.CASCADE, - limit_choices_to=Q(model="inlinekeyboardmarkup") - | Q(model="replykeyboardmarkup") - | Q(model="replykeyboardremove") - | Q(model="forcereply"), - null=True, - blank=True, - help_text="Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user", - ) - object_id = models.PositiveIntegerField(null=True, blank=True) - related_to_main = GenericForeignKey("content_type", "object_id") @property def required_fields(self) -> list: return ["chat_id", "photo"] + @property + def reply_markup_supported(self) -> bool: + return True + class SendDocument(Component): """Use this method to send general files. On success, the sent Message is returned. Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future.""" @@ -776,24 +646,15 @@ class SendDocument(Component): blank=True, help_text="Unique identifier of the message effect to be added to the message; for private chats only", ) - content_type = models.ForeignKey( - ContentType, - on_delete=models.CASCADE, - limit_choices_to=Q(model="inlinekeyboardmarkup") - | Q(model="replykeyboardmarkup") - | Q(model="replykeyboardremove") - | Q(model="forcereply"), - null=True, - blank=True, - help_text="Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user", - ) - object_id = models.PositiveIntegerField(null=True, blank=True) - related_to_main = GenericForeignKey("content_type", "object_id") @property def required_fields(self) -> list: return ["chat_id", "document"] + @property + def reply_markup_supported(self) -> bool: + return True + class SendVideo(Component): """Use this method to send video files, Telegram clients support MPEG4 videos (other formats may be sent as Document). On success, the sent Message is returned. Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future.""" @@ -889,24 +750,15 @@ class SendVideo(Component): blank=True, help_text="Unique identifier of the message effect to be added to the message; for private chats only", ) - content_type = models.ForeignKey( - ContentType, - on_delete=models.CASCADE, - limit_choices_to=Q(model="inlinekeyboardmarkup") - | Q(model="replykeyboardmarkup") - | Q(model="replykeyboardremove") - | Q(model="forcereply"), - null=True, - blank=True, - help_text="Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user", - ) - object_id = models.PositiveIntegerField(null=True, blank=True) - related_to_main = GenericForeignKey("content_type", "object_id") @property def required_fields(self) -> list: return ["chat_id", "video"] + @property + def reply_markup_supported(self) -> bool: + return True + class SendAnimation(Component): """Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). On success, the sent Message is returned. Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future.""" @@ -986,24 +838,15 @@ class SendAnimation(Component): blank=True, help_text="Unique identifier of the message effect to be added to the message; for private chats only", ) - content_type = models.ForeignKey( - ContentType, - on_delete=models.CASCADE, - limit_choices_to=Q(model="inlinekeyboardmarkup") - | Q(model="replykeyboardmarkup") - | Q(model="replykeyboardremove") - | Q(model="forcereply"), - null=True, - blank=True, - help_text="Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user", - ) - object_id = models.PositiveIntegerField(null=True, blank=True) - related_to_main = GenericForeignKey("content_type", "object_id") @property def required_fields(self) -> list: return ["chat_id", "animation"] + @property + def reply_markup_supported(self) -> bool: + return True + class SendVoice(Component): """Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .OGG file encoded with OPUS, or in .MP3 format, or in .M4A format (other formats may be sent as Audio or Document). On success, the sent Message is returned. Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future.""" @@ -1065,24 +908,15 @@ class SendVoice(Component): blank=True, help_text="Unique identifier of the message effect to be added to the message; for private chats only", ) - content_type = models.ForeignKey( - ContentType, - on_delete=models.CASCADE, - limit_choices_to=Q(model="inlinekeyboardmarkup") - | Q(model="replykeyboardmarkup") - | Q(model="replykeyboardremove") - | Q(model="forcereply"), - null=True, - blank=True, - help_text="Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user", - ) - object_id = models.PositiveIntegerField(null=True, blank=True) - related_to_main = GenericForeignKey("content_type", "object_id") @property def required_fields(self) -> list: return ["chat_id", "voice"] + @property + def reply_markup_supported(self) -> bool: + return True + class SendVideoNote(Component): """As of v.4.0, Telegram clients support rounded square MPEG4 videos of up to 1 minute long. Use this method to send video messages. On success, the sent Message is returned.""" @@ -1144,24 +978,15 @@ class SendVideoNote(Component): blank=True, help_text="Unique identifier of the message effect to be added to the message; for private chats only", ) - content_type = models.ForeignKey( - ContentType, - on_delete=models.CASCADE, - limit_choices_to=Q(model="inlinekeyboardmarkup") - | Q(model="replykeyboardmarkup") - | Q(model="replykeyboardremove") - | Q(model="forcereply"), - null=True, - blank=True, - help_text="Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user", - ) - object_id = models.PositiveIntegerField(null=True, blank=True) - related_to_main = GenericForeignKey("content_type", "object_id") @property def required_fields(self) -> list: return ["chat_id", "video_note"] + @property + def reply_markup_supported(self) -> bool: + return True + class SendPaidMedia(Component): """Use this method to send paid media. On success, the sent Message is returned.""" @@ -1217,24 +1042,15 @@ class SendPaidMedia(Component): blank=True, help_text="Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance", ) - content_type = models.ForeignKey( - ContentType, - on_delete=models.CASCADE, - limit_choices_to=Q(model="inlinekeyboardmarkup") - | Q(model="replykeyboardmarkup") - | Q(model="replykeyboardremove") - | Q(model="forcereply"), - null=True, - blank=True, - help_text="Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user", - ) - object_id = models.PositiveIntegerField(null=True, blank=True) - related_to_main = GenericForeignKey("content_type", "object_id") @property def required_fields(self) -> list: return ["chat_id", "star_count", "media"] + @property + def reply_markup_supported(self) -> bool: + return True + class SendMediaGroup(Component): """Use this method to send a group of photos, videos, documents or audios as an album. Documents and audio files can be only grouped in an album with messages of the same type. On success, an array of Messages that were sent is returned.""" @@ -1279,6 +1095,10 @@ class SendMediaGroup(Component): def required_fields(self) -> list: return ["chat_id", "media"] + @property + def reply_markup_supported(self) -> bool: + return False + class SendLocation(Component): """Use this method to send point on the map. On success, the sent Message is returned.""" @@ -1348,24 +1168,15 @@ class SendLocation(Component): blank=True, help_text="Unique identifier of the message effect to be added to the message; for private chats only", ) - content_type = models.ForeignKey( - ContentType, - on_delete=models.CASCADE, - limit_choices_to=Q(model="inlinekeyboardmarkup") - | Q(model="replykeyboardmarkup") - | Q(model="replykeyboardremove") - | Q(model="forcereply"), - null=True, - blank=True, - help_text="Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user", - ) - object_id = models.PositiveIntegerField(null=True, blank=True) - related_to_main = GenericForeignKey("content_type", "object_id") @property def required_fields(self) -> list: return ["chat_id", "latitude", "longitude"] + @property + def reply_markup_supported(self) -> bool: + return True + class SendVenue(Component): """Use this method to send information about a venue. On success, the sent Message is returned.""" @@ -1437,24 +1248,15 @@ class SendVenue(Component): blank=True, help_text="Unique identifier of the message effect to be added to the message; for private chats only", ) - content_type = models.ForeignKey( - ContentType, - on_delete=models.CASCADE, - limit_choices_to=Q(model="inlinekeyboardmarkup") - | Q(model="replykeyboardmarkup") - | Q(model="replykeyboardremove") - | Q(model="forcereply"), - null=True, - blank=True, - help_text="Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user", - ) - object_id = models.PositiveIntegerField(null=True, blank=True) - related_to_main = GenericForeignKey("content_type", "object_id") @property def required_fields(self) -> list: return ["chat_id", "latitude", "longitude", "title", "address"] + @property + def reply_markup_supported(self) -> bool: + return True + class SendContact(Component): """Use this method to send phone contacts. On success, the sent Message is returned.""" @@ -1510,24 +1312,15 @@ class SendContact(Component): blank=True, help_text="Unique identifier of the message effect to be added to the message; for private chats only", ) - content_type = models.ForeignKey( - ContentType, - on_delete=models.CASCADE, - limit_choices_to=Q(model="inlinekeyboardmarkup") - | Q(model="replykeyboardmarkup") - | Q(model="replykeyboardremove") - | Q(model="forcereply"), - null=True, - blank=True, - help_text="Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user", - ) - object_id = models.PositiveIntegerField(null=True, blank=True) - related_to_main = GenericForeignKey("content_type", "object_id") @property def required_fields(self) -> list: return ["chat_id", "phone_number", "first_name"] + @property + def reply_markup_supported(self) -> bool: + return True + class SendPoll(Component): """Use this method to send a native poll. On success, the sent Message is returned.""" @@ -1624,24 +1417,15 @@ class SendPoll(Component): blank=True, help_text="Unique identifier of the message effect to be added to the message; for private chats only", ) - content_type = models.ForeignKey( - ContentType, - on_delete=models.CASCADE, - limit_choices_to=Q(model="inlinekeyboardmarkup") - | Q(model="replykeyboardmarkup") - | Q(model="replykeyboardremove") - | Q(model="forcereply"), - null=True, - blank=True, - help_text="Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user", - ) - object_id = models.PositiveIntegerField(null=True, blank=True) - related_to_main = GenericForeignKey("content_type", "object_id") @property def required_fields(self) -> list: return ["chat_id", "question", "options"] + @property + def reply_markup_supported(self) -> bool: + return True + class SendDice(Component): """Use this method to send an animated emoji that will display a random value. On success, the sent Message is returned.""" @@ -1686,24 +1470,15 @@ class SendDice(Component): blank=True, help_text="Unique identifier of the message effect to be added to the message; for private chats only", ) - content_type = models.ForeignKey( - ContentType, - on_delete=models.CASCADE, - limit_choices_to=Q(model="inlinekeyboardmarkup") - | Q(model="replykeyboardmarkup") - | Q(model="replykeyboardremove") - | Q(model="forcereply"), - null=True, - blank=True, - help_text="Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user", - ) - object_id = models.PositiveIntegerField(null=True, blank=True) - related_to_main = GenericForeignKey("content_type", "object_id") @property def required_fields(self) -> list: return ["chat_id"] + @property + def reply_markup_supported(self) -> bool: + return True + class SetMessageReaction(Component): """Use this method to change the chosen reactions on a message. Service messages of some types can't be reacted to. Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. Bots can't use paid reactions. Returns True on success.""" @@ -1728,6 +1503,10 @@ class SetMessageReaction(Component): def required_fields(self) -> list: return ["chat_id", "message_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class GetUserProfilePhotos(Component): """Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object.""" @@ -1752,6 +1531,10 @@ class GetUserProfilePhotos(Component): def required_fields(self) -> list: return ["user_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class SetUserEmojiStatus(Component): """Changes the emoji status for a given user that previously allowed the bot to manage their emoji status via the Mini App method requestEmojiStatusAccess. Returns True on success.""" @@ -1776,6 +1559,10 @@ class SetUserEmojiStatus(Component): def required_fields(self) -> list: return ["user_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class GetFile(Component): """Use this method to get basic information about a file and prepare it for downloading. For the moment, bots can download files of up to 20MB in size. On success, a File object is returned. The file can then be downloaded via the link https://api.telegram.org/file/bot/, where is taken from the response. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling getFile again.""" @@ -1790,6 +1577,10 @@ class GetFile(Component): def required_fields(self) -> list: return ["file_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class BanChatMember(Component): """Use this method to ban a user in a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the chat on their own using invite links, etc., unless unbanned first. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns True on success.""" @@ -1819,6 +1610,10 @@ class BanChatMember(Component): def required_fields(self) -> list: return ["chat_id", "user_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class UnbanChatMember(Component): """Use this method to unban a previously banned user in a supergroup or channel. The user will not return to the group or channel automatically, but will be able to join via link, etc. The bot must be an administrator for this to work. By default, this method guarantees that after the call the user is not a member of the chat, but will be able to join it. So if the user is a member of the chat they will also be removed from the chat. If you don't want this, use the parameter only_if_banned. Returns True on success.""" @@ -1843,6 +1638,10 @@ class UnbanChatMember(Component): def required_fields(self) -> list: return ["chat_id", "user_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class RestrictChatMember(Component): """Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup for this to work and must have the appropriate administrator rights. Pass True for all permissions to lift restrictions from a user. Returns True on success.""" @@ -1872,6 +1671,10 @@ class RestrictChatMember(Component): def required_fields(self) -> list: return ["chat_id", "user_id", "permissions"] + @property + def reply_markup_supported(self) -> bool: + return False + class PromoteChatMember(Component): """Use this method to promote or demote a user in a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Pass False for all boolean parameters to demote a user. Returns True on success.""" @@ -1966,6 +1769,10 @@ class PromoteChatMember(Component): def required_fields(self) -> list: return ["chat_id", "user_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class SetChatAdministratorCustomTitle(Component): """Use this method to set a custom title for an administrator in a supergroup promoted by the bot. Returns True on success.""" @@ -1991,6 +1798,10 @@ class SetChatAdministratorCustomTitle(Component): def required_fields(self) -> list: return ["chat_id", "user_id", "custom_title"] + @property + def reply_markup_supported(self) -> bool: + return False + class BanChatSenderChat(Component): """Use this method to ban a channel chat in a supergroup or a channel. Until the chat is unbanned, the owner of the banned chat won't be able to send messages on behalf of any of their channels. The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights. Returns True on success.""" @@ -2010,6 +1821,10 @@ class BanChatSenderChat(Component): def required_fields(self) -> list: return ["chat_id", "sender_chat_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class UnbanChatSenderChat(Component): """Use this method to unban a previously banned channel chat in a supergroup or channel. The bot must be an administrator for this to work and must have the appropriate administrator rights. Returns True on success.""" @@ -2029,6 +1844,10 @@ class UnbanChatSenderChat(Component): def required_fields(self) -> list: return ["chat_id", "sender_chat_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class SetChatPermissions(Component): """Use this method to set default chat permissions for all members. The bot must be an administrator in the group or a supergroup for this to work and must have the can_restrict_members administrator rights. Returns True on success.""" @@ -2048,6 +1867,10 @@ class SetChatPermissions(Component): def required_fields(self) -> list: return ["chat_id", "permissions"] + @property + def reply_markup_supported(self) -> bool: + return False + class ExportChatInviteLink(Component): """Use this method to generate a new primary invite link for a chat; any previously generated primary link is revoked. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns the new invite link as String on success.""" @@ -2062,6 +1885,10 @@ class ExportChatInviteLink(Component): def required_fields(self) -> list: return ["chat_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class CreateChatInviteLink(Component): """Use this method to create an additional invite link for a chat. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. The link can be revoked using the method revokeChatInviteLink. Returns the new invite link as ChatInviteLink object.""" @@ -2097,6 +1924,10 @@ class CreateChatInviteLink(Component): def required_fields(self) -> list: return ["chat_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class EditChatInviteLink(Component): """Use this method to edit a non-primary invite link created by the bot. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns the edited invite link as a ChatInviteLink object.""" @@ -2137,6 +1968,10 @@ class EditChatInviteLink(Component): def required_fields(self) -> list: return ["chat_id", "invite_link"] + @property + def reply_markup_supported(self) -> bool: + return False + class CreateChatSubscriptionInviteLink(Component): """Use this method to create a subscription invite link for a channel chat. The bot must have the can_invite_users administrator rights. The link can be edited using the method editChatSubscriptionInviteLink or revoked using the method revokeChatInviteLink. Returns the new invite link as a ChatInviteLink object.""" @@ -2167,6 +2002,10 @@ class CreateChatSubscriptionInviteLink(Component): def required_fields(self) -> list: return ["chat_id", "subscription_period", "subscription_price"] + @property + def reply_markup_supported(self) -> bool: + return False + class EditChatSubscriptionInviteLink(Component): """Use this method to edit a subscription invite link created by the bot. The bot must have the can_invite_users administrator rights. Returns the edited invite link as a ChatInviteLink object.""" @@ -2192,6 +2031,10 @@ class EditChatSubscriptionInviteLink(Component): def required_fields(self) -> list: return ["chat_id", "invite_link"] + @property + def reply_markup_supported(self) -> bool: + return False + class RevokeChatInviteLink(Component): """Use this method to revoke an invite link created by the bot. If the primary link is revoked, a new link is automatically generated. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns the revoked invite link as ChatInviteLink object.""" @@ -2211,6 +2054,10 @@ class RevokeChatInviteLink(Component): def required_fields(self) -> list: return ["chat_id", "invite_link"] + @property + def reply_markup_supported(self) -> bool: + return False + class ApproveChatJoinRequest(Component): """Use this method to approve a chat join request. The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right. Returns True on success.""" @@ -2230,6 +2077,10 @@ class ApproveChatJoinRequest(Component): def required_fields(self) -> list: return ["chat_id", "user_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class DeclineChatJoinRequest(Component): """Use this method to decline a chat join request. The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right. Returns True on success.""" @@ -2249,6 +2100,10 @@ class DeclineChatJoinRequest(Component): def required_fields(self) -> list: return ["chat_id", "user_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class SetChatPhoto(Component): """Use this method to set a new profile photo for the chat. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns True on success.""" @@ -2263,6 +2118,10 @@ class SetChatPhoto(Component): def required_fields(self) -> list: return ["chat_id", "photo"] + @property + def reply_markup_supported(self) -> bool: + return False + class DeleteChatPhoto(Component): """Use this method to delete a chat photo. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns True on success.""" @@ -2277,6 +2136,10 @@ class DeleteChatPhoto(Component): def required_fields(self) -> list: return ["chat_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class SetChatTitle(Component): """Use this method to change the title of a chat. Titles can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns True on success.""" @@ -2297,6 +2160,10 @@ class SetChatTitle(Component): def required_fields(self) -> list: return ["chat_id", "title"] + @property + def reply_markup_supported(self) -> bool: + return False + class SetChatDescription(Component): """Use this method to change the description of a group, a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns True on success.""" @@ -2317,6 +2184,10 @@ class SetChatDescription(Component): def required_fields(self) -> list: return ["chat_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class PinChatMessage(Component): """Use this method to add a message to the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' administrator right in a supergroup or 'can_edit_messages' administrator right in a channel. Returns True on success.""" @@ -2346,6 +2217,10 @@ class PinChatMessage(Component): def required_fields(self) -> list: return ["chat_id", "message_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class UnpinChatMessage(Component): """Use this method to remove a message from the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' administrator right in a supergroup or 'can_edit_messages' administrator right in a channel. Returns True on success.""" @@ -2370,6 +2245,10 @@ class UnpinChatMessage(Component): def required_fields(self) -> list: return ["chat_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class UnpinAllChatMessages(Component): """Use this method to clear the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' administrator right in a supergroup or 'can_edit_messages' administrator right in a channel. Returns True on success.""" @@ -2384,6 +2263,10 @@ class UnpinAllChatMessages(Component): def required_fields(self) -> list: return ["chat_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class LeaveChat(Component): """Use this method for your bot to leave a group, supergroup or channel. Returns True on success.""" @@ -2398,6 +2281,10 @@ class LeaveChat(Component): def required_fields(self) -> list: return ["chat_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class GetChat(Component): """Use this method to get up-to-date information about the chat. Returns a ChatFullInfo object on success.""" @@ -2412,6 +2299,10 @@ class GetChat(Component): def required_fields(self) -> list: return ["chat_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class GetChatAdministrators(Component): """Use this method to get a list of administrators in a chat, which aren't bots. Returns an Array of ChatMember objects.""" @@ -2426,6 +2317,10 @@ class GetChatAdministrators(Component): def required_fields(self) -> list: return ["chat_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class GetChatMemberCount(Component): """Use this method to get the number of members in a chat. Returns Int on success.""" @@ -2440,6 +2335,10 @@ class GetChatMemberCount(Component): def required_fields(self) -> list: return ["chat_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class GetChatMember(Component): """Use this method to get information about a member of a chat. The method is only guaranteed to work for other users if the bot is an administrator in the chat. Returns a ChatMember object on success.""" @@ -2459,6 +2358,10 @@ class GetChatMember(Component): def required_fields(self) -> list: return ["chat_id", "user_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class SetChatStickerSet(Component): """Use this method to set a new group sticker set for a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. Returns True on success.""" @@ -2478,6 +2381,10 @@ class SetChatStickerSet(Component): def required_fields(self) -> list: return ["chat_id", "sticker_set_name"] + @property + def reply_markup_supported(self) -> bool: + return False + class DeleteChatStickerSet(Component): """Use this method to delete a group sticker set from a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. Returns True on success.""" @@ -2492,6 +2399,10 @@ class DeleteChatStickerSet(Component): def required_fields(self) -> list: return ["chat_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class CreateForumTopic(Component): """Use this method to create a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns information about the created topic as a ForumTopic object.""" @@ -2522,6 +2433,10 @@ class CreateForumTopic(Component): def required_fields(self) -> list: return ["chat_id", "name"] + @property + def reply_markup_supported(self) -> bool: + return False + class EditForumTopic(Component): """Use this method to edit name and icon of a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.""" @@ -2552,6 +2467,10 @@ class EditForumTopic(Component): def required_fields(self) -> list: return ["chat_id", "message_thread_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class CloseForumTopic(Component): """Use this method to close an open topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.""" @@ -2571,6 +2490,10 @@ class CloseForumTopic(Component): def required_fields(self) -> list: return ["chat_id", "message_thread_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class ReopenForumTopic(Component): """Use this method to reopen a closed topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.""" @@ -2590,6 +2513,10 @@ class ReopenForumTopic(Component): def required_fields(self) -> list: return ["chat_id", "message_thread_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class DeleteForumTopic(Component): """Use this method to delete a forum topic along with all its messages in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_delete_messages administrator rights. Returns True on success.""" @@ -2609,6 +2536,10 @@ class DeleteForumTopic(Component): def required_fields(self) -> list: return ["chat_id", "message_thread_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class UnpinAllForumTopicMessages(Component): """Use this method to clear the list of pinned messages in a forum topic. The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator right in the supergroup. Returns True on success.""" @@ -2628,6 +2559,10 @@ class UnpinAllForumTopicMessages(Component): def required_fields(self) -> list: return ["chat_id", "message_thread_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class EditGeneralForumTopic(Component): """Use this method to edit the name of the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns True on success.""" @@ -2648,6 +2583,10 @@ class EditGeneralForumTopic(Component): def required_fields(self) -> list: return ["chat_id", "name"] + @property + def reply_markup_supported(self) -> bool: + return False + class CloseGeneralForumTopic(Component): """Use this method to close an open 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns True on success.""" @@ -2662,6 +2601,10 @@ class CloseGeneralForumTopic(Component): def required_fields(self) -> list: return ["chat_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class ReopenGeneralForumTopic(Component): """Use this method to reopen a closed 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. The topic will be automatically unhidden if it was hidden. Returns True on success.""" @@ -2676,6 +2619,10 @@ class ReopenGeneralForumTopic(Component): def required_fields(self) -> list: return ["chat_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class HideGeneralForumTopic(Component): """Use this method to hide the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. The topic will be automatically closed if it was open. Returns True on success.""" @@ -2690,6 +2637,10 @@ class HideGeneralForumTopic(Component): def required_fields(self) -> list: return ["chat_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class UnhideGeneralForumTopic(Component): """Use this method to unhide the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns True on success.""" @@ -2704,6 +2655,10 @@ class UnhideGeneralForumTopic(Component): def required_fields(self) -> list: return ["chat_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class UnpinAllGeneralForumTopicMessages(Component): """Use this method to clear the list of pinned messages in a General forum topic. The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator right in the supergroup. Returns True on success.""" @@ -2718,6 +2673,10 @@ class UnpinAllGeneralForumTopicMessages(Component): def required_fields(self) -> list: return ["chat_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class GetUserChatBoosts(Component): """Use this method to get the list of boosts added to a chat by a user. Requires administrator rights in the chat. Returns a UserChatBoosts object.""" @@ -2737,6 +2696,10 @@ class GetUserChatBoosts(Component): def required_fields(self) -> list: return ["chat_id", "user_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class GetBusinessConnection(Component): """Use this method to get information about the connection of the bot with a business account. Returns a BusinessConnection object on success.""" @@ -2751,6 +2714,10 @@ class GetBusinessConnection(Component): def required_fields(self) -> list: return ["business_connection_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class SetMyCommands(Component): """Use this method to change the list of the bot's commands. See this manual for more details about bot commands. Returns True on success.""" @@ -2765,6 +2732,10 @@ class SetMyCommands(Component): def required_fields(self) -> list: return ["commands"] + @property + def reply_markup_supported(self) -> bool: + return False + class DeleteMyCommands(Component): """Use this method to delete the list of the bot's commands for the given scope and user language. After deletion, higher level commands will be shown to affected users. Returns True on success.""" @@ -2779,6 +2750,10 @@ class DeleteMyCommands(Component): def required_fields(self) -> list: return [] + @property + def reply_markup_supported(self) -> bool: + return False + class GetMyCommands(Component): """Use this method to get the current list of the bot's commands for the given scope and user language. Returns an Array of BotCommand objects. If commands aren't set, an empty list is returned.""" @@ -2793,6 +2768,10 @@ class GetMyCommands(Component): def required_fields(self) -> list: return [] + @property + def reply_markup_supported(self) -> bool: + return False + class SetMyName(Component): """Use this method to change the bot's name. Returns True on success.""" @@ -2813,6 +2792,10 @@ class SetMyName(Component): def required_fields(self) -> list: return [] + @property + def reply_markup_supported(self) -> bool: + return False + class GetMyName(Component): """Use this method to get the current bot name for the given user language. Returns BotName on success.""" @@ -2827,6 +2810,10 @@ class GetMyName(Component): def required_fields(self) -> list: return [] + @property + def reply_markup_supported(self) -> bool: + return False + class SetMyDescription(Component): """Use this method to change the bot's description, which is shown in the chat with the bot if the chat is empty. Returns True on success.""" @@ -2847,6 +2834,10 @@ class SetMyDescription(Component): def required_fields(self) -> list: return [] + @property + def reply_markup_supported(self) -> bool: + return False + class GetMyDescription(Component): """Use this method to get the current bot description for the given user language. Returns BotDescription on success.""" @@ -2861,6 +2852,10 @@ class GetMyDescription(Component): def required_fields(self) -> list: return [] + @property + def reply_markup_supported(self) -> bool: + return False + class SetMyShortDescription(Component): """Use this method to change the bot's short description, which is shown on the bot's profile page and is sent together with the link when users share the bot. Returns True on success.""" @@ -2881,6 +2876,10 @@ class SetMyShortDescription(Component): def required_fields(self) -> list: return [] + @property + def reply_markup_supported(self) -> bool: + return False + class GetMyShortDescription(Component): """Use this method to get the current bot short description for the given user language. Returns BotShortDescription on success.""" @@ -2895,6 +2894,10 @@ class GetMyShortDescription(Component): def required_fields(self) -> list: return [] + @property + def reply_markup_supported(self) -> bool: + return False + class SetChatMenuButton(Component): """Use this method to change the bot's menu button in a private chat, or the default menu button. Returns True on success.""" @@ -2909,6 +2912,10 @@ class SetChatMenuButton(Component): def required_fields(self) -> list: return [] + @property + def reply_markup_supported(self) -> bool: + return False + class GetChatMenuButton(Component): """Use this method to get the current value of the bot's menu button in a private chat, or the default menu button. Returns MenuButton on success.""" @@ -2923,6 +2930,10 @@ class GetChatMenuButton(Component): def required_fields(self) -> list: return [] + @property + def reply_markup_supported(self) -> bool: + return False + class SetMyDefaultAdministratorRights(Component): """Use this method to change the default administrator rights requested by the bot when it's added as an administrator to groups or channels. These rights will be suggested to users, but they are free to modify the list before adding the bot. Returns True on success.""" @@ -2937,6 +2948,10 @@ class SetMyDefaultAdministratorRights(Component): def required_fields(self) -> list: return [] + @property + def reply_markup_supported(self) -> bool: + return False + class GetMyDefaultAdministratorRights(Component): """Use this method to get the current default administrator rights of the bot. Returns ChatAdministratorRights on success.""" @@ -2951,6 +2966,10 @@ class GetMyDefaultAdministratorRights(Component): def required_fields(self) -> list: return [] + @property + def reply_markup_supported(self) -> bool: + return False + class EditMessageText(Component): """Use this method to edit text and game messages. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent.""" @@ -2986,21 +3005,15 @@ class EditMessageText(Component): blank=True, help_text="Mode for parsing entities in the message text. See formatting options for more details.", ) - content_type = models.ForeignKey( - ContentType, - on_delete=models.CASCADE, - limit_choices_to=Q(model="inlinekeyboardmarkup"), - null=True, - blank=True, - help_text="A JSON-serialized object for an inline keyboard.", - ) - object_id = models.PositiveIntegerField(null=True, blank=True) - related_to_main = GenericForeignKey("content_type", "object_id") @property def required_fields(self) -> list: return ["text"] + @property + def reply_markup_supported(self) -> bool: + return True + class EditMessageCaption(Component): """Use this method to edit captions of messages. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent.""" @@ -3041,21 +3054,15 @@ class EditMessageCaption(Component): blank=True, help_text="Pass True, if the caption must be shown above the message media. Supported only for animation, photo and video messages.", ) - content_type = models.ForeignKey( - ContentType, - on_delete=models.CASCADE, - limit_choices_to=Q(model="inlinekeyboardmarkup"), - null=True, - blank=True, - help_text="A JSON-serialized object for an inline keyboard.", - ) - object_id = models.PositiveIntegerField(null=True, blank=True) - related_to_main = GenericForeignKey("content_type", "object_id") @property def required_fields(self) -> list: return [] + @property + def reply_markup_supported(self) -> bool: + return True + class EditMessageMedia(Component): """Use this method to edit animation, audio, document, photo, or video messages, or to add media to text messages. If a message is part of a message album, then it can be edited only to an audio for audio albums, only to a document for document albums and to a photo or a video otherwise. When an inline message is edited, a new file can't be uploaded; use a previously uploaded file via its file_id or specify a URL. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent.""" @@ -3080,21 +3087,15 @@ class EditMessageMedia(Component): blank=True, help_text="Required if chat_id and message_id are not specified. Identifier of the inline message", ) - content_type = models.ForeignKey( - ContentType, - on_delete=models.CASCADE, - limit_choices_to=Q(model="inlinekeyboardmarkup"), - null=True, - blank=True, - help_text="A JSON-serialized object for a new inline keyboard.", - ) - object_id = models.PositiveIntegerField(null=True, blank=True) - related_to_main = GenericForeignKey("content_type", "object_id") @property def required_fields(self) -> list: return ["media"] + @property + def reply_markup_supported(self) -> bool: + return True + class EditMessageLiveLocation(Component): """Use this method to edit live location messages. A location can be edited until its live_period expires or editing is explicitly disabled by a call to stopMessageLiveLocation. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned.""" @@ -3149,21 +3150,15 @@ class EditMessageLiveLocation(Component): blank=True, help_text="The maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified.", ) - content_type = models.ForeignKey( - ContentType, - on_delete=models.CASCADE, - limit_choices_to=Q(model="inlinekeyboardmarkup"), - null=True, - blank=True, - help_text="A JSON-serialized object for a new inline keyboard.", - ) - object_id = models.PositiveIntegerField(null=True, blank=True) - related_to_main = GenericForeignKey("content_type", "object_id") @property def required_fields(self) -> list: return ["latitude", "longitude"] + @property + def reply_markup_supported(self) -> bool: + return True + class StopMessageLiveLocation(Component): """Use this method to stop updating a live location message before live_period expires. On success, if the message is not an inline message, the edited Message is returned, otherwise True is returned.""" @@ -3188,21 +3183,15 @@ class StopMessageLiveLocation(Component): blank=True, help_text="Required if chat_id and message_id are not specified. Identifier of the inline message", ) - content_type = models.ForeignKey( - ContentType, - on_delete=models.CASCADE, - limit_choices_to=Q(model="inlinekeyboardmarkup"), - null=True, - blank=True, - help_text="A JSON-serialized object for a new inline keyboard.", - ) - object_id = models.PositiveIntegerField(null=True, blank=True) - related_to_main = GenericForeignKey("content_type", "object_id") @property def required_fields(self) -> list: return [] + @property + def reply_markup_supported(self) -> bool: + return True + class EditMessageReplyMarkup(Component): """Use this method to edit only the reply markup of messages. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent.""" @@ -3227,21 +3216,15 @@ class EditMessageReplyMarkup(Component): blank=True, help_text="Required if chat_id and message_id are not specified. Identifier of the inline message", ) - content_type = models.ForeignKey( - ContentType, - on_delete=models.CASCADE, - limit_choices_to=Q(model="inlinekeyboardmarkup"), - null=True, - blank=True, - help_text="A JSON-serialized object for an inline keyboard.", - ) - object_id = models.PositiveIntegerField(null=True, blank=True) - related_to_main = GenericForeignKey("content_type", "object_id") @property def required_fields(self) -> list: return [] + @property + def reply_markup_supported(self) -> bool: + return True + class StopPoll(Component): """Use this method to stop a poll which was sent by the bot. On success, the stopped Poll is returned.""" @@ -3261,21 +3244,15 @@ class StopPoll(Component): blank=True, help_text="Identifier of the original message with the poll", ) - content_type = models.ForeignKey( - ContentType, - on_delete=models.CASCADE, - limit_choices_to=Q(model="inlinekeyboardmarkup"), - null=True, - blank=True, - help_text="A JSON-serialized object for a new message inline keyboard.", - ) - object_id = models.PositiveIntegerField(null=True, blank=True) - related_to_main = GenericForeignKey("content_type", "object_id") @property def required_fields(self) -> list: return ["chat_id", "message_id"] + @property + def reply_markup_supported(self) -> bool: + return True + class DeleteMessage(Component): """Use this method to delete a message, including service messages, with the following limitations:- A message can only be deleted if it was sent less than 48 hours ago.- Service messages about a supergroup, channel, or forum topic creation can't be deleted.- A dice message in a private chat can only be deleted if it was sent more than 24 hours ago.- Bots can delete outgoing messages in private chats, groups, and supergroups.- Bots can delete incoming messages in private chats.- Bots granted can_post_messages permissions can delete outgoing messages in channels.- If the bot is an administrator of a group, it can delete any message there.- If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there.Returns True on success.""" @@ -3295,6 +3272,10 @@ class DeleteMessage(Component): def required_fields(self) -> list: return ["chat_id", "message_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class DeleteMessages(Component): """Use this method to delete multiple messages simultaneously. If some of the specified messages can't be found, they are skipped. Returns True on success.""" @@ -3316,6 +3297,10 @@ class DeleteMessages(Component): def required_fields(self) -> list: return ["chat_id", "message_ids"] + @property + def reply_markup_supported(self) -> bool: + return False + class SendGift(Component): """Sends a gift to the given user or channel chat. The gift can't be converted to Telegram Stars by the receiver. Returns True on success.""" @@ -3356,6 +3341,10 @@ class SendGift(Component): def required_fields(self) -> list: return ["gift_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class GiftPremiumSubscription(Component): """Gifts a Telegram Premium subscription to the given user. Returns True on success.""" @@ -3391,6 +3380,10 @@ class GiftPremiumSubscription(Component): def required_fields(self) -> list: return ["user_id", "month_count", "star_count"] + @property + def reply_markup_supported(self) -> bool: + return False + class VerifyUser(Component): """Verifies a user on behalf of the organization which is represented by the bot. Returns True on success.""" @@ -3411,6 +3404,10 @@ class VerifyUser(Component): def required_fields(self) -> list: return ["user_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class VerifyChat(Component): """Verifies a chat on behalf of the organization which is represented by the bot. Returns True on success.""" @@ -3431,6 +3428,10 @@ class VerifyChat(Component): def required_fields(self) -> list: return ["chat_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class RemoveUserVerification(Component): """Removes verification from a user who is currently verified on behalf of the organization represented by the bot. Returns True on success.""" @@ -3445,6 +3446,10 @@ class RemoveUserVerification(Component): def required_fields(self) -> list: return ["user_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class RemoveChatVerification(Component): """Removes verification from a chat that is currently verified on behalf of the organization represented by the bot. Returns True on success.""" @@ -3459,6 +3464,10 @@ class RemoveChatVerification(Component): def required_fields(self) -> list: return ["chat_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class ReadBusinessMessage(Component): """Marks incoming message as read on behalf of a business account. Requires the can_read_messages business bot right. Returns True on success.""" @@ -3483,6 +3492,10 @@ class ReadBusinessMessage(Component): def required_fields(self) -> list: return ["business_connection_id", "chat_id", "message_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class DeleteBusinessMessages(Component): """Delete messages on behalf of a business account. Requires the can_delete_sent_messages business bot right to delete messages sent by the bot itself, or the can_delete_all_messages business bot right to delete any message. Returns True on success.""" @@ -3504,6 +3517,10 @@ class DeleteBusinessMessages(Component): def required_fields(self) -> list: return ["business_connection_id", "message_ids"] + @property + def reply_markup_supported(self) -> bool: + return False + class SetBusinessAccountName(Component): """Changes the first and last name of a managed business account. Requires the can_change_name business bot right. Returns True on success.""" @@ -3530,6 +3547,10 @@ class SetBusinessAccountName(Component): def required_fields(self) -> list: return ["business_connection_id", "first_name"] + @property + def reply_markup_supported(self) -> bool: + return False + class SetBusinessAccountUsername(Component): """Changes the username of a managed business account. Requires the can_change_username business bot right. Returns True on success.""" @@ -3550,6 +3571,10 @@ class SetBusinessAccountUsername(Component): def required_fields(self) -> list: return ["business_connection_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class SetBusinessAccountBio(Component): """Changes the bio of a managed business account. Requires the can_change_bio business bot right. Returns True on success.""" @@ -3570,6 +3595,10 @@ class SetBusinessAccountBio(Component): def required_fields(self) -> list: return ["business_connection_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class SetBusinessAccountProfilePhoto(Component): """Changes the profile photo of a managed business account. Requires the can_edit_profile_photo business bot right. Returns True on success.""" @@ -3589,6 +3618,10 @@ class SetBusinessAccountProfilePhoto(Component): def required_fields(self) -> list: return ["business_connection_id", "photo"] + @property + def reply_markup_supported(self) -> bool: + return False + class RemoveBusinessAccountProfilePhoto(Component): """Removes the current profile photo of a managed business account. Requires the can_edit_profile_photo business bot right. Returns True on success.""" @@ -3608,6 +3641,10 @@ class RemoveBusinessAccountProfilePhoto(Component): def required_fields(self) -> list: return ["business_connection_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class SetBusinessAccountGiftSettings(Component): """Changes the privacy settings pertaining to incoming gifts in a managed business account. Requires the can_change_gift_settings business bot right. Returns True on success.""" @@ -3627,6 +3664,10 @@ class SetBusinessAccountGiftSettings(Component): def required_fields(self) -> list: return ["business_connection_id", "show_gift_button", "accepted_gift_types"] + @property + def reply_markup_supported(self) -> bool: + return False + class GetBusinessAccountStarBalance(Component): """Returns the amount of Telegram Stars owned by a managed business account. Requires the can_view_gifts_and_stars business bot right. Returns StarAmount on success.""" @@ -3641,6 +3682,10 @@ class GetBusinessAccountStarBalance(Component): def required_fields(self) -> list: return ["business_connection_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class TransferBusinessAccountStars(Component): """Transfers Telegram Stars from the business account balance to the bot's balance. Requires the can_transfer_stars business bot right. Returns True on success.""" @@ -3660,6 +3705,10 @@ class TransferBusinessAccountStars(Component): def required_fields(self) -> list: return ["business_connection_id", "star_count"] + @property + def reply_markup_supported(self) -> bool: + return False + class GetBusinessAccountGifts(Component): """Returns the gifts received and owned by a managed business account. Requires the can_view_gifts_and_stars business bot right. Returns OwnedGifts on success.""" @@ -3714,6 +3763,10 @@ class GetBusinessAccountGifts(Component): def required_fields(self) -> list: return ["business_connection_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class ConvertGiftToStars(Component): """Converts a given regular gift to Telegram Stars. Requires the can_convert_gifts_to_stars business bot right. Returns True on success.""" @@ -3733,6 +3786,10 @@ class ConvertGiftToStars(Component): def required_fields(self) -> list: return ["business_connection_id", "owned_gift_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class UpgradeGift(Component): """Upgrades a given regular gift to a unique gift. Requires the can_transfer_and_upgrade_gifts business bot right. Additionally requires the can_transfer_stars business bot right if the upgrade is paid. Returns True on success.""" @@ -3762,6 +3819,10 @@ class UpgradeGift(Component): def required_fields(self) -> list: return ["business_connection_id", "owned_gift_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class TransferGift(Component): """Transfers an owned unique gift to another user. Requires the can_transfer_and_upgrade_gifts business bot right. Requires can_transfer_stars business bot right if the transfer is paid. Returns True on success.""" @@ -3791,6 +3852,10 @@ class TransferGift(Component): def required_fields(self) -> list: return ["business_connection_id", "owned_gift_id", "new_owner_chat_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class PostStory(Component): """Posts a story on behalf of a managed business account. Requires the can_manage_stories business bot right. Returns Story on success.""" @@ -3831,6 +3896,10 @@ class PostStory(Component): def required_fields(self) -> list: return ["business_connection_id", "content", "active_period"] + @property + def reply_markup_supported(self) -> bool: + return False + class EditStory(Component): """Edits a story previously posted by the bot on behalf of a managed business account. Requires the can_manage_stories business bot right. Returns Story on success.""" @@ -3861,6 +3930,10 @@ class EditStory(Component): def required_fields(self) -> list: return ["business_connection_id", "story_id", "content"] + @property + def reply_markup_supported(self) -> bool: + return False + class DeleteStory(Component): """Deletes a story previously posted by the bot on behalf of a managed business account. Requires the can_manage_stories business bot right. Returns True on success.""" @@ -3880,6 +3953,10 @@ class DeleteStory(Component): def required_fields(self) -> list: return ["business_connection_id", "story_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class SendSticker(Component): """Use this method to send static .WEBP, animated .TGS, or video .WEBM stickers. On success, the sent Message is returned.""" @@ -3930,24 +4007,15 @@ class SendSticker(Component): blank=True, help_text="Unique identifier of the message effect to be added to the message; for private chats only", ) - content_type = models.ForeignKey( - ContentType, - on_delete=models.CASCADE, - limit_choices_to=Q(model="inlinekeyboardmarkup") - | Q(model="replykeyboardmarkup") - | Q(model="replykeyboardremove") - | Q(model="forcereply"), - null=True, - blank=True, - help_text="Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user", - ) - object_id = models.PositiveIntegerField(null=True, blank=True) - related_to_main = GenericForeignKey("content_type", "object_id") @property def required_fields(self) -> list: return ["chat_id", "sticker"] + @property + def reply_markup_supported(self) -> bool: + return True + class GetStickerSet(Component): """Use this method to get a sticker set. On success, a StickerSet object is returned.""" @@ -3958,6 +4026,10 @@ class GetStickerSet(Component): def required_fields(self) -> list: return ["name"] + @property + def reply_markup_supported(self) -> bool: + return False + class GetCustomEmojiStickers(Component): """Use this method to get information about custom emoji stickers by their identifiers. Returns an Array of Sticker objects.""" @@ -3974,6 +4046,10 @@ class GetCustomEmojiStickers(Component): def required_fields(self) -> list: return ["custom_emoji_ids"] + @property + def reply_markup_supported(self) -> bool: + return False + class UploadStickerFile(Component): """Use this method to upload a file with a sticker for later use in the createNewStickerSet, addStickerToSet, or replaceStickerInSet methods (the file can be used multiple times). Returns the uploaded File on success.""" @@ -3993,6 +4069,10 @@ class UploadStickerFile(Component): def required_fields(self) -> list: return ["user_id", "sticker", "sticker_format"] + @property + def reply_markup_supported(self) -> bool: + return False + class CreateNewStickerSet(Component): """Use this method to create a new sticker set owned by a user. The bot will be able to edit the sticker set thus created. Returns True on success.""" @@ -4029,6 +4109,10 @@ class CreateNewStickerSet(Component): def required_fields(self) -> list: return ["user_id", "name", "title", "stickers"] + @property + def reply_markup_supported(self) -> bool: + return False + class AddStickerToSet(Component): """Use this method to add a new sticker to a set created by the bot. Emoji sticker sets can have up to 200 stickers. Other sticker sets can have up to 120 stickers. Returns True on success.""" @@ -4044,6 +4128,10 @@ class AddStickerToSet(Component): def required_fields(self) -> list: return ["user_id", "name", "sticker"] + @property + def reply_markup_supported(self) -> bool: + return False + class SetStickerPositionInSet(Component): """Use this method to move a sticker in a set created by the bot to a specific position. Returns True on success.""" @@ -4063,6 +4151,10 @@ class SetStickerPositionInSet(Component): def required_fields(self) -> list: return ["sticker", "position"] + @property + def reply_markup_supported(self) -> bool: + return False + class DeleteStickerFromSet(Component): """Use this method to delete a sticker from a set created by the bot. Returns True on success.""" @@ -4077,6 +4169,10 @@ class DeleteStickerFromSet(Component): def required_fields(self) -> list: return ["sticker"] + @property + def reply_markup_supported(self) -> bool: + return False + class ReplaceStickerInSet(Component): """Use this method to replace an existing sticker in a sticker set with a new one. The method is equivalent to calling deleteStickerFromSet, then addStickerToSet, then setStickerPositionInSet. Returns True on success.""" @@ -4097,6 +4193,10 @@ class ReplaceStickerInSet(Component): def required_fields(self) -> list: return ["user_id", "name", "old_sticker", "sticker"] + @property + def reply_markup_supported(self) -> bool: + return False + class SetStickerEmojiList(Component): """Use this method to change the list of emoji assigned to a regular or custom emoji sticker. The sticker must belong to a sticker set created by the bot. Returns True on success.""" @@ -4118,6 +4218,10 @@ class SetStickerEmojiList(Component): def required_fields(self) -> list: return ["sticker", "emoji_list"] + @property + def reply_markup_supported(self) -> bool: + return False + class SetStickerKeywords(Component): """Use this method to change search keywords assigned to a regular or custom emoji sticker. The sticker must belong to a sticker set created by the bot. Returns True on success.""" @@ -4139,6 +4243,10 @@ class SetStickerKeywords(Component): def required_fields(self) -> list: return ["sticker"] + @property + def reply_markup_supported(self) -> bool: + return False + class SetStickerMaskPosition(Component): """Use this method to change the mask position of a mask sticker. The sticker must belong to a sticker set that was created by the bot. Returns True on success.""" @@ -4153,6 +4261,10 @@ class SetStickerMaskPosition(Component): def required_fields(self) -> list: return ["sticker"] + @property + def reply_markup_supported(self) -> bool: + return False + class SetStickerSetTitle(Component): """Use this method to set the title of a created sticker set. Returns True on success.""" @@ -4169,6 +4281,10 @@ class SetStickerSetTitle(Component): def required_fields(self) -> list: return ["name", "title"] + @property + def reply_markup_supported(self) -> bool: + return False + class SetStickerSetThumbnail(Component): """Use this method to set the thumbnail of a regular or mask sticker set. The format of the thumbnail file must match the format of the stickers in the set. Returns True on success.""" @@ -4195,6 +4311,10 @@ class SetStickerSetThumbnail(Component): def required_fields(self) -> list: return ["name", "user_id", "format"] + @property + def reply_markup_supported(self) -> bool: + return False + class SetCustomEmojiStickerSetThumbnail(Component): """Use this method to set the thumbnail of a custom emoji sticker set. Returns True on success.""" @@ -4210,6 +4330,10 @@ class SetCustomEmojiStickerSetThumbnail(Component): def required_fields(self) -> list: return ["name"] + @property + def reply_markup_supported(self) -> bool: + return False + class DeleteStickerSet(Component): """Use this method to delete a sticker set that was created by the bot. Returns True on success.""" @@ -4220,6 +4344,10 @@ class DeleteStickerSet(Component): def required_fields(self) -> list: return ["name"] + @property + def reply_markup_supported(self) -> bool: + return False + class AnswerInlineQuery(Component): """Use this method to send answers to an inline query. On success, True is returned.No more than 50 results per query are allowed.""" @@ -4249,6 +4377,10 @@ class AnswerInlineQuery(Component): def required_fields(self) -> list: return ["inline_query_id", "results"] + @property + def reply_markup_supported(self) -> bool: + return False + class AnswerWebAppQuery(Component): """Use this method to set the result of an interaction with a Web App and send a corresponding message on behalf of the user to the chat from which the query originated. On success, a SentWebAppMessage object is returned.""" @@ -4263,6 +4395,10 @@ class AnswerWebAppQuery(Component): def required_fields(self) -> list: return ["web_app_query_id", "result"] + @property + def reply_markup_supported(self) -> bool: + return False + class SavePreparedInlineMessage(Component): """Stores a message that can be sent by a user of a Mini App. Returns a PreparedInlineMessage object.""" @@ -4297,6 +4433,10 @@ class SavePreparedInlineMessage(Component): def required_fields(self) -> list: return ["user_id", "result"] + @property + def reply_markup_supported(self) -> bool: + return False + class SendInvoice(Component): """Use this method to send invoices. On success, the sent Message is returned.""" @@ -4427,21 +4567,15 @@ class SendInvoice(Component): blank=True, help_text="Unique identifier of the message effect to be added to the message; for private chats only", ) - content_type = models.ForeignKey( - ContentType, - on_delete=models.CASCADE, - limit_choices_to=Q(model="inlinekeyboardmarkup"), - null=True, - blank=True, - help_text="A JSON-serialized object for an inline keyboard. If empty, one 'Pay total price' button will be shown. If not empty, the first button must be a Pay button.", - ) - object_id = models.PositiveIntegerField(null=True, blank=True) - related_to_main = GenericForeignKey("content_type", "object_id") @property def required_fields(self) -> list: return ["chat_id", "title", "description", "payload", "currency", "prices"] + @property + def reply_markup_supported(self) -> bool: + return True + class CreateInvoiceLink(Component): """Use this method to create a link for an invoice. Returns the created invoice link as String on success.""" @@ -4552,6 +4686,10 @@ class CreateInvoiceLink(Component): def required_fields(self) -> list: return ["title", "description", "payload", "currency", "prices"] + @property + def reply_markup_supported(self) -> bool: + return False + class AnswerShippingQuery(Component): """If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API will send an Update with a shipping_query field to the bot. Use this method to reply to shipping queries. On success, True is returned.""" @@ -4576,6 +4714,10 @@ class AnswerShippingQuery(Component): def required_fields(self) -> list: return ["shipping_query_id", "ok"] + @property + def reply_markup_supported(self) -> bool: + return False + class AnswerPreCheckoutQuery(Component): """Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form of an Update with the field pre_checkout_query. Use this method to respond to such pre-checkout queries. On success, True is returned. Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent.""" @@ -4600,6 +4742,10 @@ class AnswerPreCheckoutQuery(Component): def required_fields(self) -> list: return ["pre_checkout_query_id", "ok"] + @property + def reply_markup_supported(self) -> bool: + return False + class GetStarTransactions(Component): """Returns the bot's Telegram Star transactions in chronological order. On success, returns a StarTransactions object.""" @@ -4619,6 +4765,10 @@ class GetStarTransactions(Component): def required_fields(self) -> list: return [] + @property + def reply_markup_supported(self) -> bool: + return False + class RefundStarPayment(Component): """Refunds a successful payment in Telegram Stars. Returns True on success.""" @@ -4638,6 +4788,10 @@ class RefundStarPayment(Component): def required_fields(self) -> list: return ["user_id", "telegram_payment_charge_id"] + @property + def reply_markup_supported(self) -> bool: + return False + class EditUserStarSubscription(Component): """Allows the bot to cancel or re-enable extension of a subscription paid in Telegram Stars. Returns True on success.""" @@ -4662,6 +4816,10 @@ class EditUserStarSubscription(Component): def required_fields(self) -> list: return ["user_id", "telegram_payment_charge_id", "is_canceled"] + @property + def reply_markup_supported(self) -> bool: + return False + class SendGame(Component): """Use this method to send a game. On success, the sent Message is returned.""" @@ -4706,21 +4864,15 @@ class SendGame(Component): blank=True, help_text="Unique identifier of the message effect to be added to the message; for private chats only", ) - content_type = models.ForeignKey( - ContentType, - on_delete=models.CASCADE, - limit_choices_to=Q(model="inlinekeyboardmarkup"), - null=True, - blank=True, - help_text="A JSON-serialized object for an inline keyboard. If empty, one 'Play game_title' button will be shown. If not empty, the first button must launch the game.", - ) - object_id = models.PositiveIntegerField(null=True, blank=True) - related_to_main = GenericForeignKey("content_type", "object_id") @property def required_fields(self) -> list: return ["chat_id", "game_short_name"] + @property + def reply_markup_supported(self) -> bool: + return True + class SetGameScore(Component): """Use this method to set the score of the specified user in a game message. On success, if the message is not an inline message, the Message is returned, otherwise True is returned. Returns an error, if the new score is not greater than the user's current score in the chat and force is False.""" @@ -4760,3 +4912,7 @@ class SetGameScore(Component): @property def required_fields(self) -> list: return ["user_id", "score"] + + @property + def reply_markup_supported(self) -> bool: + return False diff --git a/component/views.py b/component/views.py index 2b2939a..6686629 100644 --- a/component/views.py +++ b/component/views.py @@ -33,7 +33,7 @@ class OnMessageSet(ModelViewSetCustom): class ContentTypeListView(ListAPIView): - permission_classes = [IsLoginedPermission, IsBotOwner] + # permission_classes = [IsLoginedPermission, IsBotOwner] queryset = ContentType.objects.filter( Q(app_label="component") & ~Q(model="component") & ~Q(model="keyboard"), ) diff --git a/iam/test/factory.py b/iam/test/factory.py index 1ffc871..7c8846a 100644 --- a/iam/test/factory.py +++ b/iam/test/factory.py @@ -1,6 +1,6 @@ -import factory from faker import Faker +import factory from iam.models import IamUser fake = Faker() diff --git a/utils/component_updater.ipynb b/utils/component_updater.ipynb index b802152..cad8d23 100644 --- a/utils/component_updater.ipynb +++ b/utils/component_updater.ipynb @@ -2,24 +2,25 @@ "cells": [ { "cell_type": "code", + "execution_count": 1, "id": "initial_id", "metadata": { - "collapsed": true, "ExecuteTime": { "end_time": "2025-05-02T18:21:48.937158Z", "start_time": "2025-05-02T18:21:48.934972Z" - } + }, + "collapsed": true }, + "outputs": [], "source": [ "import re\n", "import requests\n", "from bs4 import BeautifulSoup" - ], - "outputs": [], - "execution_count": 109 + ] }, { "cell_type": "code", + "execution_count": 2, "id": "c9f426c907d39913", "metadata": { "ExecuteTime": { @@ -27,17 +28,17 @@ "start_time": "2025-05-02T18:21:48.984891Z" } }, + "outputs": [], "source": [ "proxies = {\n", " \"http\": \"http://127.0.0.1:2080\", # Replace with your proxy address\n", " \"https\": \"http://127.0.0.1:2080\" # For HTTPS requests as well\n", "}\n" - ], - "outputs": [], - "execution_count": 110 + ] }, { "cell_type": "code", + "execution_count": 3, "id": "40f0e82542f522c1", "metadata": { "ExecuteTime": { @@ -45,14 +46,14 @@ "start_time": "2025-05-02T18:21:49.031384Z" } }, + "outputs": [], "source": [ "res = requests.get(\"https://core.telegram.org/bots/api\", proxies=proxies)" - ], - "outputs": [], - "execution_count": 111 + ] }, { "cell_type": "code", + "execution_count": 7, "id": "ae1e8b23f5c23dc6", "metadata": { "ExecuteTime": { @@ -60,14 +61,14 @@ "start_time": "2025-05-02T18:21:49.762476Z" } }, + "outputs": [], "source": [ "pattern = r'

<\\/i><\\/a>(.*?)<\\/h4>\\s+

(.*?)<\\/p>\\s+\\s+\\s+\\s+\\s+\\s+\\s+\\s+\\s+'" - ], - "outputs": [], - "execution_count": 114 + ] }, { "cell_type": "code", + "execution_count": 10, "id": "ca64487b33fe0082", "metadata": { "ExecuteTime": { @@ -105,14 +106,14 @@ "start_time": "2025-05-02T18:21:49.906578Z" } }, + "outputs": [], "source": [ "max_char_pattern = r'-(\\d+) characters'" - ], - "outputs": [], - "execution_count": 115 + ] }, { "cell_type": "code", + "execution_count": 11, "id": "a7b3feaca0bf5a65", "metadata": { "ExecuteTime": { @@ -120,15 +121,15 @@ "start_time": "2025-05-02T18:21:49.952575Z" } }, + "outputs": [], "source": [ "def text_cleaner(text):\n", " return BeautifulSoup(text, 'html.parser').get_text().replace('\"', '\\\\\"')" - ], - "outputs": [], - "execution_count": 116 + ] }, { "cell_type": "code", + "execution_count": 24, "id": "b8277c6cbd6e0c1b", "metadata": { "ExecuteTime": { @@ -136,73 +137,28 @@ "start_time": "2025-05-02T18:21:49.999757Z" } }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "not supported: 26\n", + "['Array of MessageEntity', 'LinkPreviewOptions', 'ReplyParameters', 'Array of InputPaidMedia', 'Array of InputMediaAudio, InputMediaDocument, InputMediaPhoto and InputMediaVideo', 'Array of InputPollOption', 'Array of ReactionType', 'ChatPermissions', 'InputFile', 'Array of BotCommand', 'BotCommandScope', 'MenuButton', 'ChatAdministratorRights', 'InputMedia', 'InputProfilePhoto', 'AcceptedGiftTypes', 'InputStoryContent', 'Array of StoryArea', 'Array of InputSticker', 'InputSticker', 'MaskPosition', 'Array of InlineQueryResult', 'InlineQueryResultsButton', 'InlineQueryResult', 'Array of LabeledPrice', 'Array of ShippingOption']\n" + ] + } + ], "source": [ "with open('../component/telegram/models.py', 'w') as file:\n", " file.write(\"\"\"from django.contrib.postgres.fields import ArrayField\n", - "from django.db import models\n", + "from typing import List\n", + "\n", + "from django.conf import settings\n", "from django.contrib.contenttypes.fields import GenericForeignKey\n", "from django.contrib.contenttypes.models import ContentType\n", + "from django.contrib.postgres.fields import ArrayField\n", + "from django.db import models\n", "from django.db.models import Q\n", - "\n", - "\n", - "class Keyboard(models.Model):\n", - " timestamp = models.DateTimeField(auto_now_add=True)\n", - " \n", - " class Meta:\n", - " pass\n", - "\n", - "\n", - "class InlineKeyboardButton(models.Model):\n", - " text = models.CharField(max_length=255, help_text=\"Text of the button\")\n", - " url = models.URLField(null=True, blank=True, help_text=\"Optional. HTTP or tg:// URL to be opened when the button is pressed. Links tg://user?id= can be used to mention a user by their ID without using a username, if this is allowed by their privacy settings.\")\n", - " callback_data = models.CharField(max_length=255, null=True, blank=True, help_text=\"Optional. Data to be sent in a callback query to the bot when the button is pressed, 1-64 bytes\")\n", - " \n", - "\n", - "class InlineKeyboardMarkup(Keyboard):\n", - " inline_keyboard = models.ManyToManyField(InlineKeyboardButton, related_name=\"inline_keyboards\", help_text=\"Array of button rows, each represented by an Array of InlineKeyboardButton objects\")\n", - "\n", - " def __str__(self) -> str:\n", - " return f\"InlineKeyboardMarkup ({self.inline_keyboard.count()} rows)\"\n", - "\n", - "class KeyboardButton(models.Model):\n", - " text = models.CharField(max_length=255, help_text=\"Text of the button\")\n", - " request_contact = models.BooleanField(default=False, help_text=\"Optional. If True, the user's phone number will be sent as a contact when the button is pressed. Available in private chats only.\")\n", - " request_location = models.BooleanField(default=False, help_text=\"Optional. If True, the user's current location will be sent when the button is pressed. Available in private chats only.\")\n", - "\n", - "class ReplyKeyboardMarkup(Keyboard):\n", - " keyboard = models.ManyToManyField(KeyboardButton, related_name=\"reply_keyboards\", help_text=\"Array of button rows, each represented by an Array of KeyboardButton objects\")\n", - " is_persistent = models.BooleanField(default=False, help_text=\"Optional. Requests clients to always show the keyboard when the user opens the chat. Defaults to false, in which case the custom keyboard disappears after one use\")\n", - " resize_keyboard = models.BooleanField(default=False, help_text=\"Requests clients to resize the keyboard vertically for optimal fit\")\n", - " one_time_keyboard = models.BooleanField(default=False, help_text=\"Requests clients to hide the keyboard as soon as it's been used\")\n", - " input_field_placeholder = models.CharField(max_length=255, help_text=\"Optional. The placeholder to be shown in the input field when the keyboard is active; 1-64 characters, 0-words\")\n", - " selective = models.BooleanField(default=False, help_text=\"Optional. Use this parameter if you want to show the keyboard to specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply to a message in the same chat and forum topic, sender of the original message.\")\n", - " \n", - " def __str__(self) -> str:\n", - " return f\"ReplyKeyboardMarkup ({self.keyboard.count()} rows)\"\n", - "\n", - "\n", - "class ReplyKeyboardRemove(Keyboard):\n", - " remove_keyboard = models.BooleanField(default=True, help_text=\"Requests clients to remove the custom keyboard (user will not be able to summon this keyboard; if you want to hide the keyboard from sight but keep it accessible, use one_time_keyboard in ReplyKeyboardMarkup)\",\n", - " )\n", - " selective = models.BooleanField(default=False, help_text=\"Use this parameter if you want to remove the keyboard for specific users only\")\n", - " \n", - " def __str__(self) -> str:\n", - " return \"ReplyKeyboardRemove\"\n", - "\n", - "\n", - "class ForceReply(Keyboard):\n", - " force_reply = models.BooleanField(\n", - " default=True,\n", - " help_text=\"Shows reply interface to the user, as if they manually selected the bot's message and tapped 'Reply'\",\n", - " )\n", - " input_field_placeholder = models.CharField(\n", - " max_length=64,\n", - " help_text=\"Optional. The placeholder to be shown in the input field when the reply is active; 1-64 characters\",\n", - " )\n", - " selective = models.BooleanField(default=False, help_text=\"Use this parameter if you want to force reply from specific users only\")\n", - " \n", - " def __str__(self) -> str:\n", - " return \"ForceReply\"\n", + "from django.forms.models import model_to_dict\n", " \n", "class Component(models.Model):\n", " class ComponentType(models.TextChoices):\n", @@ -210,18 +166,225 @@ " TRIGGER = \"TRIGGER\", \"Trigger Component\"\n", " CONDITIONAL = \"CONDITIONAL\", \"Conditional Component\"\n", " CODE = \"CODE\", \"Code Component\"\n", + " STATE = \"STATE\", \"State Component\"\n", "\n", " component_type = models.CharField(\n", " max_length=20,\n", " choices=ComponentType.choices,\n", " default=ComponentType.TELEGRAM,\n", - " help_text=\"Type of the component\"\n", + " help_text=\"Type of the component\",\n", " )\n", - " timestamp = models.DateTimeField(auto_now_add=True)\n", + "\n", + " def save(self, *args: list, **kwargs: dict) -> None:\n", + " if self.pk is None:\n", + " self.component_content_type = ContentType.objects.get(\n", + " model=self.__class__.__name__.lower(),\n", + " )\n", + " super().save(*args, **kwargs)\n", + "\n", + " component_content_type = models.ForeignKey(\n", + " ContentType,\n", + " on_delete=models.CASCADE,\n", + " null=True,\n", + " blank=True,\n", + " )\n", + " component_name = models.CharField(\n", + " max_length=255,\n", + " null=True,\n", + " ) # in order to not interfere with some component 'name' field, I added redundant 'component'\n", + "\n", + " bot = models.ForeignKey(\"bot.Bot\", on_delete=models.CASCADE)\n", + "\n", + " previous_component = models.ForeignKey(\n", + " \"Component\",\n", + " on_delete=models.SET_NULL,\n", + " null=True,\n", + " blank=True,\n", + " related_name=\"next_component\",\n", + " )\n", + "\n", + " position_x = models.FloatField(null=False, blank=False)\n", + " position_y = models.FloatField(null=False, blank=False)\n", + "\n", + " def __str__(self) -> str:\n", + " return self.component_name or \"Empty Component\"\n", "\n", " class Meta:\n", " pass\n", "\n", + " @property\n", + " def code_function_name(self) -> str: # -> name of the function in generated code\n", + " return f\"{self.__class__.__name__.lower()}_{self.pk}\"\n", + "\n", + " def _get_file_params(self, underlying_object) -> str:\n", + " file_params = \"\"\n", + " for field in underlying_object._meta.get_fields():\n", + " if isinstance(field, models.FileField):\n", + " file_instance = getattr(underlying_object, field.name)\n", + " if file_instance and hasattr(file_instance, \"url\"):\n", + " full_url = f\"{settings.SITE_URL}{file_instance.url}\"\n", + " file_params = f\"{field.name}='{full_url}'\"\n", + " setattr(underlying_object, field.name, None)\n", + " return file_params\n", + "\n", + " def _get_method_name(self, class_name: str) -> str:\n", + " method = \"\"\n", + " for c in class_name:\n", + " if c.isupper():\n", + " method += \"_\"\n", + " method += c.lower()\n", + " return method.lstrip(\"_\")\n", + "\n", + " def _generate_keyboard_code(self, keyboard) -> list[str]:\n", + " if not isinstance(keyboard, InlineKeyboardMarkup):\n", + " return []\n", + "\n", + " code = [\" builder = InlineKeyboardBuilder()\"]\n", + " for k in keyboard.inline_keyboard.all():\n", + " code.append(\n", + " f\" builder.button(text='{k.text}', callback_data='{k.callback_data}')\",\n", + " )\n", + " code.append(\" keyboard = builder.as_markup()\")\n", + " return code\n", + "\n", + " def _format_code_component(self, underlying_object) -> list[str]:\n", + " try:\n", + " import black\n", + "\n", + " formatted_code = black.format_str(underlying_object.code, mode=black.Mode())\n", + " return [f\" {formatted_code}\"]\n", + " except Exception as e:\n", + " return [\n", + " f\" # Original code failed black formatting: {str(e)}\",\n", + " f\" # {underlying_object.code}\",\n", + " \" pass\",\n", + " ]\n", + "\n", + " def _get_component_params(\n", + " self,\n", + " underlying_object,\n", + " keyboard,\n", + " file_params: str,\n", + " ) -> str:\n", + " excluded_fields = {\n", + " \"id\",\n", + " \"component_ptr\",\n", + " \"component_ptr_id\",\n", + " \"timestamp\",\n", + " \"object_id\",\n", + " \"component_type\",\n", + " \"content_type\",\n", + " \"component_content_type\",\n", + " \"bot\",\n", + " \"component_name\",\n", + " \"previous_component\",\n", + " \"position_x\",\n", + " \"position_y\",\n", + " }\n", + "\n", + " component_data = model_to_dict(underlying_object, exclude=excluded_fields)\n", + " param_strings = []\n", + "\n", + " for k, v in component_data.items():\n", + " if v:\n", + " if isinstance(v, str):\n", + " param_strings.append(\n", + " f\"{k}=input_data{v}\" if v.startswith(\".\") else f\"{k}='{v}'\",\n", + " )\n", + " else:\n", + " param_strings.append(f\"{k}={v}\")\n", + "\n", + " if keyboard:\n", + " param_strings.append(\"reply_markup=keyboard\")\n", + " if file_params:\n", + " param_strings.append(file_params)\n", + "\n", + " return \", \".join(param_strings)\n", + "\n", + " def generate_code(self) -> str:\n", + " if self.component_type != Component.ComponentType.TELEGRAM:\n", + " raise NotImplementedError\n", + "\n", + " underlying_object = self.component_content_type.model_class().objects.get(\n", + " pk=self.pk,\n", + " )\n", + " file_params = self._get_file_params(underlying_object)\n", + " method = self._get_method_name(underlying_object.__class__.__name__)\n", + "\n", + " code = [\n", + " f\"async def {underlying_object.code_function_name}(input_data: Message, **kwargs):\",\n", + " ]\n", + "\n", + " # Handle code component\n", + " if underlying_object.__class__.__name__ == \"CodeComponent\":\n", + " code.extend(self._format_code_component(underlying_object))\n", + " return \"\\\\n\".join(code)\n", + "\n", + " keyboard = None\n", + " # Check if markup exists before accessing it\n", + " if hasattr(underlying_object, \"markup\") and underlying_object.markup:\n", + " markup = underlying_object.markup\n", + " match markup.markup_type:\n", + " case markup.MarkupType.ReplyKeyboard:\n", + " keyword_class = \"ReplyKeyboardMarkup\"\n", + " button_class = \"KeyboardButton\"\n", + " case markup.MarkupType.InlineKeyboard:\n", + " keyword_class = \"InlineKeyboardMarkup\"\n", + " button_class = \"InlineKeyboardButton\"\n", + " case _:\n", + " raise NotImplementedError(f\"Unknown markup {markup.markup_type}\")\n", + " keyboard_buttons = \"[\"\n", + " for row in markup.buttons:\n", + " keyboard_buttons += \"[\\\\n\"\n", + "\n", + " for cell in row:\n", + " args = {\"text\": cell}\n", + " if markup.markup_type == markup.MarkupType.InlineKeyboard:\n", + " args[\"callback_data\"] = markup.get_callback_data(cell)\n", + "\n", + " keyboard_buttons += f\"{button_class}(\\\\n\"\n", + " for k, v in args.items():\n", + " keyboard_buttons += f'{k} = \"{v}\"\\\\n'\n", + " keyboard_buttons += f\")\"\n", + "\n", + " keyboard_buttons += \"]\"\n", + " keyboard_buttons += \"]\"\n", + " keyboard = f\"{keyword_class}(resize_keyboard=True, one_time_keyboard=False, keyboard = {keyboard_buttons})\"\n", + "\n", + " # Generate parameters and method call\n", + " params_str = self._get_component_params(\n", + " underlying_object,\n", + " keyboard,\n", + " file_params,\n", + " )\n", + " code.append(f\" await bot.{method}({params_str})\")\n", + "\n", + " # Handle next components\n", + " for next_component in underlying_object.next_component.all():\n", + " next_component = (\n", + " next_component.component_content_type.model_class().objects.get(\n", + " pk=next_component.pk,\n", + " )\n", + " )\n", + " code.append(\n", + " f\" await {next_component.code_function_name}(input_data, **kwargs)\",\n", + " )\n", + "\n", + " return \"\\\\n\".join(code)\n", + "\n", + " def get_all_next_components(self) -> List[\"Component\"]:\n", + " ans = {}\n", + " stack = [self]\n", + " while stack:\n", + " current = stack.pop()\n", + " if current.id not in ans:\n", + " ans[current.id] = current\n", + " for next_component in current.next_component.all():\n", + " if next_component.id not in ans:\n", + " stack.append(next_component)\n", + " return list(ans.values())\n", + "\n", + "\n", "\"\"\")\n", " not_supported = []\n", "\n", @@ -234,6 +397,7 @@ " file.write(f\"class {name[0].upper()+name[1:]}(Component):\\n\")\n", " file.write(f\" \\\"\\\"\\\"{text_cleaner(comment)}\\\"\\\"\\\"\\n\\n\")\n", " required_fields = []\n", + " supported_reply_markup = False\n", "\n", " # print(f\"class {name[0].upper()+name[1:]}(TelegramComponent):\")\n", " for item in body:\n", @@ -270,13 +434,9 @@ " elif type_field == 'InputFile or String':\n", " django_field = f\" = models.FileField(upload_to=\\\"{item[0]}/\\\", {django_param})\"\n", " elif type_field == 'InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or ForceReply':\n", - " keyboard_field = f\" content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE, limit_choices_to=Q(model='inlinekeyboardmarkup') | Q(model='replykeyboardmarkup') | Q(model='replykeyboardremove') | Q(model='forcereply'), {django_param})\"\n", - " keyboard_field += f\"\\n object_id = models.PositiveIntegerField(null=True, blank=True)\"\n", - " keyboard_field += f\"\\n related_to_main = GenericForeignKey(\\\"content_type\\\", \\\"object_id\\\")\"\n", + " supported_reply_markup = True\n", " elif type_field == 'InlineKeyboardMarkup':\n", - " keyboard_field = f\" content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE, limit_choices_to=Q(model='inlinekeyboardmarkup'), {django_param})\"\n", - " keyboard_field += f\"\\n object_id = models.PositiveIntegerField(null=True, blank=True)\"\n", - " keyboard_field += f\"\\n related_to_main = GenericForeignKey(\\\"content_type\\\", \\\"object_id\\\")\"\n", + " supported_reply_markup = True\n", " else:\n", " if type_field not in not_supported:\n", " not_supported.append(type_field)\n", @@ -290,25 +450,19 @@ " file.write(f\" def required_fields(self) -> list:\\n\")\n", " file.write(f\" return {required_fields}\\n\")\n", "\n", + " file.write(f\" @property\\n\")\n", + " file.write(f\" def reply_markup_supported(self) -> bool:\\n\")\n", + " file.write(f\" return {supported_reply_markup}\\n\")\n", + "\n", " file.write(\"\\n\\n\")\n", "file.close()\n", "print(f\"not supported: {len(not_supported)}\")\n", "print(not_supported)" - ], - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "not supported: 26\n", - "['Array of MessageEntity', 'LinkPreviewOptions', 'ReplyParameters', 'Array of InputPaidMedia', 'Array of InputMediaAudio, InputMediaDocument, InputMediaPhoto and InputMediaVideo', 'Array of InputPollOption', 'Array of ReactionType', 'ChatPermissions', 'InputFile', 'Array of BotCommand', 'BotCommandScope', 'MenuButton', 'ChatAdministratorRights', 'InputMedia', 'InputProfilePhoto', 'AcceptedGiftTypes', 'InputStoryContent', 'Array of StoryArea', 'Array of InputSticker', 'InputSticker', 'MaskPosition', 'Array of InlineQueryResult', 'InlineQueryResultsButton', 'InlineQueryResult', 'Array of LabeledPrice', 'Array of ShippingOption']\n" - ] - } - ], - "execution_count": 117 + ] }, { "cell_type": "code", + "execution_count": 47, "id": "86d8935e4565554a", "metadata": { "ExecuteTime": { @@ -316,6 +470,7 @@ "start_time": "2025-05-02T18:21:50.083596Z" } }, + "outputs": [], "source": [ "with open('../component/telegram/serializers.py', 'w') as file:\n", " file.write(\"\"\"from rest_framework import serializers\n", @@ -335,15 +490,15 @@ " file.write(f\" class Meta:\\n\")\n", " file.write(f\" model = {name[0].upper()+name[1:]}\\n\")\n", " # file.write(f\" depth = 1\\n\")\n", - " file.write(f\" exclude = [\\\"component_type\\\", \\\"bot\\\"]\")\n", + " file.write(f\" exclude = [\\\"bot\\\"]\\n\")\n", + " file.write(f\" read_only_fields = [\\\"component_type\\\"]\")\n", " file.write(\"\\n\\n\")\n", "file.close()" - ], - "outputs": [], - "execution_count": 118 + ] }, { "cell_type": "code", + "execution_count": 26, "id": "1e39353c535e21ba", "metadata": { "ExecuteTime": { @@ -351,6 +506,7 @@ "start_time": "2025-05-02T18:21:50.129614Z" } }, + "outputs": [], "source": [ "with open('../component/telegram/views.py', 'w') as file:\n", " file.write(\"\"\"from django.db.models import QuerySet\n", @@ -383,12 +539,11 @@ " file.write(f\" queryset = {correct_name}.objects.all()\\n\")\n", " file.write(\"\\n\\n\")\n", "file.close()" - ], - "outputs": [], - "execution_count": 119 + ] }, { "cell_type": "code", + "execution_count": 28, "id": "60dc33d27c71666", "metadata": { "ExecuteTime": { @@ -396,6 +551,7 @@ "start_time": "2025-05-02T18:21:50.176544Z" } }, + "outputs": [], "source": [ "with open('../component/telegram/urls.py', 'w') as file:\n", " file.write(\"\"\"from django.urls import include, path\n", @@ -428,12 +584,11 @@ "]\n", "\"\"\")\n", "file.close()" - ], - "outputs": [], - "execution_count": 120 + ] }, { "cell_type": "code", + "execution_count": 48, "id": "ef2d5e8929964fed", "metadata": { "ExecuteTime": { @@ -441,23 +596,22 @@ "start_time": "2025-05-02T18:21:57.484783Z" } }, - "source": [ - "!python -m black ../component/*" - ], "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "\u001B[1mAll done! ✨ 🍰 ✨\u001B[0m\r\n", - "\u001B[34m15 files \u001B[0mleft unchanged.\r\n" + "/home/ali/.local/bin/Cursor-0.48.8-x86_64.AppImage: No module named black\n" ] } ], - "execution_count": 124 + "source": [ + "!python -m black ../component/*" + ] }, { "cell_type": "code", + "execution_count": 50, "id": "3929d49e5238309c", "metadata": { "ExecuteTime": { @@ -465,33 +619,29 @@ "start_time": "2025-05-02T18:21:58.818894Z" } }, - "source": [ - "!pre-commit run --all-files" - ], "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "isort....................................................................\u001B[42mPassed\u001B[m\r\n", - "black....................................................................\u001B[42mPassed\u001B[m\r\n", - "Add trailing commas......................................................\u001B[42mPassed\u001B[m\r\n", - "trim trailing whitespace.................................................\u001B[42mPassed\u001B[m\r\n", - "mypy.....................................................................\u001B[41mFailed\u001B[m\r\n", - "\u001B[2m- hook id: mypy\u001B[m\r\n", - "\u001B[2m- exit code: 1\u001B[m\r\n", - "\r\n", - "nocodi/middleware.py:11: \u001B[1m\u001B[31merror:\u001B[m Need type annotation for \u001B[m\u001B[1m\"cache\"\u001B[m (hint: \u001B[m\u001B[1m\"cache: dict[, ] = ...\"\u001B[m) \u001B[m\u001B[33m[var-annotated]\u001B[m\r\n", - "bot/views.py:3: \u001B[1m\u001B[31merror:\u001B[m Library stubs not installed for \u001B[m\u001B[1m\"requests\"\u001B[m \u001B[m\u001B[33m[import-untyped]\u001B[m\r\n", - "bot/views.py:3: \u001B[34mnote:\u001B[m Hint: \u001B[m\u001B[1m\"python3 -m pip install types-requests\"\u001B[m\u001B[m\r\n", - "bot/views.py:3: \u001B[34mnote:\u001B[m (or run \u001B[m\u001B[1m\"mypy --install-types\"\u001B[m to install all missing stub packages)\u001B[m\r\n", - "bot/views.py:3: \u001B[34mnote:\u001B[m See \u001B[4mhttps://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports\u001B[m\u001B[m\r\n", - "\u001B[1m\u001B[31mFound 2 errors in 2 files (checked 45 source files)\u001B[m\r\n", - "\r\n" + "isort....................................................................\u001b[42mPassed\u001b[m\n", + "black....................................................................\u001b[42mPassed\u001b[m\n", + "Add trailing commas......................................................\u001b[42mPassed\u001b[m\n", + "trim trailing whitespace.................................................\u001b[42mPassed\u001b[m\n" ] } ], - "execution_count": 125 + "source": [ + "!pre-commit run --all-files" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ebe474ba", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": {
Parameter<\\/th>\\s+Type<\\/th>\\s+Required<\\/th>\\s+Description<\\/th>\\s+<\\/tr>\\s+<\\/thead>\\s+([\\s\\S]*?)<\\/tbody>'" - ], - "outputs": [], - "execution_count": 112 + ] }, { "cell_type": "code", + "execution_count": 8, "id": "29c8fb1dff77f41c", "metadata": { "ExecuteTime": { @@ -75,14 +76,14 @@ "start_time": "2025-05-02T18:21:49.810743Z" } }, + "outputs": [], "source": [ "all_methods = re.findall(pattern, res.text)" - ], - "outputs": [], - "execution_count": 113 + ] }, { "cell_type": "code", + "execution_count": 9, "id": "85f8a5da061ed4a1", "metadata": { "ExecuteTime": { @@ -90,14 +91,14 @@ "start_time": "2025-05-02T18:21:49.860357Z" } }, + "outputs": [], "source": [ "table_body_pattern = r'
(.*?)(.*?)(.*?)(.*?)