Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bot API Huge Update - 7.0, introducing reactions, replies and some other changes #2106

Merged
merged 47 commits into from
Jan 3, 2024

Conversation

coder2020official
Copy link
Collaborator

@coder2020official coder2020official commented Dec 29, 2023

December 29, 2023
Bot API 7.0

Reactions

  • Added the classes ReactionTypeEmoji and ReactionTypeCustomEmoji representing different types of reaction.
  • Added updates about a reaction change on a message with non-anonymous reactions, represented by the class MessageReactionUpdated and the field message_reaction in the class Update. The bot must explicitly allow the update to receive it.
  • Added updates about reaction changes on a message with anonymous reactions, represented by the class MessageReactionCountUpdated and the field message_reaction_count in the class Update. The bot must explicitly allow the update to receive it.
  • Added the method setMessageReaction that allows bots to react to messages.
  • Added the field available_reactions to the class Chat.

Replies 2.0

Link Preview Customization

  • Allowed to explicitly specify the URL that will be used for link preview generation in outgoing text messages.
  • Allowed to position link previews above the message text.
  • Allowed to choose media size in link previews.
  • Added the class LinkPreviewOptions and replaced the parameter disable_web_page_preview with link_preview_options in the methods sendMessage and editMessageText.
  • Replaced the field disable_web_page_preview with link_preview_options in the class InputTextMessageContent.
  • Added the field link_preview_options to the class Message with information about the link preview options used to send the message.

Block Quotation

  • Added support for “blockquote” entities in received messages.
  • Added support for “blockquote” entity parsing in “MarkdownV2” and “HTML” parse modes.
  • Allowed to explicitly specify “blockquote” entities in formatted texts.

Multiple Message Actions

  • Added the method deleteMessages to allow the deletion of multiple messages in a single request.
  • Added the method forwardMessages for forwarding of multiple messages in a single request.
  • Added the method copyMessages for copying of multiple messages in a single request.

Request for multiple users

  • Renamed the class KeyboardButtonRequestUser to KeyboardButtonRequestUsers and added the field max_quantity to it.
  • Renamed the field request_user in the class KeyboardButton to request_users. The old name will still work for backward compatibility.
  • Added the class UsersShared.
  • Replaced the field user_shared in the class Message with the field users_shared.

Chat Boost

Giveaway

  • Added the class Giveaway and the field giveaway to the class Message for messages about scheduled giveaways.
  • Added the class GiveawayCreated and the field giveaway_created to the class Message for service messages about the creation of a scheduled giveaway.
  • Added the class GiveawayWinners and the field giveaway_winners to the class Message for messages about the completion of a giveaway with public winners.
  • Added the class GiveawayCompleted and the field giveaway_completed to the class Message for service messages about the completion of a giveaway without public winners.

Other Changes

  • Added support for the fields emoji_status_custom_emoji_id and emoji_status_expiration_date in the class Chat for non-private chats.
  • Added the fields accent_color_id, background_custom_emoji_id, profile_accent_color_id, and profile_background_custom_emoji_id to the class Chat.
  • Added the field has_visible_history to the class Chat.
  • Added the class MessageOrigin and replaced the fields forward_from, forward_from_chat, forward_from_message_id, forward_signature, forward_sender_name, and forward_date with the field forward_origin of type MessageOrigin in the class Message.
  • Improved documentation for the field message of the class callbackQuery and the field pinned_message of the class Message by adding the classes MaybeInaccessibleMessage and InaccessibleMessage.

@coder2020official coder2020official changed the title Start of bot API Update - 7.0 Bot API Huge Update - 7.0, introducing reactions, replies and some other changes Dec 29, 2023
…ctions, represented by the class MessageReactionCountUpdated and the field message_reaction_count in the class Update. The bot must explicitly allow the update to receive it.
…e ExternalReplyInfo to the class Message, containing information about a message that is replied to by the current message, but can be from another chat or forum topic.
telebot/types.py Outdated
@@ -1208,6 +1214,13 @@ def de_json(cls, json_string):
if 'story' in obj:
opts['story'] = Story.de_json(obj['story'])
content_type = 'story'
if 'external_reply' in obj:
opts['external_reply'] = ExternalReplyInfo.de_json(obj['external_reply'])
content_type = 'text' # @Badiboy not sure about content_types in here, please check
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Badiboy check this line and the lines below

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can check it in previous commit

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I get the meaning of the field "external_reply" - it contains ADDITIONAL INFORMATION to the main content. So it should not process content_type at all: content_type will be set by the main data fields like "text"/"audio" etc.

The same for "quote".

I'll removed the content_type assignment in commit.

content_type = 'user_shared'
if 'users_shared' in obj:
opts['users_shared'] = UserShared.de_json(obj['users_shared'])
content_type = 'users_shared' # COMPATIBILITY BROKEN!
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Badiboy compatibility will be broken here. They renamed the property, and this makes me rename the content_type too. Any ideas?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any better way... Let's hope not much people used this content type...

@coder2020official
Copy link
Collaborator Author

Bot API Update is just a bunch of deprecation warnings. Always.

coder2020official and others added 3 commits December 31, 2023 21:22
Fix "new_" usage. No valuable changes.
reply_to_message_id and allow_sending_without_reply deprecation extended with more precise values processing
@Badiboy
Copy link
Collaborator

Badiboy commented Jan 2, 2024

@coder2020official
For commit 79cc127 please update Async in the same way if you confirm these changes.

disable_web_page_preview deprecation extended with more precise values processing
@Badiboy
Copy link
Collaborator

Badiboy commented Jan 2, 2024

@coder2020official For commit 56fbcaf please update Async in the same way if you confirm these changes.

def set_message_reaction(token, chat_id, message_id, reaction=None, is_big=None):
method_url = r'setMessageReaction'
payload = {'chat_id': chat_id, 'message_id': message_id}
if reaction:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proposal.
Check if reaction is not list (single reaction) and convert it to list.
or
Check if reaction is not list and raise error with explanation.

Reasonable.
I suppose lot of mistakes by users because of parameter naming: "reaction".

@@ -586,6 +592,8 @@ async def process_new_updates(self, updates: List[types.Update]):
new_my_chat_members = None
new_chat_members = None
chat_join_request = None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Propose rename all three items to "new_".

if new_message_reaction_count_handlers:
await self.process_new_message_reaction_count(new_message_reaction_count_handlers)
if chat_boost_handlers:
await self.process_new_chat_boost(chat_boost_handlers)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed_chat_boost_handlers !

@@ -5490,6 +6133,33 @@ async def answer_callback_query(
:rtype: :obj:`bool`
"""
return await asyncio_helper.answer_callback_query(self.token, callback_query_id, text, show_alert, url, cache_time)

# getUserChatBoosts
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment

@@ -776,6 +833,9 @@ class Message(JsonDeserializable):
:param forward_date: Optional. For forwarded messages, date the original message was sent in Unix time
:type forward_date: :obj:`int`

:forward_origin: Optional. For forwarded messages, information about the original message;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment for me: set deprecation for forward_xxx fields (in the next update: this one is too large).

Added the class MessageOrigin and replaced the fields forward_from, forward_from_chat, forward_from_message_id, forward_signature, forward_sender_name, and forward_date with the field forward_origin of type MessageOrigin in the class Message.

@@ -1283,9 +1390,20 @@ def __init__(self, message_id, from_user, date, chat, content_type, options, jso
self.general_forum_topic_hidden: Optional[GeneralForumTopicHidden] = None
self.general_forum_topic_unhidden: Optional[GeneralForumTopicUnhidden] = None
self.write_access_allowed: Optional[WriteAccessAllowed] = None
self.user_shared: Optional[UserShared] = None
self.users_shared: Optional[UserShared] = None
self.user_shared: Optional[UserShared] = self.users_shared
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment for me: process with deprecation

return data

KeyboardButtonRequestUser = KeyboardButtonRequestUsers
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Process with deprecation.

@@ -7515,7 +7647,7 @@ def __init__(self, from_request: Optional[bool]=None, web_app_name: Optional[str
class UserShared(JsonDeserializable):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment for me: change class from UserShared => UsersShared + deprecation

:rtype: :class:`ExternalReplyInfo`
"""
@classmethod
def de_json(cls, json_string):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad autogenerated code not corresponding to common way. It's better to check autogeneration resutls.

return None
obj = cls.check_json(json_string)

return cls(is_disabled=obj.get('is_disabled'), url=obj.get('url'), prefer_small_media=obj.get('prefer_small_media'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad.

@Badiboy
Copy link
Collaborator

Badiboy commented Jan 3, 2024

@coder2020official I'm done. You did a huge work. Me too. :)

This update is suitable to merge and then we'll fix raised questions in separate SMALL updates )

@Badiboy Badiboy merged commit 8b0313a into eternnoir:master Jan 3, 2024
7 checks passed
@coder2020official
Copy link
Collaborator Author

Nice!
Shouldn't I fix some things for async or did you fix them manually?

@Badiboy
Copy link
Collaborator

Badiboy commented Jan 3, 2024

Nice! Shouldn't I fix some things for async or did you fix them manually?

I did critical fixes for Async also. The given comments are regarding "fine tuning" and are left for you: if you think it's usefull - you can apply the same in Async.

@Badiboy
Copy link
Collaborator

Badiboy commented Jan 3, 2024

@coder2020official What about new version?
4.15? 5.0?

@coder2020official
Copy link
Collaborator Author

4.2, 5 is a way big number

@coder2020official
Copy link
Collaborator Author

And about the fine tuning - are you talking about type hints?

@Badiboy
Copy link
Collaborator

Badiboy commented Jan 3, 2024

4.2, 5 is a way big number

4.2 is not possible, it already exists. :) 4.14 is not 4.1.4 )))
So either 4.15 or 5.0, no other ways )

@Badiboy
Copy link
Collaborator

Badiboy commented Jan 3, 2024

And about the fine tuning - are you talking about type hints?

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants