wappa 0.1.8__py3-none-any.whl → 0.1.9__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 (78) hide show
  1. wappa/cli/examples/init/.env.example +33 -0
  2. wappa/cli/examples/init/app/__init__.py +0 -0
  3. wappa/cli/examples/init/app/main.py +8 -0
  4. wappa/cli/examples/init/app/master_event.py +8 -0
  5. wappa/cli/examples/json_cache_example/.env.example +33 -0
  6. wappa/cli/examples/json_cache_example/app/__init__.py +1 -0
  7. wappa/cli/examples/json_cache_example/app/main.py +235 -0
  8. wappa/cli/examples/json_cache_example/app/master_event.py +419 -0
  9. wappa/cli/examples/json_cache_example/app/models/__init__.py +1 -0
  10. wappa/cli/examples/json_cache_example/app/models/json_demo_models.py +275 -0
  11. wappa/cli/examples/json_cache_example/app/scores/__init__.py +35 -0
  12. wappa/cli/examples/json_cache_example/app/scores/score_base.py +186 -0
  13. wappa/cli/examples/json_cache_example/app/scores/score_cache_statistics.py +248 -0
  14. wappa/cli/examples/json_cache_example/app/scores/score_message_history.py +190 -0
  15. wappa/cli/examples/json_cache_example/app/scores/score_state_commands.py +260 -0
  16. wappa/cli/examples/json_cache_example/app/scores/score_user_management.py +223 -0
  17. wappa/cli/examples/json_cache_example/app/utils/__init__.py +26 -0
  18. wappa/cli/examples/json_cache_example/app/utils/cache_utils.py +176 -0
  19. wappa/cli/examples/json_cache_example/app/utils/message_utils.py +246 -0
  20. wappa/cli/examples/openai_transcript/.gitignore +63 -4
  21. wappa/cli/examples/openai_transcript/app/__init__.py +0 -0
  22. wappa/cli/examples/openai_transcript/app/main.py +8 -0
  23. wappa/cli/examples/openai_transcript/app/master_event.py +53 -0
  24. wappa/cli/examples/openai_transcript/app/openai_utils/__init__.py +3 -0
  25. wappa/cli/examples/openai_transcript/app/openai_utils/audio_processing.py +76 -0
  26. wappa/cli/examples/redis_cache_example/.env.example +33 -0
  27. wappa/cli/examples/redis_cache_example/app/__init__.py +6 -0
  28. wappa/cli/examples/redis_cache_example/app/main.py +234 -0
  29. wappa/cli/examples/redis_cache_example/app/master_event.py +419 -0
  30. wappa/cli/examples/redis_cache_example/app/models/redis_demo_models.py +275 -0
  31. wappa/cli/examples/redis_cache_example/app/scores/__init__.py +35 -0
  32. wappa/cli/examples/redis_cache_example/app/scores/score_base.py +186 -0
  33. wappa/cli/examples/redis_cache_example/app/scores/score_cache_statistics.py +248 -0
  34. wappa/cli/examples/redis_cache_example/app/scores/score_message_history.py +190 -0
  35. wappa/cli/examples/redis_cache_example/app/scores/score_state_commands.py +260 -0
  36. wappa/cli/examples/redis_cache_example/app/scores/score_user_management.py +223 -0
  37. wappa/cli/examples/redis_cache_example/app/utils/__init__.py +26 -0
  38. wappa/cli/examples/redis_cache_example/app/utils/cache_utils.py +176 -0
  39. wappa/cli/examples/redis_cache_example/app/utils/message_utils.py +246 -0
  40. wappa/cli/examples/simple_echo_example/.env.example +33 -0
  41. wappa/cli/examples/simple_echo_example/app/__init__.py +7 -0
  42. wappa/cli/examples/simple_echo_example/app/main.py +183 -0
  43. wappa/cli/examples/simple_echo_example/app/master_event.py +209 -0
  44. wappa/cli/examples/wappa_full_example/.env.example +33 -0
  45. wappa/cli/examples/wappa_full_example/.gitignore +63 -4
  46. wappa/cli/examples/wappa_full_example/app/__init__.py +6 -0
  47. wappa/cli/examples/wappa_full_example/app/handlers/__init__.py +5 -0
  48. wappa/cli/examples/wappa_full_example/app/handlers/command_handlers.py +484 -0
  49. wappa/cli/examples/wappa_full_example/app/handlers/message_handlers.py +551 -0
  50. wappa/cli/examples/wappa_full_example/app/handlers/state_handlers.py +492 -0
  51. wappa/cli/examples/wappa_full_example/app/main.py +257 -0
  52. wappa/cli/examples/wappa_full_example/app/master_event.py +445 -0
  53. wappa/cli/examples/wappa_full_example/app/media/README.md +54 -0
  54. wappa/cli/examples/wappa_full_example/app/media/buttons/README.md +62 -0
  55. wappa/cli/examples/wappa_full_example/app/media/buttons/kitty.png +0 -0
  56. wappa/cli/examples/wappa_full_example/app/media/buttons/puppy.png +0 -0
  57. wappa/cli/examples/wappa_full_example/app/media/list/README.md +110 -0
  58. wappa/cli/examples/wappa_full_example/app/media/list/audio.mp3 +0 -0
  59. wappa/cli/examples/wappa_full_example/app/media/list/document.pdf +0 -0
  60. wappa/cli/examples/wappa_full_example/app/media/list/image.png +0 -0
  61. wappa/cli/examples/wappa_full_example/app/media/list/video.mp4 +0 -0
  62. wappa/cli/examples/wappa_full_example/app/models/__init__.py +5 -0
  63. wappa/cli/examples/wappa_full_example/app/models/state_models.py +425 -0
  64. wappa/cli/examples/wappa_full_example/app/models/user_models.py +287 -0
  65. wappa/cli/examples/wappa_full_example/app/models/webhook_metadata.py +301 -0
  66. wappa/cli/examples/wappa_full_example/app/utils/__init__.py +5 -0
  67. wappa/cli/examples/wappa_full_example/app/utils/cache_utils.py +483 -0
  68. wappa/cli/examples/wappa_full_example/app/utils/media_handler.py +473 -0
  69. wappa/cli/examples/wappa_full_example/app/utils/metadata_extractor.py +298 -0
  70. wappa/cli/main.py +8 -4
  71. {wappa-0.1.8.dist-info → wappa-0.1.9.dist-info}/METADATA +1 -1
  72. {wappa-0.1.8.dist-info → wappa-0.1.9.dist-info}/RECORD +75 -11
  73. wappa/cli/examples/init/pyproject.toml +0 -7
  74. wappa/cli/examples/simple_echo_example/.python-version +0 -1
  75. wappa/cli/examples/simple_echo_example/pyproject.toml +0 -9
  76. {wappa-0.1.8.dist-info → wappa-0.1.9.dist-info}/WHEEL +0 -0
  77. {wappa-0.1.8.dist-info → wappa-0.1.9.dist-info}/entry_points.txt +0 -0
  78. {wappa-0.1.8.dist-info → wappa-0.1.9.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,257 @@
1
+ """
2
+ Wappa Full Example - Main Application Entry Point
3
+
4
+ This is a comprehensive demonstration of the Wappa framework capabilities including:
5
+ - Complete message type handling with metadata extraction
6
+ - Interactive commands (/button, /list, /cta, /location) with state management
7
+ - Media relay functionality using media_id
8
+ - User tracking and analytics with Redis cache
9
+ - Welcome messages for first-time users
10
+ - Professional error handling and logging
11
+
12
+ SETUP REQUIRED:
13
+ 1. Create a .env file with your WhatsApp Business API credentials:
14
+ WP_ACCESS_TOKEN=your_access_token_here
15
+ WP_PHONE_ID=your_phone_number_id_here
16
+ WP_BID=your_business_id_here
17
+
18
+ 2. Set up Redis:
19
+ REDIS_URL=redis://localhost:6379
20
+
21
+ FEATURES DEMONSTRATED:
22
+ - Comprehensive webhook metadata extraction for all message types
23
+ - Interactive button demo with animal selection and media responses
24
+ - Interactive list demo with media file types
25
+ - CTA button linking to external documentation
26
+ - Location sharing with predefined coordinates
27
+ - State management with TTL (10 minute expiration)
28
+ - User profile caching and activity tracking
29
+ - First-time user welcome messages with instructions
30
+
31
+ USAGE:
32
+ - Direct Python: python -m app.main (from project root)
33
+ - FastAPI-style: uvicorn app.main:app --reload (from project root)
34
+ - uv run: uv run python -m app.main
35
+ """
36
+
37
+ from wappa import Wappa, __version__
38
+ from wappa.core.config.settings import settings
39
+ from wappa.core.logging import get_logger
40
+
41
+ logger = get_logger(__name__)
42
+
43
+ # Import our comprehensive WappaEventHandler implementation
44
+ from .master_event import WappaFullExampleHandler
45
+
46
+
47
+ def validate_configuration() -> bool:
48
+ """
49
+ Validate required configuration settings.
50
+
51
+ Returns:
52
+ True if configuration is valid, False otherwise
53
+ """
54
+ missing_configs = []
55
+
56
+ if not settings.wp_access_token:
57
+ missing_configs.append("WP_ACCESS_TOKEN")
58
+
59
+ if not settings.wp_phone_id:
60
+ missing_configs.append("WP_PHONE_ID")
61
+
62
+ if not settings.wp_bid:
63
+ missing_configs.append("WP_BID")
64
+
65
+ if not settings.has_redis:
66
+ missing_configs.append("REDIS_URL")
67
+
68
+ if missing_configs:
69
+ logger.error(f"❌ Missing required configuration: {', '.join(missing_configs)}")
70
+ logger.error("💡 Create a .env file with the required credentials")
71
+ return False
72
+
73
+ logger.info("✅ Configuration validation passed")
74
+ return True
75
+
76
+
77
+ def display_startup_information() -> None:
78
+ """
79
+ Display startup information and demo features.
80
+ """
81
+ print(f"🚀 Wappa v{__version__} - Full Example (Comprehensive Demo)")
82
+ print("=" * 80)
83
+ print()
84
+
85
+ print("🎯 *COMPREHENSIVE WAPPA FRAMEWORK DEMONSTRATION*")
86
+ print(" This example showcases ALL major Wappa framework features:")
87
+ print(" • Complete message type handling with metadata extraction")
88
+ print(" • Interactive commands with state management and TTL")
89
+ print(" • Media relay functionality using media_id")
90
+ print(" • User tracking and analytics with Redis cache")
91
+ print(" • Welcome messages for first-time users")
92
+ print(" • Professional error handling and logging")
93
+ print()
94
+
95
+ print("📋 *CONFIGURATION STATUS:*")
96
+ print(f" • Access Token: {'✅ Configured' if settings.wp_access_token else '❌ Missing'}")
97
+ print(f" • Phone ID: {settings.wp_phone_id if settings.wp_phone_id else '❌ Missing'}")
98
+ print(f" • Business ID: {'✅ Configured' if settings.wp_bid else '❌ Missing'}")
99
+ print(f" • Redis URL: {'✅ Configured' if settings.has_redis else '❌ Missing'}")
100
+ print(f" • Environment: {'🛠️ Development' if settings.is_development else '🚀 Production'}")
101
+ print()
102
+
103
+ print("🎮 *INTERACTIVE DEMO COMMANDS:*")
104
+ print(" • `/button` → Interactive button demo with animal selection")
105
+ print(" - Creates buttons for Kitty 🐱 and Puppy 🐶")
106
+ print(" - 10-minute TTL with state management")
107
+ print(" - Sends corresponding animal image on selection")
108
+ print(" - Shows comprehensive metadata extraction")
109
+ print()
110
+ print(" • `/list` → Interactive list demo with media files")
111
+ print(" - List with Image, Video, Audio, Document options")
112
+ print(" - Sends actual media files based on selection")
113
+ print(" - Demonstrates list interaction patterns")
114
+ print()
115
+ print(" • `/cta` → Call-to-Action button demonstration")
116
+ print(" - External link to Wappa documentation")
117
+ print(" - Shows CTA button implementation")
118
+ print()
119
+ print(" • `/location` → Location sharing demonstration")
120
+ print(" - Shares predefined location (Bogotá, Colombia)")
121
+ print(" - Shows location message implementation")
122
+ print()
123
+
124
+ print("📨 *MESSAGE TYPE HANDLING:*")
125
+ print(" • Text Messages → Echo with 'Echo - {content}' + metadata")
126
+ print(" • Media Messages → Relay same media using media_id + metadata")
127
+ print(" • Location Messages → Echo same location coordinates + metadata")
128
+ print(" • Contact Messages → Echo contact information + metadata")
129
+ print(" • Interactive Messages → Process selections + metadata")
130
+ print()
131
+
132
+ print("👤 *USER MANAGEMENT FEATURES:*")
133
+ print(" • First-time user detection and welcome messages")
134
+ print(" • User profile caching with activity tracking")
135
+ print(" • Message count and interaction statistics")
136
+ print(" • Command usage analytics")
137
+ print()
138
+
139
+ print("🏗️ *TECHNICAL ARCHITECTURE:*")
140
+ print(" • Redis cache for user profiles and interactive states")
141
+ print(" • Comprehensive metadata extraction per message type")
142
+ print(" • State management with TTL for interactive features")
143
+ print(" • Professional error handling and recovery")
144
+ print(" • Structured logging with performance metrics")
145
+ print(" • Clean code architecture with separation of concerns")
146
+ print()
147
+
148
+ print("📊 *DEMONSTRATED PATTERNS:*")
149
+ print(" • Complete IMessenger interface utilization")
150
+ print(" • Media handling with download/upload capabilities")
151
+ print(" • Interactive workflow state machines")
152
+ print(" • User session and activity tracking")
153
+ print(" • Production-ready error handling")
154
+ print(" • Scalable Redis caching strategies")
155
+ print()
156
+
157
+
158
+ def create_wappa_application() -> Wappa:
159
+ """
160
+ Create and configure the Wappa application.
161
+
162
+ Returns:
163
+ Configured Wappa application instance
164
+ """
165
+ try:
166
+ # Create Wappa instance with Redis cache
167
+ logger.info("🏗️ Creating Wappa application with Redis cache...")
168
+ app = Wappa(cache="redis")
169
+
170
+ logger.info("✅ Wappa application created successfully")
171
+ return app
172
+
173
+ except Exception as e:
174
+ logger.error(f"❌ Failed to create Wappa application: {e}")
175
+ raise
176
+
177
+
178
+ def main() -> None:
179
+ """
180
+ Main application entry point.
181
+
182
+ Demonstrates complete Wappa framework integration with:
183
+ - Configuration validation
184
+ - Application setup
185
+ - Handler registration
186
+ - Professional startup flow
187
+ """
188
+ logger.info("🚀 Starting Wappa Full Example - Comprehensive Demo")
189
+
190
+ try:
191
+ # Display comprehensive startup information
192
+ display_startup_information()
193
+
194
+ # Validate configuration before proceeding
195
+ if not validate_configuration():
196
+ logger.error("❌ Configuration validation failed - cannot start application")
197
+ return
198
+
199
+ # Create Wappa application
200
+ app = create_wappa_application()
201
+
202
+ # Create and set our comprehensive WappaEventHandler implementation
203
+ handler = WappaFullExampleHandler()
204
+ app.set_event_handler(handler)
205
+
206
+ logger.info("✅ Application initialization completed with comprehensive WappaEventHandler")
207
+
208
+ print("🌐 Starting comprehensive Wappa demo server...")
209
+ print("💡 Press CTRL+C to stop the server")
210
+ print()
211
+ print("🎯 *Try these features once connected:*")
212
+ print(" 1. Send any message → See metadata extraction + echo")
213
+ print(" 2. Send /button → Interactive button demo")
214
+ print(" 3. Send /list → Interactive list demo")
215
+ print(" 4. Send /cta → Call-to-action button")
216
+ print(" 5. Send /location → Location sharing demo")
217
+ print(" 6. Send media files → See media relay functionality")
218
+ print("=" * 80)
219
+ print()
220
+
221
+ # Start the application
222
+ # The framework will handle dependency injection automatically
223
+ app.run()
224
+
225
+ except KeyboardInterrupt:
226
+ logger.info("👋 Application stopped by user")
227
+ print("\n👋 Wappa Full Example stopped by user")
228
+
229
+ except Exception as e:
230
+ logger.error(f"❌ Application startup error: {e}", exc_info=True)
231
+ print(f"\n❌ Server error: {e}")
232
+
233
+ finally:
234
+ logger.info("🏁 Wappa Full Example completed")
235
+ print("🏁 Wappa Full Example completed")
236
+
237
+
238
+ # Module-level app instance for uvicorn compatibility
239
+ # This enables: uvicorn app.main:app --reload
240
+
241
+ try:
242
+ logger.info("📦 Creating module-level Wappa application instance")
243
+ app = Wappa(cache="redis")
244
+
245
+ # Create and set our comprehensive WappaEventHandler implementation
246
+ handler = WappaFullExampleHandler()
247
+ app.set_event_handler(handler)
248
+
249
+ logger.info("✅ Module-level application instance ready with comprehensive WappaEventHandler")
250
+
251
+ except Exception as e:
252
+ logger.error(f"❌ Failed to create module-level app instance: {e}")
253
+ raise
254
+
255
+
256
+ if __name__ == "__main__":
257
+ main()