allow sending in topic forums

This commit is contained in:
Devesh Pal 2022-12-11 15:49:01 +05:30
parent 83f13da420
commit 10c46be72f
3 changed files with 29 additions and 5 deletions

View File

@ -634,6 +634,7 @@ class MessageMethods:
file: 'typing.Union[hints.FileLike, typing.Sequence[hints.FileLike]]' = None, file: 'typing.Union[hints.FileLike, typing.Sequence[hints.FileLike]]' = None,
thumb: 'hints.FileLike' = None, thumb: 'hints.FileLike' = None,
force_document: bool = False, force_document: bool = False,
topic_id: int = None,
clear_draft: bool = False, clear_draft: bool = False,
buttons: typing.Optional['hints.MarkupLike'] = None, buttons: typing.Optional['hints.MarkupLike'] = None,
silent: bool = None, silent: bool = None,
@ -675,6 +676,9 @@ class MessageMethods:
Whether to reply to a message or not. If an integer is provided, Whether to reply to a message or not. If an integer is provided,
it should be the ID of the message that it should reply to. it should be the ID of the message that it should reply to.
topic_id (`int`, optional):
Whether to send message in topic forum, It should be ID of topic forum.
attributes (`list`, optional): attributes (`list`, optional):
Optional attributes that override the inferred ones, like Optional attributes that override the inferred ones, like
:tl:`DocumentAttributeFilename` and so on. :tl:`DocumentAttributeFilename` and so on.
@ -821,7 +825,8 @@ class MessageMethods:
buttons=buttons, clear_draft=clear_draft, silent=silent, buttons=buttons, clear_draft=clear_draft, silent=silent,
schedule=schedule, supports_streaming=supports_streaming, schedule=schedule, supports_streaming=supports_streaming,
formatting_entities=formatting_entities, formatting_entities=formatting_entities,
comment_to=comment_to, background=background comment_to=comment_to, background=background,
topic_id=topic_id
) )
entity = await self.get_input_entity(entity) entity = await self.get_input_entity(entity)
@ -846,6 +851,7 @@ class MessageMethods:
silent=silent, silent=silent,
background=background, background=background,
reply_to=reply_to, reply_to=reply_to,
topic_id=topic_id,
buttons=markup, buttons=markup,
formatting_entities=message.entities, formatting_entities=message.entities,
parse_mode=None, # explicitly disable parse_mode to force using even empty formatting_entities parse_mode=None, # explicitly disable parse_mode to force using even empty formatting_entities
@ -856,6 +862,7 @@ class MessageMethods:
peer=entity, peer=entity,
message=message.message or '', message=message.message or '',
silent=silent, silent=silent,
top_msg_id=topic_id,
background=background, background=background,
reply_to_msg_id=utils.get_message_id(reply_to), reply_to_msg_id=utils.get_message_id(reply_to),
reply_markup=markup, reply_markup=markup,
@ -878,6 +885,7 @@ class MessageMethods:
peer=entity, peer=entity,
message=message, message=message,
entities=formatting_entities, entities=formatting_entities,
top_msg_id=topic_id,
no_webpage=not link_preview, no_webpage=not link_preview,
reply_to_msg_id=utils.get_message_id(reply_to), reply_to_msg_id=utils.get_message_id(reply_to),
clear_draft=clear_draft, clear_draft=clear_draft,
@ -912,6 +920,7 @@ class MessageMethods:
messages: 'typing.Union[hints.MessageIDLike, typing.Sequence[hints.MessageIDLike]]', messages: 'typing.Union[hints.MessageIDLike, typing.Sequence[hints.MessageIDLike]]',
from_peer: 'hints.EntityLike' = None, from_peer: 'hints.EntityLike' = None,
*, *,
topic_id: int = None,
background: bool = None, background: bool = None,
with_my_score: bool = None, with_my_score: bool = None,
silent: bool = None, silent: bool = None,
@ -940,6 +949,9 @@ class MessageMethods:
order for the forward to work. This parameter indicates order for the forward to work. This parameter indicates
the entity from which the messages should be forwarded. the entity from which the messages should be forwarded.
topic_id (`int`, optional):
Whether to forward message in topic forum, It should be ID of topic forum.
silent (`bool`, optional): silent (`bool`, optional):
Whether the message should notify people with sound or not. Whether the message should notify people with sound or not.
Defaults to `False` (send with a notification sound unless Defaults to `False` (send with a notification sound unless
@ -1025,6 +1037,7 @@ class MessageMethods:
from_peer=chat, from_peer=chat,
id=chunk, id=chunk,
to_peer=entity, to_peer=entity,
top_msg_id=topic_id,
silent=silent, silent=silent,
background=background, background=background,
with_my_score=with_my_score, with_my_score=with_my_score,

View File

@ -101,6 +101,7 @@ class UploadMethods:
force_document: bool = False, force_document: bool = False,
file_size: int = None, file_size: int = None,
clear_draft: bool = False, clear_draft: bool = False,
topic_id: int = None,
progress_callback: 'hints.ProgressCallback' = None, progress_callback: 'hints.ProgressCallback' = None,
reply_to: 'hints.MessageIDLike' = None, reply_to: 'hints.MessageIDLike' = None,
attributes: 'typing.Sequence[types.TypeDocumentAttribute]' = None, attributes: 'typing.Sequence[types.TypeDocumentAttribute]' = None,
@ -201,6 +202,9 @@ class UploadMethods:
reply_to (`int` | `Message <telethon.tl.custom.message.Message>`): reply_to (`int` | `Message <telethon.tl.custom.message.Message>`):
Same as `reply_to` from `send_message`. Same as `reply_to` from `send_message`.
topic_id (`int`, optional):
Whether to send message in topic forum, It should be ID of topic forum.
attributes (`list`, optional): attributes (`list`, optional):
Optional attributes that override the inferred ones, like Optional attributes that override the inferred ones, like
:tl:`DocumentAttributeFilename` and so on. :tl:`DocumentAttributeFilename` and so on.
@ -365,6 +369,7 @@ class UploadMethods:
parse_mode=parse_mode, silent=silent, schedule=schedule, parse_mode=parse_mode, silent=silent, schedule=schedule,
supports_streaming=supports_streaming, clear_draft=clear_draft, supports_streaming=supports_streaming, clear_draft=clear_draft,
force_document=force_document, background=background, force_document=force_document, background=background,
topic_id=topic_id
) )
file = file[10:] file = file[10:]
captions = captions[10:] captions = captions[10:]
@ -378,6 +383,7 @@ class UploadMethods:
video_note=video_note, buttons=buttons, silent=silent, video_note=video_note, buttons=buttons, silent=silent,
supports_streaming=supports_streaming, schedule=schedule, supports_streaming=supports_streaming, schedule=schedule,
clear_draft=clear_draft, background=background, clear_draft=clear_draft, background=background,
topic_id=topic_id,
**kwargs **kwargs
)) ))
@ -407,7 +413,7 @@ class UploadMethods:
entity, media, reply_to_msg_id=reply_to, message=caption, entity, media, reply_to_msg_id=reply_to, message=caption,
entities=msg_entities, reply_markup=markup, silent=silent, entities=msg_entities, reply_markup=markup, silent=silent,
schedule_date=schedule, clear_draft=clear_draft, schedule_date=schedule, clear_draft=clear_draft,
background=background background=background, top_msg_id=topic_id
) )
return self._get_response_message(request, await self(request), entity) return self._get_response_message(request, await self(request), entity)
@ -415,7 +421,8 @@ class UploadMethods:
progress_callback=None, reply_to=None, progress_callback=None, reply_to=None,
parse_mode=(), silent=None, schedule=None, parse_mode=(), silent=None, schedule=None,
supports_streaming=None, clear_draft=None, supports_streaming=None, clear_draft=None,
force_document=False, background=None, ttl=None): force_document=False, background=None, ttl=None,
topic_id=None):
"""Specialized version of .send_file for albums""" """Specialized version of .send_file for albums"""
# We don't care if the user wants to avoid cache, we will use it # We don't care if the user wants to avoid cache, we will use it
# anyway. Why? The cached version will be exactly the same thing # anyway. Why? The cached version will be exactly the same thing
@ -475,7 +482,7 @@ class UploadMethods:
request = functions.messages.SendMultiMediaRequest( request = functions.messages.SendMultiMediaRequest(
entity, reply_to_msg_id=reply_to, multi_media=media, entity, reply_to_msg_id=reply_to, multi_media=media,
silent=silent, schedule_date=schedule, clear_draft=clear_draft, silent=silent, schedule_date=schedule, clear_draft=clear_draft,
background=background background=background, top_msg_id=topic_id
) )
result = await self(request) result = await self(request)

View File

@ -104,7 +104,7 @@ class InlineResult:
async def click(self, entity=None, reply_to=None, comment_to=None, async def click(self, entity=None, reply_to=None, comment_to=None,
silent=False, clear_draft=False, hide_via=False, silent=False, clear_draft=False, hide_via=False,
background=None): background=None, topic_id=None):
""" """
Clicks this result and sends the associated `message`. Clicks this result and sends the associated `message`.
@ -120,6 +120,9 @@ class InlineResult:
broadcast channel instead (effectively leaving a "comment to" broadcast channel instead (effectively leaving a "comment to"
the specified message). the specified message).
topic_id (`int`, optional):
Whether to send message in topic forum, It should be ID of topic forum.
silent (`bool`, optional): silent (`bool`, optional):
Whether the message should notify people with sound or not. Whether the message should notify people with sound or not.
Defaults to `False` (send with a notification sound unless Defaults to `False` (send with a notification sound unless
@ -154,6 +157,7 @@ class InlineResult:
peer=entity, peer=entity,
query_id=self._query_id, query_id=self._query_id,
id=self.result.id, id=self.result.id,
top_msg_id=topic_id,
silent=silent, silent=silent,
background=background, background=background,
clear_draft=clear_draft, clear_draft=clear_draft,