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,161 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Settings for the Wappa WhatsApp framework.
|
|
3
|
+
|
|
4
|
+
Simple, reliable environment variable configuration focused on core WhatsApp functionality.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import os
|
|
8
|
+
import tomllib
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
from dotenv import load_dotenv
|
|
12
|
+
|
|
13
|
+
# Load .env file for local development - look in current working directory
|
|
14
|
+
load_dotenv(".env")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _get_version_from_pyproject() -> str:
|
|
18
|
+
"""
|
|
19
|
+
Read version from pyproject.toml file.
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
Version string from pyproject.toml, or fallback version
|
|
23
|
+
"""
|
|
24
|
+
# Look for pyproject.toml in the project root
|
|
25
|
+
# Start from this file and go up to find the project root
|
|
26
|
+
current_path = Path(__file__)
|
|
27
|
+
for parent in [current_path.parent, *current_path.parents]:
|
|
28
|
+
pyproject_path = parent / "pyproject.toml"
|
|
29
|
+
if pyproject_path.exists():
|
|
30
|
+
try:
|
|
31
|
+
with open(pyproject_path, "rb") as f:
|
|
32
|
+
pyproject_data = tomllib.load(f)
|
|
33
|
+
version = pyproject_data.get("project", {}).get("version")
|
|
34
|
+
if version:
|
|
35
|
+
return version
|
|
36
|
+
except (OSError, tomllib.TOMLDecodeError):
|
|
37
|
+
# If we can't read the file, continue searching
|
|
38
|
+
continue
|
|
39
|
+
|
|
40
|
+
# Fallback version if pyproject.toml not found or doesn't contain version
|
|
41
|
+
return "0.1.0"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class Settings:
|
|
45
|
+
"""Application settings with environment-based configuration."""
|
|
46
|
+
|
|
47
|
+
def __init__(self):
|
|
48
|
+
# ================================================================
|
|
49
|
+
# Version & Framework Configuration
|
|
50
|
+
# ================================================================
|
|
51
|
+
self.version: str = _get_version_from_pyproject()
|
|
52
|
+
|
|
53
|
+
# ================================================================
|
|
54
|
+
# Environment & General Configuration
|
|
55
|
+
# ================================================================
|
|
56
|
+
self.port: int = int(os.getenv("PORT", "8000"))
|
|
57
|
+
self.time_zone: str = os.getenv("TIME_ZONE", "UTC")
|
|
58
|
+
self.log_level: str = os.getenv("LOG_LEVEL", "INFO")
|
|
59
|
+
self.api_version: str = os.getenv("API_VERSION", "v21.0")
|
|
60
|
+
self.base_url: str = os.getenv("BASE_URL", "https://graph.facebook.com/")
|
|
61
|
+
|
|
62
|
+
# ================================================================
|
|
63
|
+
# WhatsApp Configuration
|
|
64
|
+
# ================================================================
|
|
65
|
+
self.wp_access_token: str | None = os.getenv("WP_ACCESS_TOKEN")
|
|
66
|
+
self.wp_phone_id: str | None = os.getenv("WP_PHONE_ID")
|
|
67
|
+
self.wp_bid: str | None = os.getenv("WP_BID")
|
|
68
|
+
|
|
69
|
+
# Common WhatsApp settings
|
|
70
|
+
self.whatsapp_webhook_verify_token: str = os.getenv(
|
|
71
|
+
"WHATSAPP_WEBHOOK_VERIFY_TOKEN", "demo_verify_token"
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
# ================================================================
|
|
75
|
+
# AI & Tools Configuration (Optional)
|
|
76
|
+
# ================================================================
|
|
77
|
+
self.openai_api_key: str | None = os.getenv("OPENAI_API_KEY")
|
|
78
|
+
|
|
79
|
+
# ================================================================
|
|
80
|
+
# Redis Configuration (Optional)
|
|
81
|
+
# ================================================================
|
|
82
|
+
self.redis_url: str | None = os.getenv("REDIS_URL")
|
|
83
|
+
|
|
84
|
+
# Redis connection settings (only used if Redis is enabled)
|
|
85
|
+
self.redis_max_connections: int = int(os.getenv("REDIS_MAX_CONNECTIONS", "64"))
|
|
86
|
+
self.redis_connection_timeout: int = int(
|
|
87
|
+
os.getenv("REDIS_CONNECTION_TIMEOUT", "30")
|
|
88
|
+
)
|
|
89
|
+
self.redis_health_check_interval: int = int(
|
|
90
|
+
os.getenv("REDIS_HEALTH_CHECK_INTERVAL", "60")
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
# ================================================================
|
|
94
|
+
# Framework Configuration
|
|
95
|
+
# ================================================================
|
|
96
|
+
self.log_dir: str = os.getenv("LOG_DIR", "./logs")
|
|
97
|
+
|
|
98
|
+
# Development/Production detection
|
|
99
|
+
self.environment: str = os.getenv("ENVIRONMENT", "DEV")
|
|
100
|
+
|
|
101
|
+
# Apply validation
|
|
102
|
+
self._validate_settings()
|
|
103
|
+
self._validate_whatsapp_credentials()
|
|
104
|
+
|
|
105
|
+
def _validate_settings(self):
|
|
106
|
+
"""Validate settings values."""
|
|
107
|
+
# Validate log level
|
|
108
|
+
valid_levels = ["DEBUG", "INFO", "WARNING", "ERROR"]
|
|
109
|
+
if self.log_level.upper() not in valid_levels:
|
|
110
|
+
raise ValueError(f"LOG_LEVEL must be one of {valid_levels}")
|
|
111
|
+
self.log_level = self.log_level.upper()
|
|
112
|
+
|
|
113
|
+
# Validate environment
|
|
114
|
+
valid_environments = ["DEV", "PROD"]
|
|
115
|
+
if self.environment.upper() not in valid_environments:
|
|
116
|
+
self.environment = "DEV" # Default fallback
|
|
117
|
+
self.environment = self.environment.upper()
|
|
118
|
+
|
|
119
|
+
def _validate_whatsapp_credentials(self):
|
|
120
|
+
"""Validate required WhatsApp credentials."""
|
|
121
|
+
if not self.wp_access_token:
|
|
122
|
+
raise ValueError("WP_ACCESS_TOKEN is required")
|
|
123
|
+
if not self.wp_phone_id:
|
|
124
|
+
raise ValueError("WP_PHONE_ID is required")
|
|
125
|
+
if not self.wp_bid:
|
|
126
|
+
raise ValueError("WP_BID is required")
|
|
127
|
+
|
|
128
|
+
@property
|
|
129
|
+
def owner_id(self) -> str:
|
|
130
|
+
"""
|
|
131
|
+
Get owner ID (always the WhatsApp phone ID from configuration).
|
|
132
|
+
|
|
133
|
+
USAGE PATTERN:
|
|
134
|
+
- settings.owner_id: Use for URL generation, startup logging, and configuration display
|
|
135
|
+
- get_current_tenant_context(): Use for ALL webhook processing and request-scoped operations
|
|
136
|
+
|
|
137
|
+
This property represents the OWNER of the WhatsApp Business Account (configuration).
|
|
138
|
+
For runtime business context, use tenant_id from webhook context instead.
|
|
139
|
+
"""
|
|
140
|
+
if not self.wp_phone_id:
|
|
141
|
+
raise ValueError("WP_PHONE_ID is required for owner_id")
|
|
142
|
+
return self.wp_phone_id
|
|
143
|
+
|
|
144
|
+
@property
|
|
145
|
+
def has_redis(self) -> bool:
|
|
146
|
+
"""Check if Redis is configured."""
|
|
147
|
+
return self.redis_url is not None
|
|
148
|
+
|
|
149
|
+
@property
|
|
150
|
+
def is_development(self) -> bool:
|
|
151
|
+
"""Check if running in development mode."""
|
|
152
|
+
return self.environment == "DEV"
|
|
153
|
+
|
|
154
|
+
@property
|
|
155
|
+
def is_production(self) -> bool:
|
|
156
|
+
"""Check if running in production mode."""
|
|
157
|
+
return self.environment == "PROD"
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
# Global settings instance
|
|
161
|
+
settings = Settings()
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Events module for the Wappa framework.
|
|
3
|
+
|
|
4
|
+
This module contains all event-related functionality including:
|
|
5
|
+
- Event handlers and processing
|
|
6
|
+
- Default handlers for messages, status, and errors
|
|
7
|
+
- Event dispatching
|
|
8
|
+
- Webhook URL factory
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from .default_handlers import (
|
|
12
|
+
DefaultErrorHandler,
|
|
13
|
+
DefaultHandlerFactory,
|
|
14
|
+
DefaultMessageHandler,
|
|
15
|
+
DefaultStatusHandler,
|
|
16
|
+
ErrorLogStrategy,
|
|
17
|
+
MessageLogStrategy,
|
|
18
|
+
StatusLogStrategy,
|
|
19
|
+
)
|
|
20
|
+
from .event_dispatcher import WappaEventDispatcher
|
|
21
|
+
from .event_handler import WappaEventHandler
|
|
22
|
+
from .webhook_factory import WebhookEndpointType, WebhookURLFactory, webhook_url_factory
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
# Event Handlers
|
|
26
|
+
"WappaEventHandler",
|
|
27
|
+
"WappaEventDispatcher",
|
|
28
|
+
# Default Handlers
|
|
29
|
+
"DefaultMessageHandler",
|
|
30
|
+
"DefaultStatusHandler",
|
|
31
|
+
"DefaultErrorHandler",
|
|
32
|
+
"DefaultHandlerFactory",
|
|
33
|
+
# Logging Strategies
|
|
34
|
+
"MessageLogStrategy",
|
|
35
|
+
"StatusLogStrategy",
|
|
36
|
+
"ErrorLogStrategy",
|
|
37
|
+
# Webhook Factory
|
|
38
|
+
"WebhookURLFactory",
|
|
39
|
+
"WebhookEndpointType",
|
|
40
|
+
"webhook_url_factory",
|
|
41
|
+
]
|