wappa 0.1.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.
Potentially problematic release.
This version of wappa might be problematic. Click here for more details.
- wappa/__init__.py +85 -0
- wappa/api/__init__.py +1 -0
- wappa/api/controllers/__init__.py +10 -0
- wappa/api/controllers/webhook_controller.py +441 -0
- wappa/api/dependencies/__init__.py +15 -0
- wappa/api/dependencies/whatsapp_dependencies.py +220 -0
- wappa/api/dependencies/whatsapp_media_dependencies.py +26 -0
- wappa/api/middleware/__init__.py +7 -0
- wappa/api/middleware/error_handler.py +158 -0
- wappa/api/middleware/owner.py +99 -0
- wappa/api/middleware/request_logging.py +184 -0
- wappa/api/routes/__init__.py +6 -0
- wappa/api/routes/health.py +102 -0
- wappa/api/routes/webhooks.py +211 -0
- wappa/api/routes/whatsapp/__init__.py +15 -0
- wappa/api/routes/whatsapp/whatsapp_interactive.py +429 -0
- wappa/api/routes/whatsapp/whatsapp_media.py +440 -0
- wappa/api/routes/whatsapp/whatsapp_messages.py +195 -0
- wappa/api/routes/whatsapp/whatsapp_specialized.py +516 -0
- wappa/api/routes/whatsapp/whatsapp_templates.py +431 -0
- wappa/api/routes/whatsapp_combined.py +35 -0
- wappa/cli/__init__.py +9 -0
- wappa/cli/main.py +199 -0
- wappa/core/__init__.py +6 -0
- wappa/core/config/__init__.py +5 -0
- wappa/core/config/settings.py +161 -0
- wappa/core/events/__init__.py +41 -0
- wappa/core/events/default_handlers.py +642 -0
- wappa/core/events/event_dispatcher.py +244 -0
- wappa/core/events/event_handler.py +247 -0
- wappa/core/events/webhook_factory.py +219 -0
- wappa/core/factory/__init__.py +15 -0
- wappa/core/factory/plugin.py +68 -0
- wappa/core/factory/wappa_builder.py +326 -0
- wappa/core/logging/__init__.py +5 -0
- wappa/core/logging/context.py +100 -0
- wappa/core/logging/logger.py +343 -0
- wappa/core/plugins/__init__.py +34 -0
- wappa/core/plugins/auth_plugin.py +169 -0
- wappa/core/plugins/cors_plugin.py +128 -0
- wappa/core/plugins/custom_middleware_plugin.py +182 -0
- wappa/core/plugins/database_plugin.py +235 -0
- wappa/core/plugins/rate_limit_plugin.py +183 -0
- wappa/core/plugins/redis_plugin.py +224 -0
- wappa/core/plugins/wappa_core_plugin.py +261 -0
- wappa/core/plugins/webhook_plugin.py +253 -0
- wappa/core/types.py +108 -0
- wappa/core/wappa_app.py +546 -0
- wappa/database/__init__.py +18 -0
- wappa/database/adapter.py +107 -0
- wappa/database/adapters/__init__.py +17 -0
- wappa/database/adapters/mysql_adapter.py +187 -0
- wappa/database/adapters/postgresql_adapter.py +169 -0
- wappa/database/adapters/sqlite_adapter.py +174 -0
- wappa/domain/__init__.py +28 -0
- wappa/domain/builders/__init__.py +5 -0
- wappa/domain/builders/message_builder.py +189 -0
- wappa/domain/entities/__init__.py +5 -0
- wappa/domain/enums/messenger_platform.py +123 -0
- wappa/domain/factories/__init__.py +6 -0
- wappa/domain/factories/media_factory.py +450 -0
- wappa/domain/factories/message_factory.py +497 -0
- wappa/domain/factories/messenger_factory.py +244 -0
- wappa/domain/interfaces/__init__.py +32 -0
- wappa/domain/interfaces/base_repository.py +94 -0
- wappa/domain/interfaces/cache_factory.py +85 -0
- wappa/domain/interfaces/cache_interface.py +199 -0
- wappa/domain/interfaces/expiry_repository.py +68 -0
- wappa/domain/interfaces/media_interface.py +311 -0
- wappa/domain/interfaces/messaging_interface.py +523 -0
- wappa/domain/interfaces/pubsub_repository.py +151 -0
- wappa/domain/interfaces/repository_factory.py +108 -0
- wappa/domain/interfaces/shared_state_repository.py +122 -0
- wappa/domain/interfaces/state_repository.py +123 -0
- wappa/domain/interfaces/tables_repository.py +215 -0
- wappa/domain/interfaces/user_repository.py +114 -0
- wappa/domain/interfaces/webhooks/__init__.py +1 -0
- wappa/domain/models/media_result.py +110 -0
- wappa/domain/models/platforms/__init__.py +15 -0
- wappa/domain/models/platforms/platform_config.py +104 -0
- wappa/domain/services/__init__.py +11 -0
- wappa/domain/services/tenant_credentials_service.py +56 -0
- wappa/messaging/__init__.py +7 -0
- wappa/messaging/whatsapp/__init__.py +1 -0
- wappa/messaging/whatsapp/client/__init__.py +5 -0
- wappa/messaging/whatsapp/client/whatsapp_client.py +417 -0
- wappa/messaging/whatsapp/handlers/__init__.py +13 -0
- wappa/messaging/whatsapp/handlers/whatsapp_interactive_handler.py +653 -0
- wappa/messaging/whatsapp/handlers/whatsapp_media_handler.py +579 -0
- wappa/messaging/whatsapp/handlers/whatsapp_specialized_handler.py +434 -0
- wappa/messaging/whatsapp/handlers/whatsapp_template_handler.py +416 -0
- wappa/messaging/whatsapp/messenger/__init__.py +5 -0
- wappa/messaging/whatsapp/messenger/whatsapp_messenger.py +904 -0
- wappa/messaging/whatsapp/models/__init__.py +61 -0
- wappa/messaging/whatsapp/models/basic_models.py +65 -0
- wappa/messaging/whatsapp/models/interactive_models.py +287 -0
- wappa/messaging/whatsapp/models/media_models.py +215 -0
- wappa/messaging/whatsapp/models/specialized_models.py +304 -0
- wappa/messaging/whatsapp/models/template_models.py +261 -0
- wappa/persistence/cache_factory.py +93 -0
- wappa/persistence/json/__init__.py +14 -0
- wappa/persistence/json/cache_adapters.py +271 -0
- wappa/persistence/json/handlers/__init__.py +1 -0
- wappa/persistence/json/handlers/state_handler.py +250 -0
- wappa/persistence/json/handlers/table_handler.py +263 -0
- wappa/persistence/json/handlers/user_handler.py +213 -0
- wappa/persistence/json/handlers/utils/__init__.py +1 -0
- wappa/persistence/json/handlers/utils/file_manager.py +153 -0
- wappa/persistence/json/handlers/utils/key_factory.py +11 -0
- wappa/persistence/json/handlers/utils/serialization.py +121 -0
- wappa/persistence/json/json_cache_factory.py +76 -0
- wappa/persistence/json/storage_manager.py +285 -0
- wappa/persistence/memory/__init__.py +14 -0
- wappa/persistence/memory/cache_adapters.py +271 -0
- wappa/persistence/memory/handlers/__init__.py +1 -0
- wappa/persistence/memory/handlers/state_handler.py +250 -0
- wappa/persistence/memory/handlers/table_handler.py +280 -0
- wappa/persistence/memory/handlers/user_handler.py +213 -0
- wappa/persistence/memory/handlers/utils/__init__.py +1 -0
- wappa/persistence/memory/handlers/utils/key_factory.py +11 -0
- wappa/persistence/memory/handlers/utils/memory_store.py +317 -0
- wappa/persistence/memory/handlers/utils/ttl_manager.py +235 -0
- wappa/persistence/memory/memory_cache_factory.py +76 -0
- wappa/persistence/memory/storage_manager.py +235 -0
- wappa/persistence/redis/README.md +699 -0
- wappa/persistence/redis/__init__.py +11 -0
- wappa/persistence/redis/cache_adapters.py +285 -0
- wappa/persistence/redis/ops.py +880 -0
- wappa/persistence/redis/redis_cache_factory.py +71 -0
- wappa/persistence/redis/redis_client.py +231 -0
- wappa/persistence/redis/redis_handler/__init__.py +26 -0
- wappa/persistence/redis/redis_handler/state_handler.py +176 -0
- wappa/persistence/redis/redis_handler/table.py +158 -0
- wappa/persistence/redis/redis_handler/user.py +138 -0
- wappa/persistence/redis/redis_handler/utils/__init__.py +12 -0
- wappa/persistence/redis/redis_handler/utils/key_factory.py +32 -0
- wappa/persistence/redis/redis_handler/utils/serde.py +146 -0
- wappa/persistence/redis/redis_handler/utils/tenant_cache.py +268 -0
- wappa/persistence/redis/redis_manager.py +189 -0
- wappa/processors/__init__.py +6 -0
- wappa/processors/base_processor.py +262 -0
- wappa/processors/factory.py +550 -0
- wappa/processors/whatsapp_processor.py +810 -0
- wappa/schemas/__init__.py +6 -0
- wappa/schemas/core/__init__.py +71 -0
- wappa/schemas/core/base_message.py +499 -0
- wappa/schemas/core/base_status.py +322 -0
- wappa/schemas/core/base_webhook.py +312 -0
- wappa/schemas/core/types.py +253 -0
- wappa/schemas/core/webhook_interfaces/__init__.py +48 -0
- wappa/schemas/core/webhook_interfaces/base_components.py +293 -0
- wappa/schemas/core/webhook_interfaces/universal_webhooks.py +348 -0
- wappa/schemas/factory.py +754 -0
- wappa/schemas/webhooks/__init__.py +3 -0
- wappa/schemas/whatsapp/__init__.py +6 -0
- wappa/schemas/whatsapp/base_models.py +285 -0
- wappa/schemas/whatsapp/message_types/__init__.py +93 -0
- wappa/schemas/whatsapp/message_types/audio.py +350 -0
- wappa/schemas/whatsapp/message_types/button.py +267 -0
- wappa/schemas/whatsapp/message_types/contact.py +464 -0
- wappa/schemas/whatsapp/message_types/document.py +421 -0
- wappa/schemas/whatsapp/message_types/errors.py +195 -0
- wappa/schemas/whatsapp/message_types/image.py +424 -0
- wappa/schemas/whatsapp/message_types/interactive.py +430 -0
- wappa/schemas/whatsapp/message_types/location.py +416 -0
- wappa/schemas/whatsapp/message_types/order.py +372 -0
- wappa/schemas/whatsapp/message_types/reaction.py +271 -0
- wappa/schemas/whatsapp/message_types/sticker.py +328 -0
- wappa/schemas/whatsapp/message_types/system.py +317 -0
- wappa/schemas/whatsapp/message_types/text.py +411 -0
- wappa/schemas/whatsapp/message_types/unsupported.py +273 -0
- wappa/schemas/whatsapp/message_types/video.py +344 -0
- wappa/schemas/whatsapp/status_models.py +479 -0
- wappa/schemas/whatsapp/validators.py +454 -0
- wappa/schemas/whatsapp/webhook_container.py +438 -0
- wappa/webhooks/__init__.py +17 -0
- wappa/webhooks/core/__init__.py +71 -0
- wappa/webhooks/core/base_message.py +499 -0
- wappa/webhooks/core/base_status.py +322 -0
- wappa/webhooks/core/base_webhook.py +312 -0
- wappa/webhooks/core/types.py +253 -0
- wappa/webhooks/core/webhook_interfaces/__init__.py +48 -0
- wappa/webhooks/core/webhook_interfaces/base_components.py +293 -0
- wappa/webhooks/core/webhook_interfaces/universal_webhooks.py +441 -0
- wappa/webhooks/factory.py +754 -0
- wappa/webhooks/whatsapp/__init__.py +6 -0
- wappa/webhooks/whatsapp/base_models.py +285 -0
- wappa/webhooks/whatsapp/message_types/__init__.py +93 -0
- wappa/webhooks/whatsapp/message_types/audio.py +350 -0
- wappa/webhooks/whatsapp/message_types/button.py +267 -0
- wappa/webhooks/whatsapp/message_types/contact.py +464 -0
- wappa/webhooks/whatsapp/message_types/document.py +421 -0
- wappa/webhooks/whatsapp/message_types/errors.py +195 -0
- wappa/webhooks/whatsapp/message_types/image.py +424 -0
- wappa/webhooks/whatsapp/message_types/interactive.py +430 -0
- wappa/webhooks/whatsapp/message_types/location.py +416 -0
- wappa/webhooks/whatsapp/message_types/order.py +372 -0
- wappa/webhooks/whatsapp/message_types/reaction.py +271 -0
- wappa/webhooks/whatsapp/message_types/sticker.py +328 -0
- wappa/webhooks/whatsapp/message_types/system.py +317 -0
- wappa/webhooks/whatsapp/message_types/text.py +411 -0
- wappa/webhooks/whatsapp/message_types/unsupported.py +273 -0
- wappa/webhooks/whatsapp/message_types/video.py +344 -0
- wappa/webhooks/whatsapp/status_models.py +479 -0
- wappa/webhooks/whatsapp/validators.py +454 -0
- wappa/webhooks/whatsapp/webhook_container.py +438 -0
- wappa-0.1.0.dist-info/METADATA +269 -0
- wappa-0.1.0.dist-info/RECORD +211 -0
- wappa-0.1.0.dist-info/WHEEL +4 -0
- wappa-0.1.0.dist-info/entry_points.txt +2 -0
- wappa-0.1.0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Message builder pattern for creating complex messages with validation.
|
|
3
|
+
|
|
4
|
+
Provides a fluent interface for constructing messages while ensuring platform
|
|
5
|
+
compatibility and validation.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from typing import Any, Self
|
|
9
|
+
|
|
10
|
+
from wappa.domain.factories.message_factory import MessageFactory
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class MessageBuilder:
|
|
14
|
+
"""
|
|
15
|
+
Fluent builder for creating messages with validation.
|
|
16
|
+
|
|
17
|
+
Provides a chainable interface for constructing messages while
|
|
18
|
+
ensuring platform compatibility and validation.
|
|
19
|
+
|
|
20
|
+
Currently supports basic messaging operations. Future implementations will add:
|
|
21
|
+
- Button builder for interactive button messages
|
|
22
|
+
- List builder for interactive list messages
|
|
23
|
+
- Template builder for template messages
|
|
24
|
+
- Media builder for media messages
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def __init__(self, factory: MessageFactory, recipient: str):
|
|
28
|
+
"""Initialize message builder.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
factory: Message factory for creating platform-specific payloads
|
|
32
|
+
recipient: Recipient identifier for the message
|
|
33
|
+
"""
|
|
34
|
+
self._factory = factory
|
|
35
|
+
self._recipient = recipient
|
|
36
|
+
self._message_data: dict[str, Any] = {}
|
|
37
|
+
self._message_type: str | None = None
|
|
38
|
+
|
|
39
|
+
def text(self, content: str) -> Self:
|
|
40
|
+
"""Set text content for the message.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
content: Text content of the message
|
|
44
|
+
|
|
45
|
+
Returns:
|
|
46
|
+
Self for method chaining
|
|
47
|
+
"""
|
|
48
|
+
self._message_data["text"] = content
|
|
49
|
+
self._message_type = "text"
|
|
50
|
+
return self
|
|
51
|
+
|
|
52
|
+
def reply_to(self, message_id: str) -> Self:
|
|
53
|
+
"""Set reply-to message ID.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
message_id: Message ID to reply to (creates a thread)
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
Self for method chaining
|
|
60
|
+
"""
|
|
61
|
+
self._message_data["reply_to_message_id"] = message_id
|
|
62
|
+
return self
|
|
63
|
+
|
|
64
|
+
def disable_preview(self) -> Self:
|
|
65
|
+
"""Disable URL preview for links in the message.
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
Self for method chaining
|
|
69
|
+
"""
|
|
70
|
+
self._message_data["disable_preview"] = True
|
|
71
|
+
return self
|
|
72
|
+
|
|
73
|
+
def enable_preview(self) -> Self:
|
|
74
|
+
"""Enable URL preview for links in the message (default behavior).
|
|
75
|
+
|
|
76
|
+
Returns:
|
|
77
|
+
Self for method chaining
|
|
78
|
+
"""
|
|
79
|
+
self._message_data["disable_preview"] = False
|
|
80
|
+
return self
|
|
81
|
+
|
|
82
|
+
def read_status(self, message_id: str, typing: bool = False) -> Self:
|
|
83
|
+
"""Set read status parameters.
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
message_id: Message ID to mark as read
|
|
87
|
+
typing: Whether to show typing indicator
|
|
88
|
+
|
|
89
|
+
Returns:
|
|
90
|
+
Self for method chaining
|
|
91
|
+
"""
|
|
92
|
+
self._message_data["message_id"] = message_id
|
|
93
|
+
self._message_data["typing"] = typing
|
|
94
|
+
self._message_type = "read_status"
|
|
95
|
+
return self
|
|
96
|
+
|
|
97
|
+
def build(self) -> dict[str, Any]:
|
|
98
|
+
"""Build the message payload.
|
|
99
|
+
|
|
100
|
+
Creates the final message payload using the configured factory
|
|
101
|
+
and validates it before returning.
|
|
102
|
+
|
|
103
|
+
Returns:
|
|
104
|
+
Platform-specific message payload
|
|
105
|
+
|
|
106
|
+
Raises:
|
|
107
|
+
ValueError: If message type is not set or required data is missing
|
|
108
|
+
RuntimeError: If message validation fails
|
|
109
|
+
"""
|
|
110
|
+
if self._message_type == "text":
|
|
111
|
+
if "text" not in self._message_data:
|
|
112
|
+
raise ValueError("Text content is required for text messages")
|
|
113
|
+
|
|
114
|
+
payload = self._factory.create_text_message(
|
|
115
|
+
text=self._message_data["text"],
|
|
116
|
+
recipient=self._recipient,
|
|
117
|
+
reply_to_message_id=self._message_data.get("reply_to_message_id"),
|
|
118
|
+
disable_preview=self._message_data.get("disable_preview", False),
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
elif self._message_type == "read_status":
|
|
122
|
+
if "message_id" not in self._message_data:
|
|
123
|
+
raise ValueError("Message ID is required for read status messages")
|
|
124
|
+
|
|
125
|
+
payload = self._factory.create_read_status_message(
|
|
126
|
+
message_id=self._message_data["message_id"],
|
|
127
|
+
typing=self._message_data.get("typing", False),
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
else:
|
|
131
|
+
raise ValueError(f"Unsupported message type: {self._message_type}")
|
|
132
|
+
|
|
133
|
+
# Validate the built payload
|
|
134
|
+
if not self._factory.validate_message(payload):
|
|
135
|
+
raise RuntimeError("Built message payload failed validation")
|
|
136
|
+
|
|
137
|
+
return payload
|
|
138
|
+
|
|
139
|
+
def validate(self) -> bool:
|
|
140
|
+
"""Validate the current message configuration without building.
|
|
141
|
+
|
|
142
|
+
Returns:
|
|
143
|
+
True if current configuration is valid, False otherwise
|
|
144
|
+
"""
|
|
145
|
+
try:
|
|
146
|
+
self.build()
|
|
147
|
+
return True
|
|
148
|
+
except (ValueError, RuntimeError):
|
|
149
|
+
return False
|
|
150
|
+
|
|
151
|
+
def get_limits(self) -> dict[str, Any]:
|
|
152
|
+
"""Get platform-specific message limits.
|
|
153
|
+
|
|
154
|
+
Returns:
|
|
155
|
+
Dictionary containing platform limits for validation
|
|
156
|
+
"""
|
|
157
|
+
return self._factory.get_message_limits()
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
# Usage example functions for documentation
|
|
161
|
+
def create_text_message_example(
|
|
162
|
+
factory: MessageFactory, recipient: str, text: str
|
|
163
|
+
) -> dict[str, Any]:
|
|
164
|
+
"""Example: Create a simple text message."""
|
|
165
|
+
return MessageBuilder(factory, recipient).text(text).build()
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def create_reply_message_example(
|
|
169
|
+
factory: MessageFactory, recipient: str, text: str, reply_to: str
|
|
170
|
+
) -> dict[str, Any]:
|
|
171
|
+
"""Example: Create a reply message with URL preview disabled."""
|
|
172
|
+
return (
|
|
173
|
+
MessageBuilder(factory, recipient)
|
|
174
|
+
.text(text)
|
|
175
|
+
.reply_to(reply_to)
|
|
176
|
+
.disable_preview()
|
|
177
|
+
.build()
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def create_read_status_example(
|
|
182
|
+
factory: MessageFactory, message_id: str, with_typing: bool = False
|
|
183
|
+
) -> dict[str, Any]:
|
|
184
|
+
"""Example: Create a read status message with optional typing."""
|
|
185
|
+
return (
|
|
186
|
+
MessageBuilder(factory, "") # recipient not needed for read status
|
|
187
|
+
.read_status(message_id, typing=with_typing)
|
|
188
|
+
.build()
|
|
189
|
+
)
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Messenger platform enum with dynamic platform validation.
|
|
3
|
+
|
|
4
|
+
Provides enum-based validation for messenger platforms based on
|
|
5
|
+
enabled platforms from application settings and integration with
|
|
6
|
+
existing PlatformType enum from core types.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from enum import Enum
|
|
10
|
+
|
|
11
|
+
from wappa.core.config.settings import settings
|
|
12
|
+
from wappa.schemas.core.types import PlatformType
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def create_messenger_platform_enum() -> type[Enum]:
|
|
16
|
+
"""
|
|
17
|
+
Create dynamic MessengerPlatformEnum based on enabled platforms.
|
|
18
|
+
|
|
19
|
+
This creates an enum with only the platforms that are actually
|
|
20
|
+
configured and enabled in the current environment, integrating
|
|
21
|
+
with the existing PlatformType enum.
|
|
22
|
+
|
|
23
|
+
Returns:
|
|
24
|
+
Enum class with enabled messenger platforms
|
|
25
|
+
"""
|
|
26
|
+
enabled_platforms = settings.enabled_messenger_platforms
|
|
27
|
+
|
|
28
|
+
if not enabled_platforms:
|
|
29
|
+
# Fallback enum if no platforms are enabled
|
|
30
|
+
class MessengerPlatformEnum(str, Enum):
|
|
31
|
+
"""No messenger platforms are currently enabled."""
|
|
32
|
+
|
|
33
|
+
pass
|
|
34
|
+
|
|
35
|
+
return MessengerPlatformEnum
|
|
36
|
+
|
|
37
|
+
# Create enum members dynamically based on enabled platforms
|
|
38
|
+
enum_members = {
|
|
39
|
+
platform_name.upper(): platform_name
|
|
40
|
+
for platform_name in enabled_platforms.keys()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
# Create the enum class
|
|
44
|
+
MessengerPlatformEnum = Enum("MessengerPlatformEnum", enum_members, type=str)
|
|
45
|
+
|
|
46
|
+
# Add custom methods to the enum class
|
|
47
|
+
def get_platform_names():
|
|
48
|
+
"""Get list of all enabled platform names."""
|
|
49
|
+
return list(enabled_platforms.keys())
|
|
50
|
+
|
|
51
|
+
def is_valid_platform(platform_name: str) -> bool:
|
|
52
|
+
"""Check if platform name is valid and enabled."""
|
|
53
|
+
return platform_name in enabled_platforms
|
|
54
|
+
|
|
55
|
+
def to_platform_type(platform_name: str) -> PlatformType:
|
|
56
|
+
"""Convert platform name to PlatformType enum."""
|
|
57
|
+
try:
|
|
58
|
+
return PlatformType(platform_name.lower())
|
|
59
|
+
except ValueError:
|
|
60
|
+
raise ValueError(
|
|
61
|
+
f"Platform '{platform_name}' is not supported by PlatformType enum"
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
# Add methods to the enum class
|
|
65
|
+
MessengerPlatformEnum.get_platform_names = staticmethod(get_platform_names)
|
|
66
|
+
MessengerPlatformEnum.is_valid_platform = staticmethod(is_valid_platform)
|
|
67
|
+
MessengerPlatformEnum.to_platform_type = staticmethod(to_platform_type)
|
|
68
|
+
|
|
69
|
+
return MessengerPlatformEnum
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# Create the enum instance that will be used throughout the application
|
|
73
|
+
MessengerPlatformEnum = create_messenger_platform_enum()
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def get_available_platforms() -> dict[str, str]:
|
|
77
|
+
"""
|
|
78
|
+
Get available messenger platforms with display names.
|
|
79
|
+
|
|
80
|
+
Returns:
|
|
81
|
+
Dict mapping platform names to display names
|
|
82
|
+
"""
|
|
83
|
+
platforms_config = settings.enabled_messenger_platforms
|
|
84
|
+
return {name: config.display_name for name, config in platforms_config.items()}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def validate_platform_name(platform: str) -> str:
|
|
88
|
+
"""
|
|
89
|
+
Validate platform name against enabled platforms.
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
platform: Platform name to validate
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
Validated platform name
|
|
96
|
+
|
|
97
|
+
Raises:
|
|
98
|
+
ValueError: If platform is not enabled or configured
|
|
99
|
+
"""
|
|
100
|
+
if not MessengerPlatformEnum.is_valid_platform(platform):
|
|
101
|
+
available = MessengerPlatformEnum.get_platform_names()
|
|
102
|
+
raise ValueError(
|
|
103
|
+
f"Platform '{platform}' is not enabled. "
|
|
104
|
+
f"Available platforms: {', '.join(available)}"
|
|
105
|
+
)
|
|
106
|
+
return platform
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def get_platform_type(platform_name: str) -> PlatformType:
|
|
110
|
+
"""
|
|
111
|
+
Get PlatformType enum value for a platform name.
|
|
112
|
+
|
|
113
|
+
Args:
|
|
114
|
+
platform_name: Platform name to convert
|
|
115
|
+
|
|
116
|
+
Returns:
|
|
117
|
+
PlatformType enum value
|
|
118
|
+
|
|
119
|
+
Raises:
|
|
120
|
+
ValueError: If platform is not valid or supported
|
|
121
|
+
"""
|
|
122
|
+
validated_platform = validate_platform_name(platform_name)
|
|
123
|
+
return MessengerPlatformEnum.to_platform_type(validated_platform)
|