python-trueconf-bot 1.0.0__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.
Files changed (120) hide show
  1. python_trueconf_bot-1.0.0.dist-info/METADATA +115 -0
  2. python_trueconf_bot-1.0.0.dist-info/RECORD +120 -0
  3. python_trueconf_bot-1.0.0.dist-info/WHEEL +5 -0
  4. python_trueconf_bot-1.0.0.dist-info/licenses/LICENSE +32 -0
  5. python_trueconf_bot-1.0.0.dist-info/top_level.txt +1 -0
  6. trueconf/__init__.py +18 -0
  7. trueconf/_version.py +34 -0
  8. trueconf/client/__init__.py +0 -0
  9. trueconf/client/bot.py +1269 -0
  10. trueconf/client/context_controller.py +27 -0
  11. trueconf/client/session.py +60 -0
  12. trueconf/dispatcher/__init__.py +0 -0
  13. trueconf/dispatcher/dispatcher.py +56 -0
  14. trueconf/dispatcher/router.py +207 -0
  15. trueconf/enums/__init__.py +23 -0
  16. trueconf/enums/aouth_error.py +15 -0
  17. trueconf/enums/chat_participant_role.py +18 -0
  18. trueconf/enums/chat_type.py +17 -0
  19. trueconf/enums/envelope_author_type.py +13 -0
  20. trueconf/enums/file_ready_state.py +14 -0
  21. trueconf/enums/incoming_update_method.py +14 -0
  22. trueconf/enums/message_type.py +27 -0
  23. trueconf/enums/parse_mode.py +14 -0
  24. trueconf/enums/survey_type.py +6 -0
  25. trueconf/enums/update_type.py +14 -0
  26. trueconf/exceptions.py +17 -0
  27. trueconf/filters/__init__.py +11 -0
  28. trueconf/filters/base.py +8 -0
  29. trueconf/filters/command.py +32 -0
  30. trueconf/filters/instance_of.py +11 -0
  31. trueconf/filters/message.py +15 -0
  32. trueconf/filters/method.py +12 -0
  33. trueconf/loggers.py +4 -0
  34. trueconf/methods/__init__.py +59 -0
  35. trueconf/methods/add_participant_to_chat.py +22 -0
  36. trueconf/methods/auth.py +25 -0
  37. trueconf/methods/base.py +107 -0
  38. trueconf/methods/create_channel.py +20 -0
  39. trueconf/methods/create_group_chat.py +20 -0
  40. trueconf/methods/create_p2p_chat.py +20 -0
  41. trueconf/methods/edit_message.py +25 -0
  42. trueconf/methods/edit_survey.py +32 -0
  43. trueconf/methods/forward_message.py +22 -0
  44. trueconf/methods/get_chat_by_id.py +20 -0
  45. trueconf/methods/get_chat_history.py +24 -0
  46. trueconf/methods/get_chat_participants.py +24 -0
  47. trueconf/methods/get_chats.py +22 -0
  48. trueconf/methods/get_file_info.py +20 -0
  49. trueconf/methods/get_message_by_id.py +19 -0
  50. trueconf/methods/get_user_display_name.py +20 -0
  51. trueconf/methods/has_chat_participant.py +22 -0
  52. trueconf/methods/remove_chat.py +20 -0
  53. trueconf/methods/remove_message.py +23 -0
  54. trueconf/methods/remove_participant_from_chat.py +23 -0
  55. trueconf/methods/send_file.py +25 -0
  56. trueconf/methods/send_message.py +29 -0
  57. trueconf/methods/send_survey.py +40 -0
  58. trueconf/methods/subscribe_file_progress.py +21 -0
  59. trueconf/methods/unsubscribe_file_progress.py +21 -0
  60. trueconf/methods/upload_file.py +21 -0
  61. trueconf/py.typed +0 -0
  62. trueconf/types/__init__.py +25 -0
  63. trueconf/types/author_box.py +17 -0
  64. trueconf/types/chat_participant.py +11 -0
  65. trueconf/types/content/__init__.py +25 -0
  66. trueconf/types/content/attachment.py +14 -0
  67. trueconf/types/content/base.py +8 -0
  68. trueconf/types/content/chat_created.py +9 -0
  69. trueconf/types/content/document.py +71 -0
  70. trueconf/types/content/forward_message.py +21 -0
  71. trueconf/types/content/photo.py +70 -0
  72. trueconf/types/content/remove_participant.py +9 -0
  73. trueconf/types/content/sticker.py +70 -0
  74. trueconf/types/content/survey.py +19 -0
  75. trueconf/types/content/text.py +9 -0
  76. trueconf/types/content/video.py +71 -0
  77. trueconf/types/last_message.py +33 -0
  78. trueconf/types/message.py +411 -0
  79. trueconf/types/parser.py +90 -0
  80. trueconf/types/requests/__init__.py +21 -0
  81. trueconf/types/requests/added_chat_participant.py +40 -0
  82. trueconf/types/requests/created_channel.py +42 -0
  83. trueconf/types/requests/created_group_chat.py +42 -0
  84. trueconf/types/requests/created_personal_chat.py +42 -0
  85. trueconf/types/requests/edited_message.py +37 -0
  86. trueconf/types/requests/removed_chat.py +32 -0
  87. trueconf/types/requests/removed_chat_participant.py +39 -0
  88. trueconf/types/requests/removed_message.py +37 -0
  89. trueconf/types/requests/uploading_progress.py +34 -0
  90. trueconf/types/responses/__init__.py +57 -0
  91. trueconf/types/responses/add_chat_participant_response.py +8 -0
  92. trueconf/types/responses/api_error.py +38 -0
  93. trueconf/types/responses/auth_response_payload.py +9 -0
  94. trueconf/types/responses/create_channel_response.py +8 -0
  95. trueconf/types/responses/create_group_chat_response.py +8 -0
  96. trueconf/types/responses/create_p2p_chat_response.py +8 -0
  97. trueconf/types/responses/edit_message_response.py +9 -0
  98. trueconf/types/responses/edit_survey_response.py +9 -0
  99. trueconf/types/responses/forward_message_response.py +10 -0
  100. trueconf/types/responses/get_chat_by_id_response.py +13 -0
  101. trueconf/types/responses/get_chat_history_response.py +13 -0
  102. trueconf/types/responses/get_chat_participants_response.py +12 -0
  103. trueconf/types/responses/get_chats_response.py +12 -0
  104. trueconf/types/responses/get_file_info_response.py +24 -0
  105. trueconf/types/responses/get_message_by_id_response.py +26 -0
  106. trueconf/types/responses/get_user_display_name_response.py +8 -0
  107. trueconf/types/responses/has_chat_participant_response.py +8 -0
  108. trueconf/types/responses/remove_chat_participant_response.py +8 -0
  109. trueconf/types/responses/remove_chat_response.py +8 -0
  110. trueconf/types/responses/remove_message_response.py +8 -0
  111. trueconf/types/responses/send_file_response.py +10 -0
  112. trueconf/types/responses/send_message_response.py +10 -0
  113. trueconf/types/responses/send_survey_response.py +10 -0
  114. trueconf/types/responses/subscribe_file_progress_response.py +8 -0
  115. trueconf/types/responses/unsubscribe_file_progress_response.py +8 -0
  116. trueconf/types/responses/upload_file_response.py +8 -0
  117. trueconf/types/update.py +12 -0
  118. trueconf/utils/__init__.py +3 -0
  119. trueconf/utils/generate_secret_for_survey.py +10 -0
  120. trueconf/utils/token.py +78 -0
@@ -0,0 +1,40 @@
1
+ from __future__ import annotations
2
+ from __future__ import annotations
3
+ from dataclasses import dataclass
4
+ from trueconf.methods.base import TrueConfMethod
5
+ from trueconf.types.responses.send_survey_response import SendSurveyResponse
6
+
7
+
8
+ @dataclass
9
+ class SendSurvey(TrueConfMethod[SendSurveyResponse]):
10
+ __api_method__ = "sendSurvey"
11
+ __returning__ = SendSurveyResponse
12
+
13
+ chat_id: str
14
+ server: str
15
+ path: str
16
+ title: str
17
+ secret: str
18
+ description: str
19
+ button_text: str = "{{Go to survey}}"
20
+ reply_message_id: str | None = None
21
+ app_version: int = 1
22
+
23
+ def __post_init__(self):
24
+ super().__init__()
25
+
26
+ def payload(self):
27
+ return {
28
+ "chatId": self.chat_id,
29
+ "replyMessageId": self.reply_message_id,
30
+ "content": {
31
+ "url": f"https://{self.server}/webtools/survey",
32
+ "appVersion": self.app_version,
33
+ "path": self.path,
34
+ "title": self.title,
35
+ "description": self.description,
36
+ "buttonText": self.button_text,
37
+ "secret": self.secret,
38
+ "alt": f"📊 <a href='https://{self.server}/webtools/survey?id={self.path}&error=autologin_not_supported'>{self.title}</a>"
39
+ }
40
+ }
@@ -0,0 +1,21 @@
1
+ from __future__ import annotations
2
+ from __future__ import annotations
3
+ from dataclasses import dataclass
4
+ from trueconf.methods.base import TrueConfMethod
5
+ from trueconf.types.responses.subscribe_file_progress_response import SubscribeFileProgressResponse
6
+
7
+
8
+ @dataclass
9
+ class SubscribeFileProgress(TrueConfMethod[SubscribeFileProgressResponse]):
10
+ __api_method__ = "subscribeFileProgress"
11
+ __returning__ = SubscribeFileProgressResponse
12
+
13
+ file_id: str
14
+
15
+ def __post_init__(self):
16
+ super().__init__()
17
+
18
+ def payload(self):
19
+ return {
20
+ "fileId": self.file_id
21
+ }
@@ -0,0 +1,21 @@
1
+ from __future__ import annotations
2
+ from __future__ import annotations
3
+ from dataclasses import dataclass
4
+ from trueconf.methods.base import TrueConfMethod
5
+ from trueconf.types.responses.unsubscribe_file_progress_response import UnsubscribeFileProgressResponse
6
+
7
+
8
+ @dataclass
9
+ class UnsubscribeFileProgress(TrueConfMethod[UnsubscribeFileProgressResponse]):
10
+ __api_method__ = "unsubscribeFileProgress"
11
+ __returning__ = UnsubscribeFileProgressResponse
12
+
13
+ file_id: str
14
+
15
+ def __post_init__(self):
16
+ super().__init__()
17
+
18
+ def payload(self):
19
+ return {
20
+ "fileId": self.file_id
21
+ }
@@ -0,0 +1,21 @@
1
+ from __future__ import annotations
2
+ from __future__ import annotations
3
+ from dataclasses import dataclass
4
+ from trueconf.methods.base import TrueConfMethod
5
+ from trueconf.types.responses.upload_file_response import UploadFileResponse
6
+
7
+
8
+ @dataclass
9
+ class UploadFile(TrueConfMethod[UploadFileResponse]):
10
+ __api_method__ = "uploadFile"
11
+ __returning__ = UploadFileResponse
12
+
13
+ file_size: int
14
+
15
+ def __post_init__(self):
16
+ super().__init__()
17
+
18
+ def payload(self):
19
+ return {
20
+ "fileSize": self.file_size,
21
+ }
trueconf/py.typed ADDED
File without changes
@@ -0,0 +1,25 @@
1
+ from .message import Message
2
+ from .requests.added_chat_participant import AddedChatParticipant
3
+ from .requests.created_channel import CreatedChannel
4
+ from .requests.created_group_chat import CreatedGroupChat
5
+ from .requests.created_personal_chat import CreatedPersonalChat
6
+ from .requests.edited_message import EditedMessage
7
+ from .requests.removed_chat import RemovedChat
8
+ from .requests.removed_chat_participant import RemovedChatParticipant
9
+ from .requests.removed_message import RemovedMessage
10
+ from .requests.uploading_progress import UploadingProgress
11
+ from .update import Update
12
+
13
+ __all__ = [
14
+ "AddedChatParticipant",
15
+ "CreatedChannel",
16
+ "CreatedGroupChat",
17
+ "CreatedPersonalChat",
18
+ "EditedMessage",
19
+ "Message",
20
+ "RemovedChat",
21
+ "RemovedChatParticipant",
22
+ "RemovedMessage",
23
+ "Update",
24
+ "UploadingProgress",
25
+ ]
@@ -0,0 +1,17 @@
1
+ from __future__ import annotations
2
+ from dataclasses import dataclass
3
+ from mashumaro import DataClassDictMixin
4
+
5
+ from trueconf.enums.envelope_author_type import EnvelopeAuthorType
6
+
7
+
8
+ @dataclass
9
+ class EnvelopeAuthor(DataClassDictMixin):
10
+ id: str
11
+ type: EnvelopeAuthorType
12
+
13
+
14
+ @dataclass
15
+ class EnvelopeBox(DataClassDictMixin):
16
+ id: int
17
+ position: str
@@ -0,0 +1,11 @@
1
+ from __future__ import annotations
2
+ from dataclasses import dataclass, field
3
+ from mashumaro import DataClassDictMixin
4
+
5
+ from trueconf.enums.chat_participant_role import ChatParticipantRole
6
+
7
+
8
+ @dataclass
9
+ class ChatParticipant(DataClassDictMixin):
10
+ user_id: str = field(metadata={"alias": "id"})
11
+ role: ChatParticipantRole
@@ -0,0 +1,25 @@
1
+ from .survey import SurveyContent
2
+ from .chat_created import ParticipantRoleContent
3
+ from .forward_message import ForwardMessage
4
+ from .attachment import AttachmentContent
5
+ from .remove_participant import RemoveParticipant
6
+ from .text import TextContent
7
+ from .base import AbstractEnvelopeContent
8
+ from .photo import Photo
9
+ from .video import Video
10
+ from .sticker import Sticker
11
+ from .document import Document
12
+
13
+ __all__ = [
14
+ 'SurveyContent',
15
+ 'ParticipantRoleContent',
16
+ 'ForwardMessage',
17
+ 'AttachmentContent',
18
+ 'RemoveParticipant',
19
+ 'TextContent',
20
+ 'AbstractEnvelopeContent',
21
+ 'Photo',
22
+ 'Video',
23
+ 'Sticker',
24
+ 'Document',
25
+ ]
@@ -0,0 +1,14 @@
1
+ from __future__ import annotations
2
+ from dataclasses import dataclass, field
3
+ from typing import Optional
4
+ from trueconf.client.context_controller import BoundToBot
5
+ from trueconf.types.content.base import AbstractEnvelopeContent
6
+
7
+
8
+ @dataclass
9
+ class AttachmentContent(BoundToBot, AbstractEnvelopeContent):
10
+ file_name: str = field(metadata={"alias": "name"})
11
+ file_size: int = field(metadata={"alias": "size"})
12
+ file_id: str = field(default="", metadata={"alias": "fileId"})
13
+ mimetype: str = field(default="", metadata={"alias": "mimeType"})
14
+ ready_state: Optional[int] = field(default=None, metadata={"alias": "readyState"})
@@ -0,0 +1,8 @@
1
+ from __future__ import annotations
2
+ from abc import ABC
3
+ from mashumaro import DataClassDictMixin
4
+
5
+
6
+ class AbstractEnvelopeContent(DataClassDictMixin, ABC):
7
+ """Маркерный базовый класс."""
8
+ pass
@@ -0,0 +1,9 @@
1
+ from __future__ import annotations
2
+ from dataclasses import dataclass, field
3
+ from trueconf.types.content.base import AbstractEnvelopeContent
4
+
5
+
6
+ @dataclass
7
+ class ParticipantRoleContent(AbstractEnvelopeContent):
8
+ user_id: str = field(metadata={"alias": "userId"})
9
+ role: str
@@ -0,0 +1,71 @@
1
+ from __future__ import annotations
2
+ from dataclasses import dataclass
3
+ from trueconf.client.context_controller import BoundToBot
4
+ from pathlib import Path
5
+
6
+
7
+ @dataclass
8
+ class Document(BoundToBot):
9
+ """
10
+ Represents a file attached to a message.
11
+
12
+ This class provides access to file metadata and utility methods such as downloading and preview access.
13
+
14
+ Attributes:
15
+ file_id (str): Unique identifier of the file.
16
+ file_name (str): Name of the file as stored on the server.
17
+ file_size (int): Size of the file in bytes.
18
+ mimetype (str): MIME type of the file.
19
+ """
20
+
21
+ file_id: str
22
+ file_name: str
23
+ file_size: int
24
+ mimetype: str
25
+
26
+ @property
27
+ async def url(self) -> str:
28
+ """
29
+ Returns the direct download URL of the file.
30
+
31
+ Source: https://trueconf.com/docs/chatbot-connector/en/files/#retrieving-file-information-and-downloading-the-file
32
+
33
+ Returns:
34
+ str: A URL pointing to the original video file.
35
+ """
36
+
37
+ r = await self.bot.get_file_info(self.file_id)
38
+ return r.download_url
39
+
40
+ @property
41
+ async def preview_url(self) -> str:
42
+ """
43
+ Returns the preview URL of the file, if available.
44
+
45
+ Source: https://trueconf.com/docs/chatbot-connector/en/files/#retrieving-file-information-and-downloading-the-file
46
+
47
+ Returns:
48
+ str: A URL pointing to the preview version of the video file.
49
+ """
50
+
51
+ r = await self.bot.get_file_info(self.file_id)
52
+ return r.preview.download_url
53
+
54
+ async def download(self, dest_path: str) -> Path | None:
55
+ """
56
+ Shortcut for the `download_file_by_id` method of the bot instance.
57
+
58
+ Automatically fills the following attributes:
59
+ - `file_id`
60
+
61
+ Use this method to download the current file by its ID.
62
+
63
+ Args:
64
+ dest_path (str): Destination path to save the file.
65
+ If not specified, a temporary file will be created using
66
+ `NamedTemporaryFile(prefix="tc_dl_", suffix=file_name, delete=False)`.
67
+
68
+ Returns:
69
+ Path | None: Path to the downloaded file, or None if the download failed.
70
+ """
71
+ return await self.bot.download_file_by_id(file_id=self.file_id, dest_path=dest_path)
@@ -0,0 +1,21 @@
1
+ from __future__ import annotations
2
+ from dataclasses import dataclass, field
3
+ from typing import Optional, Union
4
+ from trueconf.enums.message_type import MessageType
5
+ from trueconf.types.content.base import AbstractEnvelopeContent
6
+ from trueconf.types.author_box import EnvelopeAuthor, EnvelopeBox
7
+ from trueconf.types.content.attachment import AttachmentContent
8
+ from trueconf.types.content.survey import SurveyContent
9
+ from trueconf.types.content.text import TextContent
10
+
11
+
12
+ @dataclass
13
+ class ForwardMessage(AbstractEnvelopeContent):
14
+ timestamp: int
15
+ type: MessageType
16
+ author: EnvelopeAuthor
17
+ content: Union[TextContent, AttachmentContent, SurveyContent]
18
+ message_id: str = field(metadata={"alias": "messageId"})
19
+ chat_id: str = field(metadata={"alias": "chatId"})
20
+ is_edited: Optional[bool] = field(metadata={"alias": "isEdited"})
21
+ box: Optional[EnvelopeBox]
@@ -0,0 +1,70 @@
1
+ from __future__ import annotations
2
+ from dataclasses import dataclass
3
+ from trueconf.client.context_controller import BoundToBot
4
+ from pathlib import Path
5
+
6
+ @dataclass
7
+ class Photo(BoundToBot):
8
+ """
9
+ Represents an image file attached to a message.
10
+
11
+ This class provides access to file metadata and utility methods such as downloading and preview access.
12
+
13
+ Attributes:
14
+ file_id (str): Unique identifier of the image file.
15
+ file_name (str): Name of the file as stored on the server.
16
+ file_size (int): Size of the file in bytes.
17
+ mimetype (str): MIME type of the image.
18
+ """
19
+
20
+ file_id: str
21
+ file_name: str
22
+ file_size: int
23
+ mimetype: str
24
+
25
+ @property
26
+ async def url(self) -> str:
27
+ """
28
+ Returns the direct download URL of the image file.
29
+
30
+ Source: https://trueconf.com/docs/chatbot-connector/en/files/#retrieving-file-information-and-downloading-the-file
31
+
32
+ Returns:
33
+ str: A URL pointing to the original image file.
34
+ """
35
+
36
+ r = await self.bot.get_file_info(self.file_id)
37
+ return r.download_url
38
+
39
+ @property
40
+ async def preview_url(self) -> str:
41
+ """
42
+ Returns the preview URL of the image file, if available.
43
+
44
+ Source: https://trueconf.com/docs/chatbot-connector/en/files/#retrieving-file-information-and-downloading-the-file
45
+
46
+ Returns:
47
+ str: A URL pointing to the preview version of the image file.
48
+ """
49
+
50
+ r = await self.bot.get_file_info(self.file_id)
51
+ return r.preview.download_url
52
+
53
+ async def download(self, dest_path: str) -> Path | None:
54
+ """
55
+ Shortcut for the `download_file_by_id` method of the bot instance.
56
+
57
+ Automatically fills the following attributes:
58
+ - `file_id`
59
+
60
+ Use this method to download the current file by its ID.
61
+
62
+ Args:
63
+ dest_path (str): Destination path to save the file.
64
+ If not specified, a temporary file will be created using
65
+ `NamedTemporaryFile(prefix="tc_dl_", suffix=file_name, delete=False)`.
66
+
67
+ Returns:
68
+ Path | None: Path to the downloaded file, or None if the download failed.
69
+ """
70
+ return await self.bot.download_file_by_id(file_id=self.file_id, dest_path=dest_path)
@@ -0,0 +1,9 @@
1
+ from __future__ import annotations
2
+ from dataclasses import dataclass, field
3
+
4
+ from trueconf.types.content.base import AbstractEnvelopeContent
5
+
6
+
7
+ @dataclass
8
+ class RemoveParticipant(AbstractEnvelopeContent):
9
+ user_id: str = field(metadata={"alias": "userId"})
@@ -0,0 +1,70 @@
1
+ from __future__ import annotations
2
+ from dataclasses import dataclass
3
+ from trueconf.client.context_controller import BoundToBot
4
+ from pathlib import Path
5
+
6
+ @dataclass
7
+ class Sticker(BoundToBot):
8
+ """
9
+ Represents a sticker file attached to a message.
10
+
11
+ This class provides access to file metadata and utility methods such as downloading and preview access.
12
+
13
+ Attributes:
14
+ file_id (str): Unique identifier of the sticker file.
15
+ file_name (str): Name of the file as stored on the server.
16
+ file_size (int): Size of the file in bytes.
17
+ mimetype (str): MIME type of the sticker.
18
+ """
19
+
20
+ file_id: str
21
+ file_name: str
22
+ file_size: int
23
+ mimetype: str
24
+
25
+ @property
26
+ async def url(self) -> str:
27
+ """
28
+ Returns the direct download URL of the sticker file.
29
+
30
+ Source: https://trueconf.com/docs/chatbot-connector/en/files/#retrieving-file-information-and-downloading-the-file
31
+
32
+ Returns:
33
+ str: A URL pointing to the original sticker file.
34
+ """
35
+
36
+ r = await self.bot.get_file_info(self.file_id)
37
+ return r.download_url
38
+
39
+ @property
40
+ async def preview_url(self) -> str:
41
+ """
42
+ Returns the preview URL of the sticker file, if available.
43
+
44
+ Source: https://trueconf.com/docs/chatbot-connector/en/files/#retrieving-file-information-and-downloading-the-file
45
+
46
+ Returns:
47
+ str: A URL pointing to the preview version of the sticker file.
48
+ """
49
+
50
+ r = await self.bot.get_file_info(self.file_id)
51
+ return r.preview.download_url
52
+
53
+ async def download(self, dest_path: str) -> Path | None:
54
+ """
55
+ Shortcut for the `download_file_by_id` method of the bot instance.
56
+
57
+ Automatically fills the following attributes:
58
+ - `file_id`
59
+
60
+ Use this method to download the current file by its ID.
61
+
62
+ Args:
63
+ dest_path (str): Destination path to save the file.
64
+ If not specified, a temporary file will be created using
65
+ `NamedTemporaryFile(prefix="tc_dl_", suffix=file_name, delete=False)`.
66
+
67
+ Returns:
68
+ Path | None: Path to the downloaded file, or None if the download failed.
69
+ """
70
+ return await self.bot.download_file_by_id(file_id=self.file_id, dest_path=dest_path)
@@ -0,0 +1,19 @@
1
+ from __future__ import annotations
2
+ from dataclasses import dataclass, field
3
+ from typing import Optional
4
+ from mashumaro import DataClassDictMixin
5
+ from trueconf.types.content.base import AbstractEnvelopeContent
6
+
7
+
8
+ @dataclass
9
+ class SurveyContent(AbstractEnvelopeContent, DataClassDictMixin):
10
+ url: str
11
+ title: str
12
+ path: Optional[str] = None
13
+ description: Optional[str] = None
14
+ button_text: Optional[str] = field(default=None, metadata={"alias": "buttonText"})
15
+ app_version: Optional[int] = field(
16
+ default=None, metadata={"alias": "appVersion"}
17
+ )
18
+ secret: Optional[str] = None
19
+ alt: Optional[str] = None
@@ -0,0 +1,9 @@
1
+ from __future__ import annotations
2
+ from dataclasses import dataclass, field
3
+ from trueconf.types.content.base import AbstractEnvelopeContent
4
+
5
+
6
+ @dataclass
7
+ class TextContent(AbstractEnvelopeContent):
8
+ text: str
9
+ parse_mode: str = field(metadata={"alias": "parseMode"})
@@ -0,0 +1,71 @@
1
+ from __future__ import annotations
2
+ from dataclasses import dataclass
3
+ from trueconf.client.context_controller import BoundToBot
4
+ from pathlib import Path
5
+
6
+ @dataclass
7
+ class Video(BoundToBot):
8
+ """
9
+ Represents a video file attached to a message.
10
+
11
+ This class provides access to file metadata and utility methods such as downloading and preview access.
12
+
13
+ Attributes:
14
+ file_id (str): Unique identifier of the video file.
15
+ file_name (str): Name of the file as stored on the server.
16
+ file_size (int): Size of the file in bytes.
17
+ mimetype (str): MIME type of the video.
18
+ """
19
+
20
+ file_id: str
21
+ file_name: str
22
+ file_size: int
23
+ mimetype: str
24
+
25
+ @property
26
+ async def url(self) -> str:
27
+ """
28
+ Returns the direct download URL of the video file.
29
+
30
+ Source: https://trueconf.com/docs/chatbot-connector/en/files/#retrieving-file-information-and-downloading-the-file
31
+
32
+ Returns:
33
+ str: A URL pointing to the original video file.
34
+ """
35
+
36
+ r = await self.bot.get_file_info(self.file_id)
37
+ return r.download_url
38
+
39
+ @property
40
+ async def preview_url(self) -> str:
41
+ """
42
+ Returns the preview URL of the video file, if available.
43
+
44
+ Source: https://trueconf.com/docs/chatbot-connector/en/files/#retrieving-file-information-and-downloading-the-file
45
+
46
+ Returns:
47
+ str: A URL pointing to the preview version of the video file.
48
+ """
49
+
50
+ r = await self.bot.get_file_info(self.file_id)
51
+ return r.preview.download_url
52
+
53
+ async def download(self, dest_path: str) -> Path | None:
54
+ """
55
+ Shortcut for the `download_file_by_id` method of the bot instance.
56
+
57
+ Automatically fills the following attributes:
58
+ - `file_id`
59
+
60
+ Use this method to download the current file by its ID.
61
+
62
+ Args:
63
+ dest_path (str): Destination path to save the file.
64
+ If not specified, a temporary file will be created using
65
+ `NamedTemporaryFile(prefix="tc_dl_", suffix=file_name, delete=False)`.
66
+
67
+ Returns:
68
+ Path | None: Path to the downloaded file, or None if the download failed.
69
+ """
70
+ return await self.bot.download_file_by_id(file_id=self.file_id, dest_path=dest_path)
71
+
@@ -0,0 +1,33 @@
1
+ from __future__ import annotations
2
+ from dataclasses import dataclass, field
3
+ from typing import Optional, Union
4
+ from mashumaro import DataClassDictMixin
5
+ from trueconf.enums.message_type import MessageType
6
+ from trueconf.types.author_box import EnvelopeAuthor
7
+ from trueconf.types.content.text import TextContent
8
+ from trueconf.types.content.attachment import AttachmentContent
9
+ from trueconf.types.content.survey import SurveyContent
10
+ from trueconf.types.content.remove_participant import RemoveParticipant
11
+ from trueconf.types.content.forward_message import ForwardMessage
12
+ from trueconf.types.content.chat_created import ParticipantRoleContent
13
+
14
+
15
+ @dataclass
16
+ class LastMessage(DataClassDictMixin):
17
+ message_id: str = field(metadata={"alias": "messageId"})
18
+ timestamp: int
19
+ author: EnvelopeAuthor
20
+ type: MessageType
21
+ content: Union[TextContent, AttachmentContent, SurveyContent, ParticipantRoleContent, RemoveParticipant, ForwardMessage]
22
+
23
+ @property
24
+ def content_type(self) -> MessageType:
25
+ return self.type
26
+
27
+ @property
28
+ def text(self) -> Optional[str]:
29
+ return self.content.text if isinstance(self.content, TextContent) else None
30
+
31
+ @property
32
+ def file(self) -> Optional[AttachmentContent]:
33
+ return self.content if isinstance(self.content, AttachmentContent) else None