telegrinder 1.0.0rc1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- telegrinder/__init__.py +258 -0
- telegrinder/__meta__.py +1 -0
- telegrinder/api/__init__.py +15 -0
- telegrinder/api/api.py +175 -0
- telegrinder/api/error.py +50 -0
- telegrinder/api/response.py +23 -0
- telegrinder/api/token.py +30 -0
- telegrinder/api/validators.py +30 -0
- telegrinder/bot/__init__.py +144 -0
- telegrinder/bot/bot.py +70 -0
- telegrinder/bot/cute_types/__init__.py +41 -0
- telegrinder/bot/cute_types/base.py +228 -0
- telegrinder/bot/cute_types/base.pyi +49 -0
- telegrinder/bot/cute_types/business_connection.py +9 -0
- telegrinder/bot/cute_types/business_messages_deleted.py +9 -0
- telegrinder/bot/cute_types/callback_query.py +248 -0
- telegrinder/bot/cute_types/chat_boost_removed.py +9 -0
- telegrinder/bot/cute_types/chat_boost_updated.py +9 -0
- telegrinder/bot/cute_types/chat_join_request.py +59 -0
- telegrinder/bot/cute_types/chat_member_updated.py +158 -0
- telegrinder/bot/cute_types/chosen_inline_result.py +11 -0
- telegrinder/bot/cute_types/inline_query.py +41 -0
- telegrinder/bot/cute_types/message.py +2809 -0
- telegrinder/bot/cute_types/message_reaction_count_updated.py +9 -0
- telegrinder/bot/cute_types/message_reaction_updated.py +9 -0
- telegrinder/bot/cute_types/paid_media_purchased.py +11 -0
- telegrinder/bot/cute_types/poll.py +9 -0
- telegrinder/bot/cute_types/poll_answer.py +9 -0
- telegrinder/bot/cute_types/pre_checkout_query.py +36 -0
- telegrinder/bot/cute_types/shipping_query.py +11 -0
- telegrinder/bot/cute_types/update.py +209 -0
- telegrinder/bot/cute_types/utils.py +141 -0
- telegrinder/bot/dispatch/__init__.py +99 -0
- telegrinder/bot/dispatch/abc.py +74 -0
- telegrinder/bot/dispatch/action.py +99 -0
- telegrinder/bot/dispatch/context.py +162 -0
- telegrinder/bot/dispatch/dispatch.py +362 -0
- telegrinder/bot/dispatch/handler/__init__.py +23 -0
- telegrinder/bot/dispatch/handler/abc.py +25 -0
- telegrinder/bot/dispatch/handler/audio_reply.py +43 -0
- telegrinder/bot/dispatch/handler/base.py +34 -0
- telegrinder/bot/dispatch/handler/document_reply.py +43 -0
- telegrinder/bot/dispatch/handler/func.py +73 -0
- telegrinder/bot/dispatch/handler/media_group_reply.py +43 -0
- telegrinder/bot/dispatch/handler/message_reply.py +35 -0
- telegrinder/bot/dispatch/handler/photo_reply.py +43 -0
- telegrinder/bot/dispatch/handler/sticker_reply.py +36 -0
- telegrinder/bot/dispatch/handler/video_reply.py +43 -0
- telegrinder/bot/dispatch/middleware/__init__.py +13 -0
- telegrinder/bot/dispatch/middleware/abc.py +112 -0
- telegrinder/bot/dispatch/middleware/box.py +32 -0
- telegrinder/bot/dispatch/middleware/filter.py +88 -0
- telegrinder/bot/dispatch/middleware/media_group.py +69 -0
- telegrinder/bot/dispatch/process.py +93 -0
- telegrinder/bot/dispatch/return_manager/__init__.py +21 -0
- telegrinder/bot/dispatch/return_manager/abc.py +107 -0
- telegrinder/bot/dispatch/return_manager/callback_query.py +19 -0
- telegrinder/bot/dispatch/return_manager/inline_query.py +14 -0
- telegrinder/bot/dispatch/return_manager/message.py +34 -0
- telegrinder/bot/dispatch/return_manager/pre_checkout_query.py +19 -0
- telegrinder/bot/dispatch/return_manager/utils.py +20 -0
- telegrinder/bot/dispatch/router/__init__.py +4 -0
- telegrinder/bot/dispatch/router/abc.py +15 -0
- telegrinder/bot/dispatch/router/base.py +154 -0
- telegrinder/bot/dispatch/view/__init__.py +15 -0
- telegrinder/bot/dispatch/view/abc.py +15 -0
- telegrinder/bot/dispatch/view/base.py +226 -0
- telegrinder/bot/dispatch/view/box.py +207 -0
- telegrinder/bot/dispatch/view/media_group.py +25 -0
- telegrinder/bot/dispatch/waiter_machine/__init__.py +25 -0
- telegrinder/bot/dispatch/waiter_machine/actions.py +16 -0
- telegrinder/bot/dispatch/waiter_machine/hasher/__init__.py +13 -0
- telegrinder/bot/dispatch/waiter_machine/hasher/callback.py +53 -0
- telegrinder/bot/dispatch/waiter_machine/hasher/hasher.py +61 -0
- telegrinder/bot/dispatch/waiter_machine/hasher/message.py +49 -0
- telegrinder/bot/dispatch/waiter_machine/machine.py +264 -0
- telegrinder/bot/dispatch/waiter_machine/middleware.py +77 -0
- telegrinder/bot/dispatch/waiter_machine/short_state.py +105 -0
- telegrinder/bot/polling/__init__.py +4 -0
- telegrinder/bot/polling/abc.py +25 -0
- telegrinder/bot/polling/error_handler.py +93 -0
- telegrinder/bot/polling/polling.py +167 -0
- telegrinder/bot/polling/utils.py +12 -0
- telegrinder/bot/rules/__init__.py +166 -0
- telegrinder/bot/rules/abc.py +150 -0
- telegrinder/bot/rules/button.py +20 -0
- telegrinder/bot/rules/callback_data.py +109 -0
- telegrinder/bot/rules/chat_join.py +28 -0
- telegrinder/bot/rules/chat_member_updated.py +145 -0
- telegrinder/bot/rules/command.py +137 -0
- telegrinder/bot/rules/enum_text.py +29 -0
- telegrinder/bot/rules/func.py +21 -0
- telegrinder/bot/rules/fuzzy.py +21 -0
- telegrinder/bot/rules/inline.py +45 -0
- telegrinder/bot/rules/integer.py +19 -0
- telegrinder/bot/rules/is_from.py +213 -0
- telegrinder/bot/rules/logic.py +22 -0
- telegrinder/bot/rules/magic.py +60 -0
- telegrinder/bot/rules/markup.py +51 -0
- telegrinder/bot/rules/media.py +13 -0
- telegrinder/bot/rules/mention.py +15 -0
- telegrinder/bot/rules/message_entities.py +37 -0
- telegrinder/bot/rules/node.py +43 -0
- telegrinder/bot/rules/payload.py +89 -0
- telegrinder/bot/rules/payment_invoice.py +14 -0
- telegrinder/bot/rules/regex.py +34 -0
- telegrinder/bot/rules/rule_enum.py +71 -0
- telegrinder/bot/rules/start.py +73 -0
- telegrinder/bot/rules/state.py +35 -0
- telegrinder/bot/rules/text.py +27 -0
- telegrinder/bot/rules/update.py +14 -0
- telegrinder/bot/scenario/__init__.py +5 -0
- telegrinder/bot/scenario/abc.py +16 -0
- telegrinder/bot/scenario/checkbox.py +183 -0
- telegrinder/bot/scenario/choice.py +44 -0
- telegrinder/client/__init__.py +11 -0
- telegrinder/client/abc.py +136 -0
- telegrinder/client/form_data.py +34 -0
- telegrinder/client/rnet.py +198 -0
- telegrinder/model.py +133 -0
- telegrinder/model.pyi +57 -0
- telegrinder/modules.py +1081 -0
- telegrinder/msgspec_utils/__init__.py +42 -0
- telegrinder/msgspec_utils/abc.py +16 -0
- telegrinder/msgspec_utils/custom_types/__init__.py +6 -0
- telegrinder/msgspec_utils/custom_types/datetime.py +24 -0
- telegrinder/msgspec_utils/custom_types/enum_meta.py +61 -0
- telegrinder/msgspec_utils/custom_types/literal.py +25 -0
- telegrinder/msgspec_utils/custom_types/option.py +17 -0
- telegrinder/msgspec_utils/decoder.py +388 -0
- telegrinder/msgspec_utils/encoder.py +204 -0
- telegrinder/msgspec_utils/json.py +15 -0
- telegrinder/msgspec_utils/tools.py +80 -0
- telegrinder/node/__init__.py +80 -0
- telegrinder/node/compose.py +193 -0
- telegrinder/node/nodes/__init__.py +96 -0
- telegrinder/node/nodes/attachment.py +169 -0
- telegrinder/node/nodes/callback_query.py +25 -0
- telegrinder/node/nodes/channel.py +97 -0
- telegrinder/node/nodes/command.py +33 -0
- telegrinder/node/nodes/error.py +43 -0
- telegrinder/node/nodes/event.py +70 -0
- telegrinder/node/nodes/file.py +39 -0
- telegrinder/node/nodes/global_node.py +66 -0
- telegrinder/node/nodes/i18n.py +110 -0
- telegrinder/node/nodes/me.py +26 -0
- telegrinder/node/nodes/message_entities.py +15 -0
- telegrinder/node/nodes/payload.py +84 -0
- telegrinder/node/nodes/reply_message.py +14 -0
- telegrinder/node/nodes/source.py +172 -0
- telegrinder/node/nodes/state_mutator.py +71 -0
- telegrinder/node/nodes/text.py +62 -0
- telegrinder/node/scope.py +88 -0
- telegrinder/node/utils.py +38 -0
- telegrinder/py.typed +0 -0
- telegrinder/rules.py +1 -0
- telegrinder/tools/__init__.py +183 -0
- telegrinder/tools/aio.py +147 -0
- telegrinder/tools/final.py +21 -0
- telegrinder/tools/formatting/__init__.py +85 -0
- telegrinder/tools/formatting/deep_links/__init__.py +39 -0
- telegrinder/tools/formatting/deep_links/links.py +468 -0
- telegrinder/tools/formatting/deep_links/parsing.py +88 -0
- telegrinder/tools/formatting/deep_links/validators.py +8 -0
- telegrinder/tools/formatting/html.py +241 -0
- telegrinder/tools/fullname.py +82 -0
- telegrinder/tools/global_context/__init__.py +13 -0
- telegrinder/tools/global_context/abc.py +63 -0
- telegrinder/tools/global_context/builtin_context.py +45 -0
- telegrinder/tools/global_context/global_context.py +614 -0
- telegrinder/tools/input_file_directory.py +30 -0
- telegrinder/tools/keyboard/__init__.py +6 -0
- telegrinder/tools/keyboard/abc.py +84 -0
- telegrinder/tools/keyboard/base.py +108 -0
- telegrinder/tools/keyboard/button.py +181 -0
- telegrinder/tools/keyboard/data.py +31 -0
- telegrinder/tools/keyboard/keyboard.py +160 -0
- telegrinder/tools/keyboard/utils.py +95 -0
- telegrinder/tools/lifespan.py +188 -0
- telegrinder/tools/limited_dict.py +35 -0
- telegrinder/tools/loop_wrapper.py +271 -0
- telegrinder/tools/magic/__init__.py +29 -0
- telegrinder/tools/magic/annotations.py +172 -0
- telegrinder/tools/magic/descriptors.py +57 -0
- telegrinder/tools/magic/function.py +254 -0
- telegrinder/tools/magic/inspect.py +16 -0
- telegrinder/tools/magic/shortcut.py +107 -0
- telegrinder/tools/member_descriptor_proxy.py +95 -0
- telegrinder/tools/parse_mode.py +12 -0
- telegrinder/tools/serialization/__init__.py +5 -0
- telegrinder/tools/serialization/abc.py +34 -0
- telegrinder/tools/serialization/json_ser.py +60 -0
- telegrinder/tools/serialization/msgpack_ser.py +197 -0
- telegrinder/tools/serialization/utils.py +18 -0
- telegrinder/tools/singleton/__init__.py +4 -0
- telegrinder/tools/singleton/abc.py +14 -0
- telegrinder/tools/singleton/singleton.py +18 -0
- telegrinder/tools/state_mutator/__init__.py +4 -0
- telegrinder/tools/state_mutator/mutation.py +85 -0
- telegrinder/tools/state_storage/__init__.py +4 -0
- telegrinder/tools/state_storage/abc.py +38 -0
- telegrinder/tools/state_storage/memory.py +27 -0
- telegrinder/tools/strings.py +22 -0
- telegrinder/types/__init__.py +323 -0
- telegrinder/types/enums.py +754 -0
- telegrinder/types/input_file.py +51 -0
- telegrinder/types/methods.py +6143 -0
- telegrinder/types/methods_utils.py +66 -0
- telegrinder/types/objects.py +8184 -0
- telegrinder/types/webapp.py +129 -0
- telegrinder/verification_utils.py +35 -0
- telegrinder-1.0.0rc1.dist-info/METADATA +166 -0
- telegrinder-1.0.0rc1.dist-info/RECORD +215 -0
- telegrinder-1.0.0rc1.dist-info/WHEEL +4 -0
- telegrinder-1.0.0rc1.dist-info/licenses/LICENSE +22 -0
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
from datetime import timedelta
|
|
3
|
+
from functools import wraps
|
|
4
|
+
|
|
5
|
+
from telegrinder.tools.formatting.deep_links.parsing import (
|
|
6
|
+
NO_VALUE,
|
|
7
|
+
DeepLinkFunction,
|
|
8
|
+
NoValue,
|
|
9
|
+
Parameter,
|
|
10
|
+
get_query_params,
|
|
11
|
+
parse_deep_link,
|
|
12
|
+
)
|
|
13
|
+
from telegrinder.tools.formatting.deep_links.validators import separate_by_plus_char
|
|
14
|
+
|
|
15
|
+
type Permission = typing.Literal[
|
|
16
|
+
"change_info",
|
|
17
|
+
"post_messages",
|
|
18
|
+
"edit_messages",
|
|
19
|
+
"delete_messages",
|
|
20
|
+
"invite_users",
|
|
21
|
+
"restrict_members",
|
|
22
|
+
"promote_members",
|
|
23
|
+
"pin_messages",
|
|
24
|
+
"manage_topics",
|
|
25
|
+
"manage_video_chats",
|
|
26
|
+
"anonymous",
|
|
27
|
+
"manage_chat",
|
|
28
|
+
"post_stories",
|
|
29
|
+
"edit_stories",
|
|
30
|
+
"delete_stories",
|
|
31
|
+
]
|
|
32
|
+
type Peer = typing.Literal[
|
|
33
|
+
"users",
|
|
34
|
+
"bots",
|
|
35
|
+
"groups",
|
|
36
|
+
"channels",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def deep_link[**P](
|
|
41
|
+
link: str,
|
|
42
|
+
/,
|
|
43
|
+
*,
|
|
44
|
+
no_value_params: set[str] | None = None,
|
|
45
|
+
order_params: set[str] | None = None,
|
|
46
|
+
) -> typing.Callable[[DeepLinkFunction[P]], DeepLinkFunction[P]]:
|
|
47
|
+
if not link.startswith("tg://"):
|
|
48
|
+
raise RuntimeError("Invalid deep link format. The link must start with 'tg://'.")
|
|
49
|
+
|
|
50
|
+
def inner(func: DeepLinkFunction[P]) -> DeepLinkFunction[P]:
|
|
51
|
+
@wraps(func)
|
|
52
|
+
def wrapper(*_: P.args, **kwargs: P.kwargs) -> str:
|
|
53
|
+
return parse_deep_link(
|
|
54
|
+
link=link,
|
|
55
|
+
params=get_query_params(func, kwargs, order_params),
|
|
56
|
+
no_value_params=no_value_params,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
return wrapper
|
|
60
|
+
|
|
61
|
+
return inner
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@deep_link("tg://resolve")
|
|
65
|
+
def tg_public_username_link(
|
|
66
|
+
*,
|
|
67
|
+
username: Parameter[str, "domain"],
|
|
68
|
+
draft_text: Parameter[str | None, "text"] = None,
|
|
69
|
+
open_profile: Parameter[bool, "profile"] = False,
|
|
70
|
+
) -> str:
|
|
71
|
+
"""Used to link to public `users`, `groups` and `channels`.
|
|
72
|
+
|
|
73
|
+
:param username: Username.
|
|
74
|
+
:param draft_text: Optional. UTF-8 text to pre-enter into the text input bar, if the user can write in the chat.
|
|
75
|
+
:param open_profile: Optional. If set, clicking on this link should open the destination peer's profile page, not the chat view.
|
|
76
|
+
"""
|
|
77
|
+
...
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@deep_link("tg://user")
|
|
81
|
+
def tg_mention_link(*, user_id: Parameter[int, "id"]) -> str:
|
|
82
|
+
"""ID links are merely an abstraction offered by the `Bot API` to simplify construction of
|
|
83
|
+
`inputMessageEntityMentionName` and `inputKeyboardButtonUserProfile` constructors, and should be
|
|
84
|
+
ignored by normal clients.
|
|
85
|
+
|
|
86
|
+
:param user_id: User ID.
|
|
87
|
+
"""
|
|
88
|
+
...
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@deep_link("tg://openmessage")
|
|
92
|
+
def tg_open_message_link(
|
|
93
|
+
*,
|
|
94
|
+
chat_id: int | None = None,
|
|
95
|
+
user_id: int | None = None,
|
|
96
|
+
message_id: int | None = None,
|
|
97
|
+
) -> str: ...
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
@deep_link("tg://emoji")
|
|
101
|
+
def tg_emoji_link(*, emoji_id: Parameter[int, "id"]) -> str:
|
|
102
|
+
"""Emoji links are merely an abstraction offered by the `Bot API` to simplify construction of
|
|
103
|
+
`messageEntityCustomEmoji` constructors, and should be ignored by normal clients.
|
|
104
|
+
|
|
105
|
+
:param emoji_id: Custom emoji ID.
|
|
106
|
+
"""
|
|
107
|
+
...
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
@deep_link("tg://addemoji")
|
|
111
|
+
def tg_emoji_stickerset_link(*, short_name: Parameter[str, "set"]) -> str:
|
|
112
|
+
"""Used to import custom emoji stickersets.
|
|
113
|
+
|
|
114
|
+
:param short_name: Stickerset short name, used when installing stickers.
|
|
115
|
+
"""
|
|
116
|
+
...
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
@deep_link("tg://resolve")
|
|
120
|
+
def tg_story_link(
|
|
121
|
+
*,
|
|
122
|
+
username: Parameter[str, "domain"],
|
|
123
|
+
story_id: Parameter[int, "story"],
|
|
124
|
+
) -> str:
|
|
125
|
+
"""Used to link to a Telegram Story.
|
|
126
|
+
|
|
127
|
+
:param username: Username of the user or channel that posted the story.
|
|
128
|
+
:param story_id: ID of the Telegram Story.
|
|
129
|
+
"""
|
|
130
|
+
...
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
@deep_link("tg://join")
|
|
134
|
+
def tg_chat_invite_link(*, invite_hash: Parameter[str, "invite"]) -> str:
|
|
135
|
+
"""Used to invite users to private `groups` and `channels`.
|
|
136
|
+
|
|
137
|
+
:param invite_hash: Invite hash.
|
|
138
|
+
"""
|
|
139
|
+
...
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
@deep_link("tg://addlist")
|
|
143
|
+
def tg_chat_folder_link(*, slug: str) -> str:
|
|
144
|
+
"""Used to add chat folders.
|
|
145
|
+
|
|
146
|
+
:param slug: Folder slug.
|
|
147
|
+
"""
|
|
148
|
+
...
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
@deep_link("tg://resolve")
|
|
152
|
+
def tg_public_message_link(
|
|
153
|
+
*,
|
|
154
|
+
dialog: Parameter[str, "domain"],
|
|
155
|
+
message_id: Parameter[int, "post"],
|
|
156
|
+
single: bool = False,
|
|
157
|
+
thread_id: Parameter[int | None, "thread"] = None,
|
|
158
|
+
comment: str | None = None,
|
|
159
|
+
timestamp: Parameter[timedelta | None, "t"] = None,
|
|
160
|
+
) -> str:
|
|
161
|
+
"""Used to link to specific messages in public or private `groups` and `channels`.
|
|
162
|
+
|
|
163
|
+
:param dialog: Dialog username.
|
|
164
|
+
:param message_id: Message ID.
|
|
165
|
+
:param single: Optional. For albums/grouped media, if set indicates that this is a link to a specific media in the album; otherwise, it is a link to the entire album.
|
|
166
|
+
:param thread_id: Optional. For message threads, contains the thread ID.
|
|
167
|
+
:param comment: Optional. For channel comments, username will contain the channel username, id will contain the message ID of the channel message that started the comment section and this field will contain the message ID of the comment in the discussion group.
|
|
168
|
+
:param timestamp: Optional. Timestamp at which to start playing the media file present in the body or in the webpage preview of the message.
|
|
169
|
+
"""
|
|
170
|
+
...
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
@deep_link("tg://privatepost")
|
|
174
|
+
def tg_private_message_link(
|
|
175
|
+
*,
|
|
176
|
+
channel: str,
|
|
177
|
+
message_id: Parameter[int, "post"],
|
|
178
|
+
single: bool = False,
|
|
179
|
+
thread_id: Parameter[int | None, "thread"] = None,
|
|
180
|
+
comment: str | None = None,
|
|
181
|
+
timestamp: Parameter[timedelta | None, "t"] = None,
|
|
182
|
+
) -> str:
|
|
183
|
+
"""Used to link to specific messages in public or private `groups` and `channels`.
|
|
184
|
+
|
|
185
|
+
:param channel: Channel or supergroup ID.
|
|
186
|
+
:param post: Message ID.
|
|
187
|
+
:param single: Optional. For albums/grouped media, if set indicates that this is a link to a specific media in the album; otherwise, it is a link to the entire album.
|
|
188
|
+
:param thread: Optional. For message threads, contains the thread ID.
|
|
189
|
+
:param comment: Optional. For channel comments, username will contain the channel username, id will contain the message ID of the channel message that started the comment section and this field will contain the message ID of the comment in the discussion group.
|
|
190
|
+
:param t: Optional. Timestamp at which to start playing the media file present in the body or in the webpage preview of the message.
|
|
191
|
+
"""
|
|
192
|
+
...
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
@deep_link("tg://msg_url")
|
|
196
|
+
def tg_share_link(*, url: str, text: str | None = None) -> str:
|
|
197
|
+
"""Used to share a prepared message and URL into a chosen chat's text field.
|
|
198
|
+
|
|
199
|
+
These links should be handled as follows:
|
|
200
|
+
* Open a dialog selection prompt
|
|
201
|
+
* After selection: validate, trim and enter the URL at the beginning of the text field
|
|
202
|
+
* Append a newline to the text field
|
|
203
|
+
* Append and select the `text`, if present
|
|
204
|
+
|
|
205
|
+
:param url: URL to share (`urlencoded`).
|
|
206
|
+
:param text: Optional. Text to prepend to the URL.
|
|
207
|
+
"""
|
|
208
|
+
...
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
@deep_link("tg://boost")
|
|
212
|
+
def tg_public_channel_boost_link(*, channel_username: Parameter[str, "domain"]) -> str:
|
|
213
|
+
"""Used by users to boost public channels, granting them the ability to post stories and further perks.
|
|
214
|
+
|
|
215
|
+
:param channel_username: Channel username.
|
|
216
|
+
"""
|
|
217
|
+
...
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
@deep_link("tg://boost")
|
|
221
|
+
def tg_private_channel_boost_link(*, channel_id: Parameter[int, "channel"]) -> str:
|
|
222
|
+
"""Used by users to boost private channels, granting them the ability to post stories and further perks.
|
|
223
|
+
|
|
224
|
+
:param channel_id: Channel ID.
|
|
225
|
+
"""
|
|
226
|
+
...
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
@deep_link("tg://invoice")
|
|
230
|
+
def tg_invoice_link(*, slug: str) -> str:
|
|
231
|
+
"""Used to initiate payment of an invoice, generated using `payments.exportedInvoice`.
|
|
232
|
+
|
|
233
|
+
:param slug: The invoice slug to be used during payment.
|
|
234
|
+
"""
|
|
235
|
+
...
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
@deep_link("tg://setlanguage")
|
|
239
|
+
def tg_language_pack_link(
|
|
240
|
+
*,
|
|
241
|
+
lang_pack: Parameter[str | None, "lang"] = None,
|
|
242
|
+
) -> str:
|
|
243
|
+
"""Used to import custom language packs using `langpack.getLangPack`.
|
|
244
|
+
|
|
245
|
+
:param lang_pack: Optional. Name of language pack.
|
|
246
|
+
"""
|
|
247
|
+
...
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
@deep_link("tg://premium_multigift")
|
|
251
|
+
def tg_premium_multigift_link(*, ref: str) -> str:
|
|
252
|
+
"""Used to bring the user to the screen used for gifting `Telegram Premium` subscriptions to friends,
|
|
253
|
+
see here for more info on gifting `Telegram Premium` to multiple users.
|
|
254
|
+
|
|
255
|
+
This link is used to invite users to gift `Premium` subscription to other users, see here for the different
|
|
256
|
+
link type containing the actual giftcodes that can be used to import a gifted `Telegram Premium` subscription.
|
|
257
|
+
|
|
258
|
+
:param ref: Used by official apps for analytics using `help.saveAppLog`.
|
|
259
|
+
"""
|
|
260
|
+
...
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
@deep_link("tg://premium_offer")
|
|
264
|
+
def tg_premium_offer_link(*, ref: str | None = None) -> str:
|
|
265
|
+
"""Used by official apps to show the `Telegram Premium` subscription page.
|
|
266
|
+
|
|
267
|
+
:param ref: Optional. Used by official apps for analytics using `help.saveAppLog`.
|
|
268
|
+
"""
|
|
269
|
+
...
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
@deep_link("tg://resolve")
|
|
273
|
+
def tg_bot_start_link(
|
|
274
|
+
*,
|
|
275
|
+
bot_username: Parameter[str, "domain"],
|
|
276
|
+
parameter: Parameter[str | None, "start"] = None,
|
|
277
|
+
) -> str:
|
|
278
|
+
"""Used to link to bots.
|
|
279
|
+
|
|
280
|
+
:param bot_username: Bot username.
|
|
281
|
+
:param parameter: Optional. Start parameter, up to 64 `base64url` characters: if provided and the `bot_username` is indeed a bot, \
|
|
282
|
+
the text input bar should be replaced with a `Start` button (even if the user has already started the bot) that should invoke \
|
|
283
|
+
`messages.startBot` with the appropriate `parameter` once clicked. Note that if the `bot_username` is equal to the `premium_bot_username` \
|
|
284
|
+
configuration value, clicking on this link should immediately invoke `messages.startBot` with the appropriate `parameter`.
|
|
285
|
+
"""
|
|
286
|
+
...
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
@deep_link("tg://resolve")
|
|
290
|
+
def tg_bot_startgroup_link(
|
|
291
|
+
*,
|
|
292
|
+
bot_username: Parameter[str, "domain"],
|
|
293
|
+
parameter: Parameter[str | NoValue, "startgroup"] = NO_VALUE,
|
|
294
|
+
permissions: Parameter[list[Permission] | None, "admin", separate_by_plus_char] = None,
|
|
295
|
+
) -> str:
|
|
296
|
+
"""Used to add bots to groups.
|
|
297
|
+
First of all, check that the `<bot_username>` indeed links to a bot.
|
|
298
|
+
|
|
299
|
+
Then, for group links:
|
|
300
|
+
|
|
301
|
+
If the `admin` parameter is not provided:
|
|
302
|
+
- Bring up a dialog selection of groups where the user can add members
|
|
303
|
+
- Add the bot to the group
|
|
304
|
+
- If a `parameter` is provided, invoke `messages.startBot` with the appropriate `parameter`
|
|
305
|
+
|
|
306
|
+
If the admin parameter is provided:
|
|
307
|
+
- Bring up a dialog selection of groups where the user can add/edit admins
|
|
308
|
+
- If the bot is already an admin of the group, combine existing admin rights with the admin rights in admin
|
|
309
|
+
- Add the bot as admin/modify admin permissions to the new rights
|
|
310
|
+
- If a parameter is provided, invoke `messages.startBot` with the appropriate `parameter`
|
|
311
|
+
|
|
312
|
+
:param bot_username: Bot username.
|
|
313
|
+
:param parameter: Optional. Start parameter, only for group links, up to 64 `base64url` characters: if provided and the `bot_username` is indeed a bot, \
|
|
314
|
+
`messages.startBot` with the appropriate parameter should be invoked after adding the bot to the group.
|
|
315
|
+
:param permissions: Optional. A combination of the following identifiers separated by `+`, each corresponding to the appropriate flag in the `chatAdminRights` constructor.
|
|
316
|
+
"""
|
|
317
|
+
...
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
@deep_link("tg://resolve", no_value_params={"startchannel"})
|
|
321
|
+
def tg_bot_startchannel_link(
|
|
322
|
+
*,
|
|
323
|
+
bot_username: Parameter[str, "domain"],
|
|
324
|
+
permissions: Parameter[list[Permission], "admin", separate_by_plus_char],
|
|
325
|
+
) -> str:
|
|
326
|
+
"""Used to add bots to channels.
|
|
327
|
+
First of all, check that the `<bot_username>` indeed links to a bot.
|
|
328
|
+
|
|
329
|
+
For channel links:
|
|
330
|
+
- Bring up a dialog selection of channels where the user can add/edit admins
|
|
331
|
+
- If the bot is already an admin of the channel, combine existing admin rights with the admin rights in admin
|
|
332
|
+
- Add the bot as admin/modify admin permissions to the new rights
|
|
333
|
+
|
|
334
|
+
:param bot_username: Bot username.
|
|
335
|
+
:param permissions: A combination of the following identifiers separated by `+`, each corresponding to the \
|
|
336
|
+
appropriate flag in the `chatAdminRights` constructor.
|
|
337
|
+
"""
|
|
338
|
+
...
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
@deep_link("tg://resolve")
|
|
342
|
+
def tg_main_mini_app_link(
|
|
343
|
+
*,
|
|
344
|
+
bot_username: Parameter[str, "domain"],
|
|
345
|
+
parameter: Parameter[str | NoValue, "startapp"] = NO_VALUE,
|
|
346
|
+
mode: typing.Literal["compact"] | None = None,
|
|
347
|
+
) -> str:
|
|
348
|
+
"""Used to open `Main Mini Apps`.
|
|
349
|
+
|
|
350
|
+
If the specified bot does not have a configured `Main` Mini App (i.e. the user.bot_has_main_app flag will not be set),
|
|
351
|
+
fall back to the behavior of username links.
|
|
352
|
+
|
|
353
|
+
The main mini app should be opened using `messages.requestMainWebView`.
|
|
354
|
+
|
|
355
|
+
:param bot_username: Bot username.
|
|
356
|
+
:param parameter: Optional. If provided, should be passed to `messages.requestMainWebView.start_param`.
|
|
357
|
+
:param mode: Optional. If equal to `compact`, the `messages.requestMainWebView.compact` flag must be set.
|
|
358
|
+
"""
|
|
359
|
+
...
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
@deep_link("tg://resolve")
|
|
363
|
+
def tg_direct_mini_app_link(
|
|
364
|
+
*,
|
|
365
|
+
bot_username: Parameter[str, "domain"],
|
|
366
|
+
short_name: Parameter[str, "appname"],
|
|
367
|
+
parameter: Parameter[str | NoValue, "startapp"] = NO_VALUE,
|
|
368
|
+
mode: typing.Literal["compact"] | None = None,
|
|
369
|
+
) -> str:
|
|
370
|
+
"""Used to share `Direct` link Mini apps.
|
|
371
|
+
|
|
372
|
+
These links are different from bot attachment menu deep links, because they don't require the user to install
|
|
373
|
+
an attachment menu, and a single bot can offer multiple named mini apps, distinguished by their `short_name`.
|
|
374
|
+
|
|
375
|
+
These links should be handled as specified in the direct link Mini Apps documentation.
|
|
376
|
+
|
|
377
|
+
:param bot_username: Username of the bot that owns the game.
|
|
378
|
+
:param short_name: Mini app short name, to pass to `inputBotAppShortName.short_name` when invoking `messages.getBotApp`.
|
|
379
|
+
:param parameter: Optional. To pass to `messages.requestAppWebView.start_param`.
|
|
380
|
+
:param mode: Optional. If equal to `compact`, the `messages.requestAppWebView.compact` flag must be set.
|
|
381
|
+
"""
|
|
382
|
+
...
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
@deep_link("tg://resolve")
|
|
386
|
+
def tg_bot_attach_open_current_chat(
|
|
387
|
+
*,
|
|
388
|
+
bot_username: Parameter[str, "domain"],
|
|
389
|
+
parameter: Parameter[str | NoValue, "startattach"] = NO_VALUE,
|
|
390
|
+
) -> str:
|
|
391
|
+
"""After installing the attachment/side menu entry globally, opens the associated mini app using
|
|
392
|
+
`messages.requestWebView` in the currently open chat, by passing it to the peer parameter of `messages.requestWebView`.
|
|
393
|
+
|
|
394
|
+
If the current chat is not supported by the `attachMenuBot.peer_types` field:
|
|
395
|
+
|
|
396
|
+
- If the user has just installed the attachment menu in the previous step, notify the user that the attachment menu was installed successfully.
|
|
397
|
+
- Otherwise, notify the user that the attachment menu webapp can't be opened in the specified chat.
|
|
398
|
+
|
|
399
|
+
:param bot_username: Username of the bot that owns the attachment/side menu entry.
|
|
400
|
+
:param parameter: Optional. If provided, should be passed to `messages.requestWebView.start_param`.
|
|
401
|
+
"""
|
|
402
|
+
...
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
@deep_link("tg://resolve")
|
|
406
|
+
def tg_bot_attach_open_specific_chat(
|
|
407
|
+
*,
|
|
408
|
+
username: Parameter[str, "domain"],
|
|
409
|
+
phone_number: Parameter[str, "phone"],
|
|
410
|
+
bot_username: Parameter[str, "attach"],
|
|
411
|
+
parameter: Parameter[str | NoValue, "startattach"] = NO_VALUE,
|
|
412
|
+
) -> str:
|
|
413
|
+
"""After installing the `attachment/side` menu entry globally, opens the associated mini app using
|
|
414
|
+
`messages.requestWebView` in a specific chat (passed to the peer parameter of `messages.requestWebView`).
|
|
415
|
+
|
|
416
|
+
If the specified chat is not supported by the attachMenuBot.peer_types field:
|
|
417
|
+
|
|
418
|
+
- If the user has just installed the attachment menu in the previous step, notify the user that the attachment menu was installed successfully.
|
|
419
|
+
- Otherwise, notify the user that the attachment menu webapp can't be opened in the specified chat.
|
|
420
|
+
"""
|
|
421
|
+
...
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
@deep_link("tg://resolve")
|
|
425
|
+
def tg_bot_attach_open_any_chat(
|
|
426
|
+
*,
|
|
427
|
+
bot_username: Parameter[str, "domain"],
|
|
428
|
+
parameter: Parameter[str | NoValue, "startattach"] = NO_VALUE,
|
|
429
|
+
peer: Parameter[list[Peer] | None, "choose", separate_by_plus_char] = None,
|
|
430
|
+
) -> str:
|
|
431
|
+
"""After installing the `attachment/side` menu entry globally, opens a dialog selection form that will open the attachment menu
|
|
432
|
+
mini app using `messages.requestWebView` in a specific chat (pass it to the peer parameter of `messages.requestWebView`).
|
|
433
|
+
|
|
434
|
+
:param bot_username: Username of the bot that owns the `attachment/side` menu.
|
|
435
|
+
:param parameter: Optional. If provided, should be passed to `messages.requestWebView.start_param`.
|
|
436
|
+
:param peer: Optional. A combination of `users`, `bots`, `groups`, `channels` separated by `+`: indicates the dialog types to show in \
|
|
437
|
+
the dialog selection popup: must be intersected with the dialog types contained in the `attachMenuBot.peer_types` field before use.
|
|
438
|
+
"""
|
|
439
|
+
...
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
__all__ = (
|
|
443
|
+
"tg_bot_attach_open_any_chat",
|
|
444
|
+
"tg_bot_attach_open_current_chat",
|
|
445
|
+
"tg_bot_attach_open_specific_chat",
|
|
446
|
+
"tg_bot_start_link",
|
|
447
|
+
"tg_bot_startchannel_link",
|
|
448
|
+
"tg_bot_startgroup_link",
|
|
449
|
+
"tg_chat_folder_link",
|
|
450
|
+
"tg_chat_invite_link",
|
|
451
|
+
"tg_direct_mini_app_link",
|
|
452
|
+
"tg_emoji_link",
|
|
453
|
+
"tg_emoji_stickerset_link",
|
|
454
|
+
"tg_invoice_link",
|
|
455
|
+
"tg_language_pack_link",
|
|
456
|
+
"tg_main_mini_app_link",
|
|
457
|
+
"tg_mention_link",
|
|
458
|
+
"tg_open_message_link",
|
|
459
|
+
"tg_premium_multigift_link",
|
|
460
|
+
"tg_premium_offer_link",
|
|
461
|
+
"tg_private_channel_boost_link",
|
|
462
|
+
"tg_private_message_link",
|
|
463
|
+
"tg_public_channel_boost_link",
|
|
464
|
+
"tg_public_message_link",
|
|
465
|
+
"tg_public_username_link",
|
|
466
|
+
"tg_share_link",
|
|
467
|
+
"tg_story_link",
|
|
468
|
+
)
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import types
|
|
2
|
+
import typing
|
|
3
|
+
from collections import OrderedDict
|
|
4
|
+
from datetime import timedelta
|
|
5
|
+
from urllib.parse import urlencode
|
|
6
|
+
|
|
7
|
+
from telegrinder.tools.magic.function import get_func_annotations
|
|
8
|
+
|
|
9
|
+
type DeepLinkFunction[**P] = typing.Callable[P, str]
|
|
10
|
+
type NoValue = types.EllipsisType
|
|
11
|
+
|
|
12
|
+
Parameter = typing.Annotated
|
|
13
|
+
|
|
14
|
+
NO_VALUE: typing.Final[NoValue] = typing.cast("NoValue", ...)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def get_query_params(
|
|
18
|
+
func: DeepLinkFunction[...],
|
|
19
|
+
kwargs: dict[str, typing.Any],
|
|
20
|
+
order_params: set[str] | None = None,
|
|
21
|
+
) -> dict[str, typing.Any]:
|
|
22
|
+
annotations = get_func_annotations(func)
|
|
23
|
+
params = OrderedDict()
|
|
24
|
+
param_names = [*order_params, *(p for p in annotations if p not in order_params)] if order_params else annotations
|
|
25
|
+
|
|
26
|
+
for param_name in param_names:
|
|
27
|
+
annotation = annotations[param_name]
|
|
28
|
+
if param_name in kwargs:
|
|
29
|
+
value = kwargs[param_name]
|
|
30
|
+
if typing.get_origin(annotation) is Parameter:
|
|
31
|
+
param_name, validator = get_parameter_metadata(annotation)
|
|
32
|
+
value = validator(value) if validator is not None else value
|
|
33
|
+
|
|
34
|
+
params[param_name] = value
|
|
35
|
+
|
|
36
|
+
return params
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def parse_query_params(
|
|
40
|
+
params: dict[str, typing.Any],
|
|
41
|
+
no_value_params: set[str] | None = None,
|
|
42
|
+
/,
|
|
43
|
+
) -> tuple[set[str], dict[str, typing.Any]]:
|
|
44
|
+
no_value_params = no_value_params or set()
|
|
45
|
+
params_: dict[str, typing.Any] = {}
|
|
46
|
+
|
|
47
|
+
for key, value in params.items():
|
|
48
|
+
if value in (False, None):
|
|
49
|
+
continue
|
|
50
|
+
|
|
51
|
+
if value in (True, NO_VALUE):
|
|
52
|
+
no_value_params.add(key)
|
|
53
|
+
continue
|
|
54
|
+
if isinstance(value, timedelta):
|
|
55
|
+
value = int(value.total_seconds())
|
|
56
|
+
|
|
57
|
+
params_[key] = value
|
|
58
|
+
|
|
59
|
+
return (no_value_params, params_)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def get_parameter_metadata(
|
|
63
|
+
parameter: typing.Any,
|
|
64
|
+
) -> tuple[str, typing.Callable[[typing.Any], typing.Any] | None]:
|
|
65
|
+
meta: tuple[typing.Any, ...] = getattr(parameter, "__metadata__")
|
|
66
|
+
return meta if len(meta) == 2 else (meta[0], None)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def parse_deep_link(
|
|
70
|
+
*,
|
|
71
|
+
link: str,
|
|
72
|
+
params: dict[str, typing.Any],
|
|
73
|
+
no_value_params: set[str] | None = None,
|
|
74
|
+
) -> str:
|
|
75
|
+
no_value_params, params = parse_query_params(params, no_value_params)
|
|
76
|
+
query = urlencode(params, encoding="UTF-8") + ("&" if no_value_params else "") + "&".join(no_value_params)
|
|
77
|
+
return f"{link}?{query}"
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
__all__ = (
|
|
81
|
+
"NO_VALUE",
|
|
82
|
+
"NoValue",
|
|
83
|
+
"Parameter",
|
|
84
|
+
"get_parameter_metadata",
|
|
85
|
+
"get_query_params",
|
|
86
|
+
"parse_deep_link",
|
|
87
|
+
"parse_query_params",
|
|
88
|
+
)
|