wappa 0.1.9__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.
- wappa/__init__.py +4 -5
- wappa/api/controllers/webhook_controller.py +5 -2
- wappa/api/dependencies/__init__.py +0 -5
- wappa/api/middleware/error_handler.py +4 -4
- wappa/api/middleware/owner.py +11 -5
- wappa/api/routes/webhooks.py +2 -2
- wappa/cli/__init__.py +1 -1
- wappa/cli/examples/init/app/main.py +2 -1
- wappa/cli/examples/init/app/master_event.py +5 -3
- wappa/cli/examples/json_cache_example/app/__init__.py +1 -1
- wappa/cli/examples/json_cache_example/app/main.py +56 -44
- wappa/cli/examples/json_cache_example/app/master_event.py +181 -145
- wappa/cli/examples/json_cache_example/app/models/__init__.py +1 -1
- wappa/cli/examples/json_cache_example/app/models/json_demo_models.py +32 -51
- wappa/cli/examples/json_cache_example/app/scores/__init__.py +2 -2
- wappa/cli/examples/json_cache_example/app/scores/score_base.py +52 -46
- wappa/cli/examples/json_cache_example/app/scores/score_cache_statistics.py +70 -62
- wappa/cli/examples/json_cache_example/app/scores/score_message_history.py +41 -44
- wappa/cli/examples/json_cache_example/app/scores/score_state_commands.py +83 -71
- wappa/cli/examples/json_cache_example/app/scores/score_user_management.py +73 -57
- wappa/cli/examples/json_cache_example/app/utils/__init__.py +2 -2
- wappa/cli/examples/json_cache_example/app/utils/cache_utils.py +54 -56
- wappa/cli/examples/json_cache_example/app/utils/message_utils.py +85 -80
- wappa/cli/examples/openai_transcript/app/main.py +2 -1
- wappa/cli/examples/openai_transcript/app/master_event.py +31 -22
- wappa/cli/examples/openai_transcript/app/openai_utils/__init__.py +1 -1
- wappa/cli/examples/openai_transcript/app/openai_utils/audio_processing.py +37 -24
- wappa/cli/examples/redis_cache_example/app/__init__.py +1 -1
- wappa/cli/examples/redis_cache_example/app/main.py +56 -44
- wappa/cli/examples/redis_cache_example/app/master_event.py +181 -145
- wappa/cli/examples/redis_cache_example/app/models/redis_demo_models.py +31 -50
- wappa/cli/examples/redis_cache_example/app/scores/__init__.py +2 -2
- wappa/cli/examples/redis_cache_example/app/scores/score_base.py +52 -46
- wappa/cli/examples/redis_cache_example/app/scores/score_cache_statistics.py +70 -62
- wappa/cli/examples/redis_cache_example/app/scores/score_message_history.py +41 -44
- wappa/cli/examples/redis_cache_example/app/scores/score_state_commands.py +83 -71
- wappa/cli/examples/redis_cache_example/app/scores/score_user_management.py +73 -57
- wappa/cli/examples/redis_cache_example/app/utils/__init__.py +2 -2
- wappa/cli/examples/redis_cache_example/app/utils/cache_utils.py +54 -56
- wappa/cli/examples/redis_cache_example/app/utils/message_utils.py +85 -80
- wappa/cli/examples/simple_echo_example/app/__init__.py +1 -1
- wappa/cli/examples/simple_echo_example/app/main.py +41 -33
- wappa/cli/examples/simple_echo_example/app/master_event.py +78 -57
- wappa/cli/examples/wappa_full_example/app/__init__.py +1 -1
- wappa/cli/examples/wappa_full_example/app/handlers/__init__.py +1 -1
- wappa/cli/examples/wappa_full_example/app/handlers/command_handlers.py +134 -126
- wappa/cli/examples/wappa_full_example/app/handlers/message_handlers.py +237 -229
- wappa/cli/examples/wappa_full_example/app/handlers/state_handlers.py +170 -148
- wappa/cli/examples/wappa_full_example/app/main.py +51 -39
- wappa/cli/examples/wappa_full_example/app/master_event.py +179 -120
- wappa/cli/examples/wappa_full_example/app/models/__init__.py +1 -1
- wappa/cli/examples/wappa_full_example/app/models/state_models.py +113 -104
- wappa/cli/examples/wappa_full_example/app/models/user_models.py +92 -76
- wappa/cli/examples/wappa_full_example/app/models/webhook_metadata.py +109 -83
- wappa/cli/examples/wappa_full_example/app/utils/__init__.py +1 -1
- wappa/cli/examples/wappa_full_example/app/utils/cache_utils.py +132 -113
- wappa/cli/examples/wappa_full_example/app/utils/media_handler.py +175 -132
- wappa/cli/examples/wappa_full_example/app/utils/metadata_extractor.py +126 -87
- wappa/cli/main.py +9 -4
- wappa/core/__init__.py +18 -23
- wappa/core/config/settings.py +7 -5
- wappa/core/events/default_handlers.py +1 -1
- wappa/core/factory/wappa_builder.py +38 -25
- wappa/core/plugins/redis_plugin.py +1 -3
- wappa/core/plugins/wappa_core_plugin.py +7 -6
- wappa/core/types.py +12 -12
- wappa/core/wappa_app.py +10 -8
- wappa/database/__init__.py +3 -4
- wappa/domain/enums/messenger_platform.py +1 -2
- wappa/domain/factories/media_factory.py +5 -20
- wappa/domain/factories/message_factory.py +5 -20
- wappa/domain/factories/messenger_factory.py +2 -4
- wappa/domain/interfaces/cache_interface.py +7 -7
- wappa/domain/interfaces/media_interface.py +2 -5
- wappa/domain/models/media_result.py +1 -3
- wappa/domain/models/platforms/platform_config.py +1 -3
- wappa/messaging/__init__.py +9 -12
- wappa/messaging/whatsapp/handlers/whatsapp_media_handler.py +20 -22
- wappa/models/__init__.py +27 -35
- wappa/persistence/__init__.py +12 -15
- wappa/persistence/cache_factory.py +0 -1
- wappa/persistence/json/__init__.py +1 -1
- wappa/persistence/json/cache_adapters.py +37 -25
- wappa/persistence/json/handlers/state_handler.py +60 -52
- wappa/persistence/json/handlers/table_handler.py +51 -49
- wappa/persistence/json/handlers/user_handler.py +71 -55
- wappa/persistence/json/handlers/utils/file_manager.py +42 -39
- wappa/persistence/json/handlers/utils/key_factory.py +1 -1
- wappa/persistence/json/handlers/utils/serialization.py +13 -11
- wappa/persistence/json/json_cache_factory.py +4 -8
- wappa/persistence/json/storage_manager.py +66 -79
- wappa/persistence/memory/__init__.py +1 -1
- wappa/persistence/memory/cache_adapters.py +37 -25
- wappa/persistence/memory/handlers/state_handler.py +62 -52
- wappa/persistence/memory/handlers/table_handler.py +59 -53
- wappa/persistence/memory/handlers/user_handler.py +75 -55
- wappa/persistence/memory/handlers/utils/key_factory.py +1 -1
- wappa/persistence/memory/handlers/utils/memory_store.py +75 -71
- wappa/persistence/memory/handlers/utils/ttl_manager.py +59 -67
- wappa/persistence/memory/memory_cache_factory.py +3 -7
- wappa/persistence/memory/storage_manager.py +52 -62
- wappa/persistence/redis/cache_adapters.py +27 -21
- wappa/persistence/redis/ops.py +11 -11
- wappa/persistence/redis/redis_client.py +4 -6
- wappa/persistence/redis/redis_manager.py +12 -4
- wappa/processors/factory.py +5 -5
- wappa/schemas/factory.py +2 -5
- wappa/schemas/whatsapp/message_types/errors.py +3 -12
- wappa/schemas/whatsapp/validators.py +3 -3
- wappa/webhooks/__init__.py +17 -18
- wappa/webhooks/factory.py +3 -5
- wappa/webhooks/whatsapp/__init__.py +10 -13
- wappa/webhooks/whatsapp/message_types/audio.py +0 -4
- wappa/webhooks/whatsapp/message_types/document.py +1 -9
- wappa/webhooks/whatsapp/message_types/errors.py +3 -12
- wappa/webhooks/whatsapp/message_types/location.py +1 -21
- wappa/webhooks/whatsapp/message_types/sticker.py +1 -5
- wappa/webhooks/whatsapp/message_types/text.py +0 -6
- wappa/webhooks/whatsapp/message_types/video.py +1 -20
- wappa/webhooks/whatsapp/status_models.py +2 -2
- wappa/webhooks/whatsapp/validators.py +3 -3
- {wappa-0.1.9.dist-info → wappa-0.1.10.dist-info}/METADATA +362 -8
- {wappa-0.1.9.dist-info → wappa-0.1.10.dist-info}/RECORD +126 -126
- {wappa-0.1.9.dist-info → wappa-0.1.10.dist-info}/WHEEL +0 -0
- {wappa-0.1.9.dist-info → wappa-0.1.10.dist-info}/entry_points.txt +0 -0
- {wappa-0.1.9.dist-info → wappa-0.1.10.dist-info}/licenses/LICENSE +0 -0
|
@@ -36,28 +36,28 @@ from .master_event import SimpleEchoHandler
|
|
|
36
36
|
def validate_configuration() -> bool:
|
|
37
37
|
"""
|
|
38
38
|
Validate required configuration settings.
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
Returns:
|
|
41
41
|
True if configuration is valid, False otherwise
|
|
42
42
|
"""
|
|
43
|
-
|
|
43
|
+
|
|
44
44
|
# Check required WhatsApp credentials
|
|
45
45
|
missing_configs = []
|
|
46
|
-
|
|
46
|
+
|
|
47
47
|
if not settings.wp_access_token:
|
|
48
48
|
missing_configs.append("WP_ACCESS_TOKEN")
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
if not settings.wp_phone_id:
|
|
51
51
|
missing_configs.append("WP_PHONE_ID")
|
|
52
|
-
|
|
52
|
+
|
|
53
53
|
if not settings.wp_bid:
|
|
54
54
|
missing_configs.append("WP_BID")
|
|
55
|
-
|
|
55
|
+
|
|
56
56
|
if missing_configs:
|
|
57
57
|
logger.error(f"❌ Missing required configuration: {', '.join(missing_configs)}")
|
|
58
58
|
logger.error("💡 Create a .env file with the required credentials")
|
|
59
59
|
return False
|
|
60
|
-
|
|
60
|
+
|
|
61
61
|
logger.info("✅ Configuration validation passed")
|
|
62
62
|
return True
|
|
63
63
|
|
|
@@ -69,14 +69,20 @@ def display_startup_information() -> None:
|
|
|
69
69
|
print(f"🚀 Wappa v{__version__} - Simple Echo Example")
|
|
70
70
|
print("=" * 70)
|
|
71
71
|
print()
|
|
72
|
-
|
|
72
|
+
|
|
73
73
|
print("📋 *CONFIGURATION STATUS:*")
|
|
74
|
-
print(
|
|
75
|
-
|
|
74
|
+
print(
|
|
75
|
+
f" • Access Token: {'✅ Configured' if settings.wp_access_token else '❌ Missing'}"
|
|
76
|
+
)
|
|
77
|
+
print(
|
|
78
|
+
f" • Phone ID: {settings.wp_phone_id if settings.wp_phone_id else '❌ Missing'}"
|
|
79
|
+
)
|
|
76
80
|
print(f" • Business ID: {'✅ Configured' if settings.wp_bid else '❌ Missing'}")
|
|
77
|
-
print(
|
|
81
|
+
print(
|
|
82
|
+
f" • Environment: {'🛠️ Development' if settings.is_development else '🚀 Production'}"
|
|
83
|
+
)
|
|
78
84
|
print()
|
|
79
|
-
|
|
85
|
+
|
|
80
86
|
print("🎯 *DEMO FEATURES:*")
|
|
81
87
|
print(" • Send any text message → Get echo response")
|
|
82
88
|
print(" • Send media files → Get acknowledgment")
|
|
@@ -84,7 +90,7 @@ def display_startup_information() -> None:
|
|
|
84
90
|
print(" • Send contacts → Get contact confirmation")
|
|
85
91
|
print(" • All messages are counted and logged")
|
|
86
92
|
print()
|
|
87
|
-
|
|
93
|
+
|
|
88
94
|
print("🔧 *TECHNICAL FEATURES:*")
|
|
89
95
|
print(" • Clean WappaEventHandler implementation")
|
|
90
96
|
print(" • Proper dependency injection")
|
|
@@ -97,19 +103,19 @@ def display_startup_information() -> None:
|
|
|
97
103
|
def create_wappa_application() -> Wappa:
|
|
98
104
|
"""
|
|
99
105
|
Create and configure the Wappa application.
|
|
100
|
-
|
|
106
|
+
|
|
101
107
|
Returns:
|
|
102
108
|
Configured Wappa application instance
|
|
103
109
|
"""
|
|
104
|
-
|
|
110
|
+
|
|
105
111
|
try:
|
|
106
112
|
# Create Wappa instance with JSON cache (simple file-based cache for echo example)
|
|
107
113
|
logger.info("🏗️ Creating Wappa application with JSON cache...")
|
|
108
114
|
app = Wappa(cache="json")
|
|
109
|
-
|
|
115
|
+
|
|
110
116
|
logger.info("✅ Wappa application created successfully")
|
|
111
117
|
return app
|
|
112
|
-
|
|
118
|
+
|
|
113
119
|
except Exception as e:
|
|
114
120
|
logger.error(f"❌ Failed to create Wappa application: {e}")
|
|
115
121
|
raise
|
|
@@ -119,43 +125,45 @@ def main() -> None:
|
|
|
119
125
|
"""
|
|
120
126
|
Main application entry point.
|
|
121
127
|
"""
|
|
122
|
-
|
|
128
|
+
|
|
123
129
|
logger.info("🚀 Starting Simple Echo Example")
|
|
124
|
-
|
|
130
|
+
|
|
125
131
|
try:
|
|
126
132
|
# Display startup information
|
|
127
133
|
display_startup_information()
|
|
128
|
-
|
|
134
|
+
|
|
129
135
|
# Validate configuration before proceeding
|
|
130
136
|
if not validate_configuration():
|
|
131
|
-
logger.error(
|
|
137
|
+
logger.error(
|
|
138
|
+
"❌ Configuration validation failed - cannot start application"
|
|
139
|
+
)
|
|
132
140
|
return
|
|
133
|
-
|
|
141
|
+
|
|
134
142
|
# Create Wappa application
|
|
135
143
|
app = create_wappa_application()
|
|
136
|
-
|
|
144
|
+
|
|
137
145
|
# Create and set the simple echo handler
|
|
138
146
|
handler = SimpleEchoHandler()
|
|
139
147
|
app.set_event_handler(handler)
|
|
140
|
-
|
|
148
|
+
|
|
141
149
|
logger.info("✅ Application initialization completed with SimpleEchoHandler")
|
|
142
|
-
|
|
150
|
+
|
|
143
151
|
print("🌐 Starting simple echo server...")
|
|
144
152
|
print("💡 Press CTRL+C to stop the server")
|
|
145
153
|
print("=" * 70)
|
|
146
154
|
print()
|
|
147
|
-
|
|
155
|
+
|
|
148
156
|
# Start the application
|
|
149
157
|
app.run()
|
|
150
|
-
|
|
158
|
+
|
|
151
159
|
except KeyboardInterrupt:
|
|
152
160
|
logger.info("👋 Application stopped by user")
|
|
153
161
|
print("\\n👋 Simple echo server stopped by user")
|
|
154
|
-
|
|
162
|
+
|
|
155
163
|
except Exception as e:
|
|
156
164
|
logger.error(f"❌ Application startup error: {e}", exc_info=True)
|
|
157
165
|
print(f"\\n❌ Server error: {e}")
|
|
158
|
-
|
|
166
|
+
|
|
159
167
|
finally:
|
|
160
168
|
logger.info("🏁 Simple echo example completed")
|
|
161
169
|
print("🏁 Simple echo example completed")
|
|
@@ -167,17 +175,17 @@ def main() -> None:
|
|
|
167
175
|
try:
|
|
168
176
|
logger.info("📦 Creating module-level Wappa application instance")
|
|
169
177
|
app = Wappa()
|
|
170
|
-
|
|
178
|
+
|
|
171
179
|
# Create and set the simple echo handler
|
|
172
180
|
handler = SimpleEchoHandler()
|
|
173
181
|
app.set_event_handler(handler)
|
|
174
|
-
|
|
182
|
+
|
|
175
183
|
logger.info("✅ Module-level application instance ready with SimpleEchoHandler")
|
|
176
|
-
|
|
184
|
+
|
|
177
185
|
except Exception as e:
|
|
178
186
|
logger.error(f"❌ Failed to create module-level app instance: {e}")
|
|
179
187
|
raise
|
|
180
188
|
|
|
181
189
|
|
|
182
190
|
if __name__ == "__main__":
|
|
183
|
-
main()
|
|
191
|
+
main()
|
|
@@ -11,9 +11,6 @@ This handler shows:
|
|
|
11
11
|
- Proper logging and error handling
|
|
12
12
|
"""
|
|
13
13
|
|
|
14
|
-
import asyncio
|
|
15
|
-
from datetime import datetime
|
|
16
|
-
|
|
17
14
|
from wappa import WappaEventHandler
|
|
18
15
|
from wappa.core.logging import get_logger
|
|
19
16
|
from wappa.webhooks import ErrorWebhook, IncomingMessageWebhook, StatusWebhook
|
|
@@ -24,7 +21,7 @@ logger = get_logger(__name__)
|
|
|
24
21
|
class SimpleEchoHandler(WappaEventHandler):
|
|
25
22
|
"""
|
|
26
23
|
Simple echo handler that replies to all messages.
|
|
27
|
-
|
|
24
|
+
|
|
28
25
|
This demonstrates the basic WappaEventHandler pattern without
|
|
29
26
|
the complexity of score modules or caching systems.
|
|
30
27
|
"""
|
|
@@ -38,18 +35,20 @@ class SimpleEchoHandler(WappaEventHandler):
|
|
|
38
35
|
async def process_message(self, webhook: IncomingMessageWebhook) -> None:
|
|
39
36
|
"""
|
|
40
37
|
Process incoming messages with simple echo functionality.
|
|
41
|
-
|
|
38
|
+
|
|
42
39
|
Args:
|
|
43
40
|
webhook: Incoming message webhook to process
|
|
44
41
|
"""
|
|
45
|
-
|
|
42
|
+
|
|
46
43
|
# Validate dependencies are properly injected
|
|
47
44
|
if not self.validate_dependencies():
|
|
48
|
-
logger.error(
|
|
45
|
+
logger.error(
|
|
46
|
+
"❌ Dependencies not properly injected - cannot process message"
|
|
47
|
+
)
|
|
49
48
|
return
|
|
50
49
|
|
|
51
50
|
self._message_count += 1
|
|
52
|
-
|
|
51
|
+
|
|
53
52
|
user_id = webhook.user.user_id
|
|
54
53
|
message_text = webhook.get_message_text()
|
|
55
54
|
message_type = webhook.get_message_type_name()
|
|
@@ -60,26 +59,34 @@ class SimpleEchoHandler(WappaEventHandler):
|
|
|
60
59
|
try:
|
|
61
60
|
# Mark message as read with typing indicator
|
|
62
61
|
await self.messenger.mark_as_read(message_id=message_id, typing=True)
|
|
63
|
-
|
|
62
|
+
|
|
64
63
|
# Handle different message types
|
|
65
|
-
await self._handle_message_by_type(
|
|
66
|
-
|
|
64
|
+
await self._handle_message_by_type(
|
|
65
|
+
webhook, user_id, message_text, message_type
|
|
66
|
+
)
|
|
67
|
+
|
|
67
68
|
except Exception as e:
|
|
68
69
|
logger.error(f"❌ Error processing message: {e}", exc_info=True)
|
|
69
70
|
|
|
70
71
|
async def _handle_message_by_type(
|
|
71
|
-
self,
|
|
72
|
-
webhook: IncomingMessageWebhook,
|
|
73
|
-
user_id: str,
|
|
74
|
-
message_text: str,
|
|
75
|
-
message_type: str
|
|
72
|
+
self,
|
|
73
|
+
webhook: IncomingMessageWebhook,
|
|
74
|
+
user_id: str,
|
|
75
|
+
message_text: str,
|
|
76
|
+
message_type: str,
|
|
76
77
|
) -> None:
|
|
77
78
|
"""Handle message based on its type."""
|
|
78
|
-
|
|
79
|
+
|
|
79
80
|
try:
|
|
80
81
|
if message_type.lower() == "text":
|
|
81
82
|
await self._handle_text_message(webhook, user_id, message_text)
|
|
82
|
-
elif message_type.lower() in [
|
|
83
|
+
elif message_type.lower() in [
|
|
84
|
+
"image",
|
|
85
|
+
"video",
|
|
86
|
+
"audio",
|
|
87
|
+
"document",
|
|
88
|
+
"sticker",
|
|
89
|
+
]:
|
|
83
90
|
await self._handle_media_message(webhook, user_id, message_type)
|
|
84
91
|
elif message_type.lower() == "location":
|
|
85
92
|
await self._handle_location_message(webhook, user_id)
|
|
@@ -87,103 +94,115 @@ class SimpleEchoHandler(WappaEventHandler):
|
|
|
87
94
|
await self._handle_contact_message(webhook, user_id)
|
|
88
95
|
else:
|
|
89
96
|
await self._handle_other_message(webhook, user_id, message_type)
|
|
90
|
-
|
|
97
|
+
|
|
91
98
|
except Exception as e:
|
|
92
99
|
logger.error(f"❌ Error handling {message_type} message: {e}")
|
|
93
100
|
|
|
94
|
-
async def _handle_text_message(
|
|
101
|
+
async def _handle_text_message(
|
|
102
|
+
self, webhook: IncomingMessageWebhook, user_id: str, message_text: str
|
|
103
|
+
) -> None:
|
|
95
104
|
"""Handle text messages with simple echo."""
|
|
96
|
-
|
|
105
|
+
|
|
97
106
|
logger.info(f"💬 Echoing text: '{message_text}'")
|
|
98
|
-
|
|
107
|
+
|
|
99
108
|
# Create echo response
|
|
100
109
|
echo_response = f"🔄 Echo: {message_text}"
|
|
101
|
-
|
|
110
|
+
|
|
102
111
|
# Add some metadata for the first few messages
|
|
103
112
|
if self._message_count <= 3:
|
|
104
|
-
echo_response +=
|
|
113
|
+
echo_response += (
|
|
114
|
+
f"\n\n📊 Message #{self._message_count} processed successfully!"
|
|
115
|
+
)
|
|
105
116
|
if self._message_count == 1:
|
|
106
117
|
echo_response += "\n👋 Welcome to the Simple Echo Example!"
|
|
107
|
-
|
|
118
|
+
|
|
108
119
|
# Send echo response
|
|
109
120
|
result = await self.messenger.send_text(
|
|
110
121
|
recipient=user_id,
|
|
111
122
|
text=echo_response,
|
|
112
|
-
reply_to_message_id=webhook.message.message_id
|
|
123
|
+
reply_to_message_id=webhook.message.message_id,
|
|
113
124
|
)
|
|
114
|
-
|
|
125
|
+
|
|
115
126
|
if result.success:
|
|
116
127
|
logger.info(f"✅ Text echo sent successfully: {result.message_id}")
|
|
117
128
|
else:
|
|
118
129
|
logger.error(f"❌ Text echo failed: {result.error}")
|
|
119
130
|
|
|
120
|
-
async def _handle_media_message(
|
|
131
|
+
async def _handle_media_message(
|
|
132
|
+
self, webhook: IncomingMessageWebhook, user_id: str, message_type: str
|
|
133
|
+
) -> None:
|
|
121
134
|
"""Handle media messages."""
|
|
122
|
-
|
|
135
|
+
|
|
123
136
|
logger.info(f"🎬 Processing {message_type} message")
|
|
124
|
-
|
|
137
|
+
|
|
125
138
|
response = f"📁 {message_type.title()} received! Simple echo doesn't download media, but message was processed successfully.\n\n📊 Total messages: {self._message_count}"
|
|
126
|
-
|
|
139
|
+
|
|
127
140
|
result = await self.messenger.send_text(
|
|
128
141
|
recipient=user_id,
|
|
129
142
|
text=response,
|
|
130
|
-
reply_to_message_id=webhook.message.message_id
|
|
143
|
+
reply_to_message_id=webhook.message.message_id,
|
|
131
144
|
)
|
|
132
|
-
|
|
145
|
+
|
|
133
146
|
if result.success:
|
|
134
147
|
logger.info(f"✅ {message_type} response sent: {result.message_id}")
|
|
135
148
|
else:
|
|
136
149
|
logger.error(f"❌ {message_type} response failed: {result.error}")
|
|
137
150
|
|
|
138
|
-
async def _handle_location_message(
|
|
151
|
+
async def _handle_location_message(
|
|
152
|
+
self, webhook: IncomingMessageWebhook, user_id: str
|
|
153
|
+
) -> None:
|
|
139
154
|
"""Handle location messages."""
|
|
140
|
-
|
|
155
|
+
|
|
141
156
|
logger.info("📍 Processing location message")
|
|
142
|
-
|
|
157
|
+
|
|
143
158
|
response = f"📍 Location received! Thanks for sharing your location.\n\n📊 Total messages: {self._message_count}"
|
|
144
|
-
|
|
159
|
+
|
|
145
160
|
result = await self.messenger.send_text(
|
|
146
161
|
recipient=user_id,
|
|
147
162
|
text=response,
|
|
148
|
-
reply_to_message_id=webhook.message.message_id
|
|
163
|
+
reply_to_message_id=webhook.message.message_id,
|
|
149
164
|
)
|
|
150
|
-
|
|
165
|
+
|
|
151
166
|
if result.success:
|
|
152
167
|
logger.info(f"✅ Location response sent: {result.message_id}")
|
|
153
168
|
else:
|
|
154
169
|
logger.error(f"❌ Location response failed: {result.error}")
|
|
155
170
|
|
|
156
|
-
async def _handle_contact_message(
|
|
171
|
+
async def _handle_contact_message(
|
|
172
|
+
self, webhook: IncomingMessageWebhook, user_id: str
|
|
173
|
+
) -> None:
|
|
157
174
|
"""Handle contact messages."""
|
|
158
|
-
|
|
175
|
+
|
|
159
176
|
logger.info("👥 Processing contact message")
|
|
160
|
-
|
|
177
|
+
|
|
161
178
|
response = f"👥 Contact shared! Thanks for the contact information.\n\n📊 Total messages: {self._message_count}"
|
|
162
|
-
|
|
179
|
+
|
|
163
180
|
result = await self.messenger.send_text(
|
|
164
181
|
recipient=user_id,
|
|
165
182
|
text=response,
|
|
166
|
-
reply_to_message_id=webhook.message.message_id
|
|
183
|
+
reply_to_message_id=webhook.message.message_id,
|
|
167
184
|
)
|
|
168
|
-
|
|
185
|
+
|
|
169
186
|
if result.success:
|
|
170
187
|
logger.info(f"✅ Contact response sent: {result.message_id}")
|
|
171
188
|
else:
|
|
172
189
|
logger.error(f"❌ Contact response failed: {result.error}")
|
|
173
190
|
|
|
174
|
-
async def _handle_other_message(
|
|
191
|
+
async def _handle_other_message(
|
|
192
|
+
self, webhook: IncomingMessageWebhook, user_id: str, message_type: str
|
|
193
|
+
) -> None:
|
|
175
194
|
"""Handle other message types."""
|
|
176
|
-
|
|
195
|
+
|
|
177
196
|
logger.info(f"❓ Processing unsupported message type: {message_type}")
|
|
178
|
-
|
|
197
|
+
|
|
179
198
|
response = f"📨 {message_type.title()} message received! This message type is not fully supported yet, but was processed successfully.\n\n📊 Total messages: {self._message_count}"
|
|
180
|
-
|
|
199
|
+
|
|
181
200
|
result = await self.messenger.send_text(
|
|
182
201
|
recipient=user_id,
|
|
183
202
|
text=response,
|
|
184
|
-
reply_to_message_id=webhook.message.message_id
|
|
203
|
+
reply_to_message_id=webhook.message.message_id,
|
|
185
204
|
)
|
|
186
|
-
|
|
205
|
+
|
|
187
206
|
if result.success:
|
|
188
207
|
logger.info(f"✅ {message_type} response sent: {result.message_id}")
|
|
189
208
|
else:
|
|
@@ -191,19 +210,21 @@ class SimpleEchoHandler(WappaEventHandler):
|
|
|
191
210
|
|
|
192
211
|
async def process_status(self, webhook: StatusWebhook) -> None:
|
|
193
212
|
"""Process status webhooks with simple logging."""
|
|
194
|
-
|
|
213
|
+
|
|
195
214
|
status_value = webhook.status.value
|
|
196
215
|
recipient = webhook.recipient_id
|
|
197
|
-
|
|
198
|
-
logger.info(
|
|
216
|
+
|
|
217
|
+
logger.info(
|
|
218
|
+
f"📊 Status update: {status_value.upper()} for recipient {recipient}"
|
|
219
|
+
)
|
|
199
220
|
|
|
200
221
|
async def process_error(self, webhook: ErrorWebhook) -> None:
|
|
201
222
|
"""Process error webhooks with simple logging."""
|
|
202
|
-
|
|
223
|
+
|
|
203
224
|
error_count = webhook.get_error_count()
|
|
204
225
|
primary_error = webhook.get_primary_error()
|
|
205
|
-
|
|
226
|
+
|
|
206
227
|
logger.error(
|
|
207
228
|
f"🚨 Platform error: {error_count} errors, "
|
|
208
229
|
f"primary: {primary_error.error_code} - {primary_error.error_title}"
|
|
209
|
-
)
|
|
230
|
+
)
|