Skip to content

Commit c4b754f

Browse files
Some fixes for checklists
1 parent 8fccf91 commit c4b754f

10 files changed

Lines changed: 332 additions & 92 deletions

File tree

compiler/docs/compiler.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ def get_title_list(s: str) -> list:
246246
send_reaction
247247
edit_message_text
248248
edit_message_caption
249+
edit_message_checklist
249250
edit_message_media
250251
edit_message_reply_markup
251252
edit_inline_text
@@ -777,6 +778,7 @@ def get_title_list(s: str) -> list:
777778
""",
778779
input_content="""
779780
Input Content
781+
InputChecklist
780782
InputContactMessageContent
781783
InputCredentials
782784
InputCredentialsApplePay
@@ -887,6 +889,7 @@ def get_title_list(s: str) -> list:
887889
Message.edit_text
888890
Message.edit_caption
889891
Message.edit_media
892+
Message.edit_checklist
890893
Message.edit_reply_markup
891894
Message.reply
892895
Message.reply_text

compiler/errors/source/400_BAD_REQUEST.tsv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ TIMEZONE_INVALID The specified timezone does not exist.
549549
TITLE_INVALID The specified stickerpack title is invalid.
550550
TMP_PASSWORD_DISABLED The temporary password is disabled.
551551
TMP_PASSWORD_INVALID The temporary password is invalid.
552+
TODO_ITEM_DUPLICATE The provided ToDo task already exists.
552553
TOKEN_EMPTY The specified token is empty.
553554
TOKEN_INVALID The provided token is invalid.
554555
TOKEN_SECRET_INVALID The specified token secret is invalid.

pyrogram/methods/messages/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from .edit_inline_reply_markup import EditInlineReplyMarkup
3030
from .edit_inline_text import EditInlineText
3131
from .edit_message_caption import EditMessageCaption
32+
from .edit_message_checklist import EditMessageChecklist
3233
from .edit_message_media import EditMessageMedia
3334
from .edit_message_reply_markup import EditMessageReplyMarkup
3435
from .edit_message_text import EditMessageText
@@ -95,6 +96,7 @@ class Messages(
9596
AddToGifs,
9697
DeleteMessages,
9798
EditMessageCaption,
99+
EditMessageChecklist,
98100
EditMessageReplyMarkup,
99101
EditMessageMedia,
100102
EditMessageText,
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
3+
#
4+
# This file is part of Pyrogram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+
from typing import Optional, Union
20+
21+
import pyrogram
22+
from pyrogram import raw, types, utils
23+
24+
25+
class EditMessageChecklist:
26+
async def edit_message_checklist(
27+
self: "pyrogram.Client",
28+
chat_id: Union[int, str],
29+
message_id: int,
30+
checklist: "types.InputChecklist",
31+
business_connection_id: Optional[str] = None,
32+
reply_markup: Optional["types.InlineKeyboardMarkup"] = None,
33+
) -> "types.Message":
34+
"""Use this method to edit a checklist.
35+
36+
.. include:: /_includes/usable-by/users-bots.rst
37+
38+
Parameters:
39+
chat_id (``int`` | ``str``):
40+
Unique identifier (int) or username (str) of the target chat.
41+
For your personal cloud (Saved Messages) you can simply use "me" or "self".
42+
For a contact that exists in your Telegram address book you can use his phone number (str).
43+
44+
message_id (``int``):
45+
Message identifier in the chat specified in chat_id.
46+
47+
checklist (:obj:`~pyrogram.types.InputChecklist`):
48+
New checklist.
49+
50+
business_connection_id (``str``, *optional*):
51+
Unique identifier of the business connection on behalf of which the message will be sent.
52+
53+
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
54+
An InlineKeyboardMarkup object.
55+
56+
Returns:
57+
:obj:`~pyrogram.types.Message`: On success, the edited message is returned.
58+
59+
Example:
60+
.. code-block:: python
61+
62+
# Replace the current checklist with a new one
63+
await app.edit_message_checklist(
64+
chat_id=chat_id,
65+
message_id=message_id,
66+
checklist=types.InputChecklist(
67+
title="Checklist",
68+
tasks=[
69+
types.InputChecklistTask(id=1, text="Task 1"),
70+
types.InputChecklistTask(id=2, text="Task 2")
71+
]
72+
)
73+
)
74+
"""
75+
title, entities = (await utils.parse_text_entities(
76+
self, checklist.title, checklist.parse_mode, checklist.entities
77+
)).values()
78+
79+
r = await self.invoke(
80+
raw.functions.messages.EditMessage(
81+
peer=await self.resolve_peer(chat_id),
82+
id=message_id,
83+
media=raw.types.InputMediaTodo(
84+
todo=raw.types.TodoList(
85+
title=raw.types.TextWithEntities(
86+
text=title,
87+
entities=entities or []
88+
),
89+
list=[await task.write(self) for task in checklist.tasks],
90+
others_can_append=checklist.others_can_add_tasks,
91+
others_can_complete=checklist.others_can_mark_tasks_as_done
92+
)
93+
),
94+
reply_markup=await reply_markup.write(self) if reply_markup else None,
95+
entities=entities
96+
),
97+
business_connection_id=business_connection_id
98+
)
99+
100+
for i in r.updates:
101+
if isinstance(i, (raw.types.UpdateEditMessage, raw.types.UpdateEditChannelMessage)):
102+
return await types.Message._parse(
103+
self, i.message,
104+
{i.id: i for i in r.users},
105+
{i.id: i for i in r.chats}
106+
)

pyrogram/methods/messages/mark_checklist_tasks_as_done.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@
1919
from typing import List, Union
2020

2121
import pyrogram
22-
from pyrogram import raw, types
22+
from pyrogram import raw
2323

2424

2525
class MarkChecklistTasksAsDone:
2626
async def mark_checklist_tasks_as_done(
2727
self: "pyrogram.Client",
2828
chat_id: Union[int, str],
2929
message_id: int,
30-
tasks: List["types.InputChecklistTask"]
30+
*,
31+
marked_as_done_task_ids: List[int] = None,
32+
marked_as_not_done_task_ids: List[int] = None,
3133
) -> int:
32-
"""Add tasks to a checklist in a message.
34+
"""Add tasks of a checklist in a message as done or not done.
3335
3436
.. include:: /_includes/usable-by/users.rst
3537
@@ -42,31 +44,30 @@ async def mark_checklist_tasks_as_done(
4244
message_id (``int``):
4345
Identifier of the message containing the checklist.
4446
45-
tasks (List of :obj:`~pyrogram.types.InputChecklistTask`):
46-
List of tasks to add to the checklist.
47+
marked_as_done_task_ids (List of ``int``):
48+
Identifiers of tasks that were marked as done.
49+
50+
marked_as_not_done_task_ids (List of ``int``):
51+
Identifiers of tasks that were marked as not done.
4752
4853
Returns:
4954
``bool``: On success, True is returned.
5055
5156
Example:
5257
.. code-block:: python
5358
54-
await app.add_checklist_tasks(
59+
await app.mark_checklist_tasks_as_done(
5560
chat_id,
5661
message_id,
57-
tasks=[
58-
types.InputChecklistTask(
59-
id=2,
60-
text="Task 2"
61-
)
62-
]
62+
marked_as_done_task_ids=[1, 2, 3]
6363
)
6464
"""
6565
await self.invoke(
66-
raw.functions.messages.AppendTodoList(
66+
raw.functions.messages.ToggleTodoCompleted(
6767
peer=await self.resolve_peer(chat_id),
6868
msg_id=message_id,
69-
list=[await task.write(self) for task in tasks]
69+
completed=marked_as_done_task_ids or [],
70+
incompleted=marked_as_not_done_task_ids or [],
7071
)
7172
)
7273

pyrogram/methods/messages/send_checklist.py

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,47 +29,36 @@ class SendChecklist:
2929
async def send_checklist(
3030
self: "pyrogram.Client",
3131
chat_id: Union[int, str],
32-
title: str,
33-
tasks: List["types.InputChecklistTask"],
34-
parse_mode: Optional["enums.ParseMode"] = None,
35-
entities: Optional[List["types.MessageEntity"]] = None,
36-
others_can_add_tasks: Optional[bool] = None,
37-
others_can_mark_tasks_as_done: Optional[bool] = None,
32+
checklist: "types.InputChecklist",
3833
disable_notification: Optional[bool] = None,
3934
protect_content: Optional[bool] = None,
4035
message_thread_id: Optional[int] = None,
4136
effect_id: Optional[int] = None,
4237
reply_parameters: Optional["types.ReplyParameters"] = None,
4338
schedule_date: Optional[datetime] = None,
44-
paid_message_star_count: int = None
39+
business_connection_id: Optional[str] = None,
40+
paid_message_star_count: int = None,
41+
reply_markup: Optional[
42+
Union[
43+
"types.InlineKeyboardMarkup",
44+
"types.ReplyKeyboardMarkup",
45+
"types.ReplyKeyboardRemove",
46+
"types.ForceReply"
47+
]
48+
] = None,
4549
) -> "types.Message":
4650
"""Send a new checklist.
4751
48-
.. include:: /_includes/usable-by/users.rst
52+
.. include:: /_includes/usable-by/users-bots.rst
4953
5054
Parameters:
5155
chat_id (``int`` | ``str``):
5256
Unique identifier (int) or username (str) of the target chat.
5357
For your personal cloud (Saved Messages) you can simply use "me" or "self".
5458
For a contact that exists in your Telegram address book you can use his phone number (str).
5559
56-
title (``str``):
57-
Title of the checklist.
58-
59-
tasks (List of ``str``):
60-
List of tasks in the checklist, 1-30 tasks.
61-
62-
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
63-
The parse mode to use for the checklist.
64-
65-
entities (List of :obj:`~pyrogram.types.MessageEntity`, *optional*):
66-
List of special entities that appear in the checklist title.
67-
68-
others_can_add_tasks (``bool``, *optional*):
69-
True, if other users can add tasks to the list.
70-
71-
others_can_mark_tasks_as_done (``bool``, *optional*):
72-
True, if other users can mark tasks as done or not done.
60+
checklist (:obj:`~pyrogram.types.InputChecklist`):
61+
Checklist to send.
7362
7463
disable_notification (``bool``, *optional*):
7564
Sends the message silently.
@@ -92,9 +81,16 @@ async def send_checklist(
9281
schedule_date (:py:obj:`~datetime.datetime`, *optional*):
9382
Date when the message will be automatically sent.
9483
84+
business_connection_id (``str``, *optional*):
85+
Unique identifier of the business connection on behalf of which the message will be sent.
86+
9587
paid_message_star_count (``int``, *optional*):
9688
The number of Telegram Stars the user agreed to pay to send the messages.
9789
90+
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*):
91+
Additional interface options. An object for an inline keyboard, custom reply keyboard,
92+
instructions to remove reply keyboard or to force a reply from the user.
93+
9894
Returns:
9995
:obj:`~pyrogram.types.Message`: On success, the sent checklist message is returned.
10096
@@ -111,7 +107,7 @@ async def send_checklist(
111107
)
112108
"""
113109
title, entities = (await utils.parse_text_entities(
114-
self, title, parse_mode, entities
110+
self, checklist.title, checklist.parse_mode, checklist.entities
115111
)).values()
116112

117113
r = await self.invoke(
@@ -123,9 +119,9 @@ async def send_checklist(
123119
text=title,
124120
entities=entities or []
125121
),
126-
list=[await task.write(self) for task in tasks],
127-
others_can_append=others_can_add_tasks,
128-
others_can_complete=others_can_mark_tasks_as_done
122+
list=[await task.write(self) for task in checklist.tasks],
123+
others_can_append=checklist.others_can_add_tasks,
124+
others_can_complete=checklist.others_can_mark_tasks_as_done
129125
)
130126
),
131127
message="",
@@ -139,8 +135,10 @@ async def send_checklist(
139135
schedule_date=utils.datetime_to_timestamp(schedule_date),
140136
noforwards=protect_content,
141137
allow_paid_stars=paid_message_star_count,
138+
reply_markup=await reply_markup.write(self) if reply_markup else None,
142139
effect=effect_id
143-
)
140+
),
141+
business_connection_id=business_connection_id
144142
)
145143

146144
messages = await utils.parse_messages(client=self, messages=r)

pyrogram/types/input_content/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19+
from .input_checklist import InputChecklist
1920
from .input_contact_message_content import InputContactMessageContent
2021
from .input_credentials import InputCredentials
2122
from .input_credentials_apple_pay import InputCredentialsApplePay
@@ -52,6 +53,7 @@
5253
from .input_venue_message_content import InputVenueMessageContent
5354

5455
__all__ = [
56+
"InputChecklist",
5557
"InputContactMessageContent",
5658
"InputCredentials",
5759
"InputCredentialsApplePay",

0 commit comments

Comments
 (0)