wappa 0.1.8__py3-none-any.whl → 0.1.10__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.

Files changed (147) hide show
  1. wappa/__init__.py +4 -5
  2. wappa/api/controllers/webhook_controller.py +5 -2
  3. wappa/api/dependencies/__init__.py +0 -5
  4. wappa/api/middleware/error_handler.py +4 -4
  5. wappa/api/middleware/owner.py +11 -5
  6. wappa/api/routes/webhooks.py +2 -2
  7. wappa/cli/__init__.py +1 -1
  8. wappa/cli/examples/init/.env.example +33 -0
  9. wappa/cli/examples/init/app/__init__.py +0 -0
  10. wappa/cli/examples/init/app/main.py +9 -0
  11. wappa/cli/examples/init/app/master_event.py +10 -0
  12. wappa/cli/examples/json_cache_example/.env.example +33 -0
  13. wappa/cli/examples/json_cache_example/app/__init__.py +1 -0
  14. wappa/cli/examples/json_cache_example/app/main.py +247 -0
  15. wappa/cli/examples/json_cache_example/app/master_event.py +455 -0
  16. wappa/cli/examples/json_cache_example/app/models/__init__.py +1 -0
  17. wappa/cli/examples/json_cache_example/app/models/json_demo_models.py +256 -0
  18. wappa/cli/examples/json_cache_example/app/scores/__init__.py +35 -0
  19. wappa/cli/examples/json_cache_example/app/scores/score_base.py +192 -0
  20. wappa/cli/examples/json_cache_example/app/scores/score_cache_statistics.py +256 -0
  21. wappa/cli/examples/json_cache_example/app/scores/score_message_history.py +187 -0
  22. wappa/cli/examples/json_cache_example/app/scores/score_state_commands.py +272 -0
  23. wappa/cli/examples/json_cache_example/app/scores/score_user_management.py +239 -0
  24. wappa/cli/examples/json_cache_example/app/utils/__init__.py +26 -0
  25. wappa/cli/examples/json_cache_example/app/utils/cache_utils.py +174 -0
  26. wappa/cli/examples/json_cache_example/app/utils/message_utils.py +251 -0
  27. wappa/cli/examples/openai_transcript/.gitignore +63 -4
  28. wappa/cli/examples/openai_transcript/app/__init__.py +0 -0
  29. wappa/cli/examples/openai_transcript/app/main.py +9 -0
  30. wappa/cli/examples/openai_transcript/app/master_event.py +62 -0
  31. wappa/cli/examples/openai_transcript/app/openai_utils/__init__.py +3 -0
  32. wappa/cli/examples/openai_transcript/app/openai_utils/audio_processing.py +89 -0
  33. wappa/cli/examples/redis_cache_example/.env.example +33 -0
  34. wappa/cli/examples/redis_cache_example/app/__init__.py +6 -0
  35. wappa/cli/examples/redis_cache_example/app/main.py +246 -0
  36. wappa/cli/examples/redis_cache_example/app/master_event.py +455 -0
  37. wappa/cli/examples/redis_cache_example/app/models/redis_demo_models.py +256 -0
  38. wappa/cli/examples/redis_cache_example/app/scores/__init__.py +35 -0
  39. wappa/cli/examples/redis_cache_example/app/scores/score_base.py +192 -0
  40. wappa/cli/examples/redis_cache_example/app/scores/score_cache_statistics.py +256 -0
  41. wappa/cli/examples/redis_cache_example/app/scores/score_message_history.py +187 -0
  42. wappa/cli/examples/redis_cache_example/app/scores/score_state_commands.py +272 -0
  43. wappa/cli/examples/redis_cache_example/app/scores/score_user_management.py +239 -0
  44. wappa/cli/examples/redis_cache_example/app/utils/__init__.py +26 -0
  45. wappa/cli/examples/redis_cache_example/app/utils/cache_utils.py +174 -0
  46. wappa/cli/examples/redis_cache_example/app/utils/message_utils.py +251 -0
  47. wappa/cli/examples/simple_echo_example/.env.example +33 -0
  48. wappa/cli/examples/simple_echo_example/app/__init__.py +7 -0
  49. wappa/cli/examples/simple_echo_example/app/main.py +191 -0
  50. wappa/cli/examples/simple_echo_example/app/master_event.py +230 -0
  51. wappa/cli/examples/wappa_full_example/.env.example +33 -0
  52. wappa/cli/examples/wappa_full_example/.gitignore +63 -4
  53. wappa/cli/examples/wappa_full_example/app/__init__.py +6 -0
  54. wappa/cli/examples/wappa_full_example/app/handlers/__init__.py +5 -0
  55. wappa/cli/examples/wappa_full_example/app/handlers/command_handlers.py +492 -0
  56. wappa/cli/examples/wappa_full_example/app/handlers/message_handlers.py +559 -0
  57. wappa/cli/examples/wappa_full_example/app/handlers/state_handlers.py +514 -0
  58. wappa/cli/examples/wappa_full_example/app/main.py +269 -0
  59. wappa/cli/examples/wappa_full_example/app/master_event.py +504 -0
  60. wappa/cli/examples/wappa_full_example/app/media/README.md +54 -0
  61. wappa/cli/examples/wappa_full_example/app/media/buttons/README.md +62 -0
  62. wappa/cli/examples/wappa_full_example/app/media/buttons/kitty.png +0 -0
  63. wappa/cli/examples/wappa_full_example/app/media/buttons/puppy.png +0 -0
  64. wappa/cli/examples/wappa_full_example/app/media/list/README.md +110 -0
  65. wappa/cli/examples/wappa_full_example/app/media/list/audio.mp3 +0 -0
  66. wappa/cli/examples/wappa_full_example/app/media/list/document.pdf +0 -0
  67. wappa/cli/examples/wappa_full_example/app/media/list/image.png +0 -0
  68. wappa/cli/examples/wappa_full_example/app/media/list/video.mp4 +0 -0
  69. wappa/cli/examples/wappa_full_example/app/models/__init__.py +5 -0
  70. wappa/cli/examples/wappa_full_example/app/models/state_models.py +434 -0
  71. wappa/cli/examples/wappa_full_example/app/models/user_models.py +303 -0
  72. wappa/cli/examples/wappa_full_example/app/models/webhook_metadata.py +327 -0
  73. wappa/cli/examples/wappa_full_example/app/utils/__init__.py +5 -0
  74. wappa/cli/examples/wappa_full_example/app/utils/cache_utils.py +502 -0
  75. wappa/cli/examples/wappa_full_example/app/utils/media_handler.py +516 -0
  76. wappa/cli/examples/wappa_full_example/app/utils/metadata_extractor.py +337 -0
  77. wappa/cli/main.py +14 -5
  78. wappa/core/__init__.py +18 -23
  79. wappa/core/config/settings.py +7 -5
  80. wappa/core/events/default_handlers.py +1 -1
  81. wappa/core/factory/wappa_builder.py +38 -25
  82. wappa/core/plugins/redis_plugin.py +1 -3
  83. wappa/core/plugins/wappa_core_plugin.py +7 -6
  84. wappa/core/types.py +12 -12
  85. wappa/core/wappa_app.py +10 -8
  86. wappa/database/__init__.py +3 -4
  87. wappa/domain/enums/messenger_platform.py +1 -2
  88. wappa/domain/factories/media_factory.py +5 -20
  89. wappa/domain/factories/message_factory.py +5 -20
  90. wappa/domain/factories/messenger_factory.py +2 -4
  91. wappa/domain/interfaces/cache_interface.py +7 -7
  92. wappa/domain/interfaces/media_interface.py +2 -5
  93. wappa/domain/models/media_result.py +1 -3
  94. wappa/domain/models/platforms/platform_config.py +1 -3
  95. wappa/messaging/__init__.py +9 -12
  96. wappa/messaging/whatsapp/handlers/whatsapp_media_handler.py +20 -22
  97. wappa/models/__init__.py +27 -35
  98. wappa/persistence/__init__.py +12 -15
  99. wappa/persistence/cache_factory.py +0 -1
  100. wappa/persistence/json/__init__.py +1 -1
  101. wappa/persistence/json/cache_adapters.py +37 -25
  102. wappa/persistence/json/handlers/state_handler.py +60 -52
  103. wappa/persistence/json/handlers/table_handler.py +51 -49
  104. wappa/persistence/json/handlers/user_handler.py +71 -55
  105. wappa/persistence/json/handlers/utils/file_manager.py +42 -39
  106. wappa/persistence/json/handlers/utils/key_factory.py +1 -1
  107. wappa/persistence/json/handlers/utils/serialization.py +13 -11
  108. wappa/persistence/json/json_cache_factory.py +4 -8
  109. wappa/persistence/json/storage_manager.py +66 -79
  110. wappa/persistence/memory/__init__.py +1 -1
  111. wappa/persistence/memory/cache_adapters.py +37 -25
  112. wappa/persistence/memory/handlers/state_handler.py +62 -52
  113. wappa/persistence/memory/handlers/table_handler.py +59 -53
  114. wappa/persistence/memory/handlers/user_handler.py +75 -55
  115. wappa/persistence/memory/handlers/utils/key_factory.py +1 -1
  116. wappa/persistence/memory/handlers/utils/memory_store.py +75 -71
  117. wappa/persistence/memory/handlers/utils/ttl_manager.py +59 -67
  118. wappa/persistence/memory/memory_cache_factory.py +3 -7
  119. wappa/persistence/memory/storage_manager.py +52 -62
  120. wappa/persistence/redis/cache_adapters.py +27 -21
  121. wappa/persistence/redis/ops.py +11 -11
  122. wappa/persistence/redis/redis_client.py +4 -6
  123. wappa/persistence/redis/redis_manager.py +12 -4
  124. wappa/processors/factory.py +5 -5
  125. wappa/schemas/factory.py +2 -5
  126. wappa/schemas/whatsapp/message_types/errors.py +3 -12
  127. wappa/schemas/whatsapp/validators.py +3 -3
  128. wappa/webhooks/__init__.py +17 -18
  129. wappa/webhooks/factory.py +3 -5
  130. wappa/webhooks/whatsapp/__init__.py +10 -13
  131. wappa/webhooks/whatsapp/message_types/audio.py +0 -4
  132. wappa/webhooks/whatsapp/message_types/document.py +1 -9
  133. wappa/webhooks/whatsapp/message_types/errors.py +3 -12
  134. wappa/webhooks/whatsapp/message_types/location.py +1 -21
  135. wappa/webhooks/whatsapp/message_types/sticker.py +1 -5
  136. wappa/webhooks/whatsapp/message_types/text.py +0 -6
  137. wappa/webhooks/whatsapp/message_types/video.py +1 -20
  138. wappa/webhooks/whatsapp/status_models.py +2 -2
  139. wappa/webhooks/whatsapp/validators.py +3 -3
  140. {wappa-0.1.8.dist-info → wappa-0.1.10.dist-info}/METADATA +362 -8
  141. {wappa-0.1.8.dist-info → wappa-0.1.10.dist-info}/RECORD +144 -80
  142. wappa/cli/examples/init/pyproject.toml +0 -7
  143. wappa/cli/examples/simple_echo_example/.python-version +0 -1
  144. wappa/cli/examples/simple_echo_example/pyproject.toml +0 -9
  145. {wappa-0.1.8.dist-info → wappa-0.1.10.dist-info}/WHEEL +0 -0
  146. {wappa-0.1.8.dist-info → wappa-0.1.10.dist-info}/entry_points.txt +0 -0
  147. {wappa-0.1.8.dist-info → wappa-0.1.10.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,6 @@
1
+ """
2
+ Redis Cache Example App Module
3
+
4
+ This package contains the application code for the Redis Cache Example,
5
+ demonstrating SOLID architecture principles with the Wappa framework.
6
+ """
@@ -0,0 +1,246 @@
1
+ """
2
+ Redis Cache Example - SOLID Architecture Implementation
3
+
4
+ This is the main initialization file following SOLID principles:
5
+ - Single Responsibility: Pure initialization and configuration
6
+ - Open/Closed: Extensible through score module registration
7
+ - Liskov Substitution: Compatible with Wappa framework interface
8
+ - Interface Segregation: Clean dependency interfaces
9
+ - Dependency Inversion: Abstractions injected into concrete implementations
10
+
11
+ SETUP REQUIRED:
12
+ 1. Create a .env file with your WhatsApp Business API credentials:
13
+ WP_ACCESS_TOKEN=your_access_token_here
14
+ WP_PHONE_ID=your_phone_number_id_here
15
+ WP_BID=your_business_id_here
16
+
17
+ 2. Set up Redis:
18
+ REDIS_URL=redis://localhost:6379
19
+
20
+ DEMO FEATURES:
21
+ - SOLID architecture with separated concerns
22
+ - Master event orchestrator with score modules
23
+ - User management, message history, and state commands
24
+ - Cache statistics and monitoring
25
+ - Professional logging and error handling
26
+
27
+ USAGE:
28
+ - Direct Python: python -m app.main (from project root)
29
+ - FastAPI-style: uvicorn app.main:app --reload (from project root)
30
+ - Wappa CLI: wappa dev app.main (when CLI is available)
31
+ """
32
+
33
+ # Import core Wappa components
34
+ from wappa import Wappa, __version__
35
+ from wappa.core.config.settings import settings
36
+ from wappa.core.logging import get_logger
37
+
38
+ logger = get_logger(__name__)
39
+
40
+ # Import our SOLID architecture WappaEventHandler implementation
41
+ from .master_event import RedisCacheExampleHandler
42
+
43
+
44
+ def validate_configuration() -> bool:
45
+ """
46
+ Validate required configuration settings.
47
+
48
+ Returns:
49
+ True if configuration is valid, False otherwise
50
+ """
51
+
52
+ # Check required WhatsApp credentials
53
+ missing_configs = []
54
+
55
+ if not settings.wp_access_token:
56
+ missing_configs.append("WP_ACCESS_TOKEN")
57
+
58
+ if not settings.wp_phone_id:
59
+ missing_configs.append("WP_PHONE_ID")
60
+
61
+ if not settings.wp_bid:
62
+ missing_configs.append("WP_BID")
63
+
64
+ if not settings.has_redis:
65
+ missing_configs.append("REDIS_URL")
66
+
67
+ if missing_configs:
68
+ logger.error(f"❌ Missing required configuration: {', '.join(missing_configs)}")
69
+ logger.error("💡 Create a .env file with the required credentials")
70
+ return False
71
+
72
+ logger.info("✅ Configuration validation passed")
73
+ return True
74
+
75
+
76
+ def display_startup_information() -> None:
77
+ """
78
+ Display startup information and demo features.
79
+
80
+ Shows configuration status, architecture overview,
81
+ and available demo features.
82
+ """
83
+ print(f"🚀 Wappa v{__version__} - Redis Cache Example (SOLID Architecture)")
84
+ print("=" * 80)
85
+ print()
86
+
87
+ print("🏗️ *SOLID ARCHITECTURE IMPLEMENTATION:*")
88
+ print(" • Single Responsibility: Each score module has one specific concern")
89
+ print(" • Open/Closed: New score modules can be added without modification")
90
+ print(" • Liskov Substitution: All scores implement the same interface")
91
+ print(" • Interface Segregation: Clean, focused interfaces for each concern")
92
+ print(" • Dependency Inversion: Dependencies injected through abstractions")
93
+ print()
94
+
95
+ print("📋 *CONFIGURATION STATUS:*")
96
+ print(
97
+ f" • Access Token: {'✅ Configured' if settings.wp_access_token else '❌ Missing'}"
98
+ )
99
+ print(
100
+ f" • Phone ID: {settings.wp_phone_id if settings.wp_phone_id else '❌ Missing'}"
101
+ )
102
+ print(f" • Business ID: {'✅ Configured' if settings.wp_bid else '❌ Missing'}")
103
+ print(f" • Redis URL: {'✅ Configured' if settings.has_redis else '❌ Missing'}")
104
+ print(
105
+ f" • Environment: {'🛠️ Development' if settings.is_development else '🚀 Production'}"
106
+ )
107
+ print()
108
+
109
+ print("🎯 *SCORE MODULES (BUSINESS LOGIC):*")
110
+ print(" • UserManagementScore: User profile and caching logic")
111
+ print(" • MessageHistoryScore: Message logging and /HISTORY command")
112
+ print(" • StateCommandsScore: /WAPPA and /EXIT command processing")
113
+ print(" • CacheStatisticsScore: Cache monitoring and /STATS command")
114
+ print()
115
+
116
+ print("🧪 *DEMO FEATURES:*")
117
+ print(" 1. Send any message → User profile created/updated + message logged")
118
+ print(" 2. Send '/WAPPA' → Enter special state with cache management")
119
+ print(" 3. While in WAPPA state → All messages replied with 'Hola Wapp@ ;)'")
120
+ print(" 4. Send '/EXIT' → Leave special state with session summary")
121
+ print(" 5. Send '/HISTORY' → View your last 20 messages with timestamps")
122
+ print(" 6. Send '/STATS' → View comprehensive cache statistics")
123
+ print()
124
+
125
+ print("💎 *REDIS CACHE ARCHITECTURE:*")
126
+ print(" • user_cache: User profiles with dependency injection")
127
+ print(" • table_cache: Message history with BaseModel auto-serialization")
128
+ print(" • state_cache: Command state management with TTL")
129
+ print(" • Comprehensive error handling and logging")
130
+ print()
131
+
132
+ print("🔧 *TECHNICAL FEATURES:*")
133
+ print(" • Dependency injection with interface abstractions")
134
+ print(" • Score module registry with automatic discovery")
135
+ print(" • Professional error handling and recovery")
136
+ print(" • Performance monitoring and statistics")
137
+ print(" • Comprehensive logging with structured output")
138
+ print(" • Proper WappaEventHandler implementation with all required methods")
139
+ print()
140
+
141
+
142
+ def create_wappa_application() -> Wappa:
143
+ """
144
+ Create and configure the Wappa application.
145
+
146
+ This function follows Single Responsibility Principle by focusing
147
+ only on application creation and initial configuration.
148
+
149
+ Returns:
150
+ Configured Wappa application instance
151
+ """
152
+
153
+ try:
154
+ # Create Wappa instance with Redis cache
155
+ logger.info("🏗️ Creating Wappa application with Redis cache...")
156
+ app = Wappa(cache="redis")
157
+
158
+ logger.info("✅ Wappa application created successfully")
159
+ return app
160
+
161
+ except Exception as e:
162
+ logger.error(f"❌ Failed to create Wappa application: {e}")
163
+ raise
164
+
165
+
166
+ def main() -> None:
167
+ """
168
+ Main application entry point.
169
+
170
+ Demonstrates SOLID principles in action:
171
+ - Single Responsibility: Each function has one clear purpose
172
+ - Dependency Inversion: Dependencies flow from abstractions
173
+ - Open/Closed: System is open for extension via score modules
174
+ """
175
+
176
+ logger.info("🚀 Starting Redis Cache Example with SOLID Architecture")
177
+
178
+ try:
179
+ # Display startup information
180
+ display_startup_information()
181
+
182
+ # Validate configuration before proceeding
183
+ if not validate_configuration():
184
+ logger.error(
185
+ "❌ Configuration validation failed - cannot start application"
186
+ )
187
+ return
188
+
189
+ # Create Wappa application
190
+ app = create_wappa_application()
191
+
192
+ # Create and set the SOLID WappaEventHandler implementation
193
+ handler = RedisCacheExampleHandler()
194
+ app.set_event_handler(handler)
195
+
196
+ logger.info(
197
+ "✅ Application initialization completed with SOLID WappaEventHandler"
198
+ )
199
+
200
+ print("🌐 Starting SOLID Redis cache demo server...")
201
+ print("💡 Press CTRL+C to stop the server")
202
+ print("=" * 80)
203
+ print()
204
+
205
+ # Start the application
206
+ # The framework will handle dependency injection automatically
207
+ app.run()
208
+
209
+ except KeyboardInterrupt:
210
+ logger.info("👋 Application stopped by user")
211
+ print("\n👋 Redis cache demo stopped by user")
212
+
213
+ except Exception as e:
214
+ logger.error(f"❌ Application startup error: {e}", exc_info=True)
215
+ print(f"\n❌ Server error: {e}")
216
+
217
+ finally:
218
+ logger.info("🏁 Redis cache demo completed")
219
+ print("🏁 Redis cache demo completed")
220
+
221
+
222
+ # Module-level app instance for uvicorn compatibility
223
+ # This enables: uvicorn main:app --reload
224
+
225
+ # Set up basic logging for module-level initialization
226
+
227
+
228
+ try:
229
+ logger.info("📦 Creating module-level Wappa application instance")
230
+ app = Wappa(cache="redis")
231
+
232
+ # Create and set the SOLID WappaEventHandler implementation
233
+ handler = RedisCacheExampleHandler()
234
+ app.set_event_handler(handler)
235
+
236
+ logger.info(
237
+ "✅ Module-level application instance ready with SOLID WappaEventHandler"
238
+ )
239
+
240
+ except Exception as e:
241
+ logger.error(f"❌ Failed to create module-level app instance: {e}")
242
+ raise
243
+
244
+
245
+ if __name__ == "__main__":
246
+ main()