wappa 0.1.6__py3-none-any.whl → 0.1.7__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 +13 -69
- wappa/cli/examples/init/.gitignore +69 -0
- wappa/cli/examples/init/pyproject.toml +7 -0
- wappa/cli/examples/json_cache_example/.gitignore +69 -0
- wappa/cli/examples/json_cache_example/README.md +190 -0
- wappa/cli/examples/openai_transcript/.gitignore +10 -0
- wappa/cli/examples/openai_transcript/README.md +0 -0
- wappa/cli/examples/redis_cache_example/.gitignore +69 -0
- wappa/cli/examples/redis_cache_example/README.md +0 -0
- wappa/cli/examples/simple_echo_example/.gitignore +69 -0
- wappa/cli/examples/simple_echo_example/.python-version +1 -0
- wappa/cli/examples/simple_echo_example/README.md +0 -0
- wappa/cli/examples/simple_echo_example/pyproject.toml +9 -0
- wappa/cli/examples/wappa_full_example/.dockerignore +171 -0
- wappa/cli/examples/wappa_full_example/.gitignore +10 -0
- wappa/cli/examples/wappa_full_example/Dockerfile +85 -0
- wappa/cli/examples/wappa_full_example/RAILWAY_DEPLOYMENT.md +366 -0
- wappa/cli/examples/wappa_full_example/README.md +322 -0
- wappa/cli/examples/wappa_full_example/docker-compose.yml +170 -0
- wappa/cli/examples/wappa_full_example/nginx.conf +177 -0
- wappa/cli/examples/wappa_full_example/railway.toml +30 -0
- wappa/cli/main.py +346 -22
- wappa/cli/templates/__init__.py.template +0 -0
- wappa/cli/templates/env.template +37 -0
- wappa/cli/templates/gitignore.template +165 -0
- wappa/cli/templates/main.py.template +8 -0
- wappa/cli/templates/master_event.py.template +8 -0
- wappa/core/__init__.py +86 -3
- wappa/core/plugins/wappa_core_plugin.py +15 -5
- wappa/database/__init__.py +16 -4
- wappa/domain/interfaces/media_interface.py +57 -3
- wappa/domain/models/media_result.py +43 -0
- wappa/messaging/__init__.py +53 -3
- wappa/messaging/whatsapp/handlers/whatsapp_media_handler.py +112 -4
- wappa/models/__init__.py +103 -0
- wappa/persistence/__init__.py +55 -0
- wappa/webhooks/__init__.py +53 -4
- wappa/webhooks/whatsapp/__init__.py +57 -3
- wappa/webhooks/whatsapp/status_models.py +10 -0
- {wappa-0.1.6.dist-info → wappa-0.1.7.dist-info}/METADATA +1 -1
- {wappa-0.1.6.dist-info → wappa-0.1.7.dist-info}/RECORD +44 -23
- wappa/domain/interfaces/webhooks/__init__.py +0 -1
- wappa/persistence/json/handlers/__init__.py +0 -1
- wappa/persistence/json/handlers/utils/__init__.py +0 -1
- wappa/persistence/memory/handlers/__init__.py +0 -1
- wappa/persistence/memory/handlers/utils/__init__.py +0 -1
- wappa/schemas/webhooks/__init__.py +0 -3
- {wappa-0.1.6.dist-info → wappa-0.1.7.dist-info}/WHEEL +0 -0
- {wappa-0.1.6.dist-info → wappa-0.1.7.dist-info}/entry_points.txt +0 -0
- {wappa-0.1.6.dist-info → wappa-0.1.7.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
# Wappa Full Example
|
|
2
|
+
|
|
3
|
+
A comprehensive demonstration of the **Wappa Framework** showcasing all WhatsApp Business API features including message handling, interactive commands, state management, and media processing.
|
|
4
|
+
|
|
5
|
+
## 🌟 Overview
|
|
6
|
+
|
|
7
|
+
This example demonstrates a production-ready WhatsApp Business application that showcases:
|
|
8
|
+
|
|
9
|
+
- ✅ **Complete message type handling** with metadata extraction
|
|
10
|
+
- 🔘 **Interactive commands** with button and list demonstrations
|
|
11
|
+
- 🗃️ **State management** with TTL and Redis caching
|
|
12
|
+
- 📎 **Media relay functionality** using media_id
|
|
13
|
+
- 👥 **User tracking and analytics** with comprehensive profiles
|
|
14
|
+
- 🎉 **Welcome messages** for first-time users
|
|
15
|
+
- 🏗️ **Professional architecture** with clean code patterns
|
|
16
|
+
- 📊 **Performance monitoring** and statistics tracking
|
|
17
|
+
|
|
18
|
+
## 🚀 Quick Start
|
|
19
|
+
|
|
20
|
+
### Prerequisites
|
|
21
|
+
|
|
22
|
+
- Python 3.12+
|
|
23
|
+
- Redis server running locally or remotely
|
|
24
|
+
- WhatsApp Business API access token and phone number ID
|
|
25
|
+
|
|
26
|
+
### Installation
|
|
27
|
+
|
|
28
|
+
1. **Clone or navigate to the project:**
|
|
29
|
+
```bash
|
|
30
|
+
cd wappa_examples/wappa_full_example
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
2. **Install dependencies:**
|
|
34
|
+
```bash
|
|
35
|
+
uv sync
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
3. **Create environment file:**
|
|
39
|
+
```bash
|
|
40
|
+
cp .env.example .env
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
4. **Configure your WhatsApp Business API credentials in `.env`:**
|
|
44
|
+
```env
|
|
45
|
+
WP_ACCESS_TOKEN=your_access_token_here
|
|
46
|
+
WP_PHONE_ID=your_phone_number_id_here
|
|
47
|
+
WP_BID=your_business_id_here
|
|
48
|
+
REDIS_URL=redis://localhost:6379
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
5. **Add media files (optional):**
|
|
52
|
+
- Add `kitty.png` and `puppy.png` to `app/media/buttons/`
|
|
53
|
+
- Add sample files to `app/media/list/` (image.png, video.mp4, audio.mp3, document.pdf)
|
|
54
|
+
|
|
55
|
+
6. **Run the application:**
|
|
56
|
+
```bash
|
|
57
|
+
uv run python -m app.main
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## 🎮 Interactive Features
|
|
61
|
+
|
|
62
|
+
### Special Commands
|
|
63
|
+
|
|
64
|
+
Send these commands to your WhatsApp number to try the interactive features:
|
|
65
|
+
|
|
66
|
+
#### `/button` - Interactive Button Demo
|
|
67
|
+
- Creates buttons for "🐱 Kitty" and "🐶 Puppy"
|
|
68
|
+
- 10-minute TTL with state management
|
|
69
|
+
- Sends corresponding animal image on selection
|
|
70
|
+
- Demonstrates comprehensive metadata extraction
|
|
71
|
+
|
|
72
|
+
#### `/list` - Interactive List Demo
|
|
73
|
+
- List with Image, Video, Audio, Document options
|
|
74
|
+
- Sends actual media files based on selection
|
|
75
|
+
- Demonstrates list interaction patterns
|
|
76
|
+
|
|
77
|
+
#### `/cta` - Call-to-Action Button
|
|
78
|
+
- External link to Wappa documentation
|
|
79
|
+
- Shows CTA button implementation
|
|
80
|
+
|
|
81
|
+
#### `/location` - Location Sharing Demo
|
|
82
|
+
- Shares predefined location (Bogotá, Colombia)
|
|
83
|
+
- Demonstrates location message handling
|
|
84
|
+
|
|
85
|
+
### Message Type Handling
|
|
86
|
+
|
|
87
|
+
The application automatically handles and echoes all WhatsApp message types:
|
|
88
|
+
|
|
89
|
+
| Message Type | Response | Features |
|
|
90
|
+
|--------------|----------|----------|
|
|
91
|
+
| **Text** | Echo with "Echo - {content}" + metadata | URL detection, mention parsing |
|
|
92
|
+
| **Images/Videos/Audio/Documents** | Relay same media using media_id + metadata | File size, dimensions, duration |
|
|
93
|
+
| **Location** | Echo same coordinates + metadata | Name, address, coordinates |
|
|
94
|
+
| **Contacts** | Echo contact information + metadata | Names, phones, emails |
|
|
95
|
+
| **Interactive** | Process button/list selections + metadata | Selection IDs, titles |
|
|
96
|
+
|
|
97
|
+
## 🏗️ Architecture
|
|
98
|
+
|
|
99
|
+
### Project Structure
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
wappa_full_example/
|
|
103
|
+
├── app/
|
|
104
|
+
│ ├── handlers/ # Message, command, and state handlers
|
|
105
|
+
│ │ ├── message_handlers.py # Handle different message types
|
|
106
|
+
│ │ ├── command_handlers.py # Handle special commands
|
|
107
|
+
│ │ └── state_handlers.py # Handle interactive states
|
|
108
|
+
│ ├── models/ # Pydantic data models
|
|
109
|
+
│ │ ├── webhook_metadata.py # Metadata models per message type
|
|
110
|
+
│ │ ├── user_models.py # User profile and session models
|
|
111
|
+
│ │ └── state_models.py # Interactive state models
|
|
112
|
+
│ ├── utils/ # Utility modules
|
|
113
|
+
│ │ ├── metadata_extractor.py # Extract webhook metadata
|
|
114
|
+
│ │ ├── media_handler.py # Media download/upload
|
|
115
|
+
│ │ └── cache_utils.py # Redis cache operations
|
|
116
|
+
│ ├── media/ # Media files for demos
|
|
117
|
+
│ │ ├── buttons/ # Button response images
|
|
118
|
+
│ │ └── list/ # List response media files
|
|
119
|
+
│ ├── master_event.py # Main WappaEventHandler
|
|
120
|
+
│ └── main.py # FastAPI application
|
|
121
|
+
├── logs/ # Application logs
|
|
122
|
+
├── pyproject.toml # Project configuration
|
|
123
|
+
└── README.md # This file
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Key Components
|
|
127
|
+
|
|
128
|
+
#### 1. **Master Event Handler** (`master_event.py`)
|
|
129
|
+
- Main `WappaEventHandler` implementation
|
|
130
|
+
- Orchestrates all message processing
|
|
131
|
+
- Handles user profiles and welcome messages
|
|
132
|
+
- Manages statistics and logging
|
|
133
|
+
|
|
134
|
+
#### 2. **Message Handlers** (`handlers/message_handlers.py`)
|
|
135
|
+
- Type-specific message processing
|
|
136
|
+
- Metadata extraction and formatting
|
|
137
|
+
- Media relay functionality
|
|
138
|
+
- User activity tracking
|
|
139
|
+
|
|
140
|
+
#### 3. **Command Handlers** (`handlers/command_handlers.py`)
|
|
141
|
+
- Special command processing (`/button`, `/list`, `/cta`, `/location`)
|
|
142
|
+
- Interactive message creation
|
|
143
|
+
- State initialization with TTL
|
|
144
|
+
|
|
145
|
+
#### 4. **State Handlers** (`handlers/state_handlers.py`)
|
|
146
|
+
- Interactive state management
|
|
147
|
+
- Button and list response processing
|
|
148
|
+
- State validation and cleanup
|
|
149
|
+
- Media file serving
|
|
150
|
+
|
|
151
|
+
#### 5. **Utilities**
|
|
152
|
+
- **Metadata Extractor**: Comprehensive webhook metadata extraction
|
|
153
|
+
- **Media Handler**: Media download/upload and relay functionality
|
|
154
|
+
- **Cache Utils**: Redis operations and user management
|
|
155
|
+
|
|
156
|
+
## 📊 Features Demonstrated
|
|
157
|
+
|
|
158
|
+
### User Management
|
|
159
|
+
- **First-time user detection** with welcome messages
|
|
160
|
+
- **User profile caching** with activity tracking
|
|
161
|
+
- **Message count statistics** and interaction analytics
|
|
162
|
+
- **Command usage tracking** and behavioral insights
|
|
163
|
+
|
|
164
|
+
### State Management
|
|
165
|
+
- **TTL-based states** (10-minute expiration for interactive commands)
|
|
166
|
+
- **State validation** and error handling
|
|
167
|
+
- **Automatic cleanup** of expired states
|
|
168
|
+
- **Multi-state support** (buttons, lists, custom states)
|
|
169
|
+
|
|
170
|
+
### Message Processing
|
|
171
|
+
- **Comprehensive metadata extraction** for all message types
|
|
172
|
+
- **Media relay using media_id** for efficient bandwidth usage
|
|
173
|
+
- **Professional error handling** with user-friendly messages
|
|
174
|
+
- **Performance monitoring** with processing time tracking
|
|
175
|
+
|
|
176
|
+
### Interactive Features
|
|
177
|
+
- **Button workflows** with media responses
|
|
178
|
+
- **List interactions** with file serving
|
|
179
|
+
- **CTA buttons** linking to external resources
|
|
180
|
+
- **Location sharing** with predefined coordinates
|
|
181
|
+
|
|
182
|
+
## 🛠️ Development
|
|
183
|
+
|
|
184
|
+
### Running in Development
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
# Start with auto-reload
|
|
188
|
+
uvicorn app.main:app --reload
|
|
189
|
+
|
|
190
|
+
# Or use uv run
|
|
191
|
+
uv run python -m app.main
|
|
192
|
+
|
|
193
|
+
# With specific host/port
|
|
194
|
+
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Code Quality
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
# Format code
|
|
201
|
+
uv run ruff format .
|
|
202
|
+
|
|
203
|
+
# Lint code
|
|
204
|
+
uv run ruff check .
|
|
205
|
+
|
|
206
|
+
# Type checking
|
|
207
|
+
uv run mypy app/
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Testing
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
# Run tests (when test suite is added)
|
|
214
|
+
uv run pytest
|
|
215
|
+
|
|
216
|
+
# With coverage
|
|
217
|
+
uv run pytest --cov=app tests/
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## 📈 Monitoring and Analytics
|
|
221
|
+
|
|
222
|
+
The application provides comprehensive statistics:
|
|
223
|
+
|
|
224
|
+
### Handler Statistics
|
|
225
|
+
- Total messages processed
|
|
226
|
+
- Success/failure rates
|
|
227
|
+
- Processing time metrics
|
|
228
|
+
- Feature usage analytics
|
|
229
|
+
|
|
230
|
+
### User Analytics
|
|
231
|
+
- New user registrations
|
|
232
|
+
- Message type distribution
|
|
233
|
+
- Command usage patterns
|
|
234
|
+
- Interactive feature engagement
|
|
235
|
+
|
|
236
|
+
### Cache Statistics
|
|
237
|
+
- Redis operation metrics
|
|
238
|
+
- User profile hit rates
|
|
239
|
+
- State management efficiency
|
|
240
|
+
- Memory usage patterns
|
|
241
|
+
|
|
242
|
+
## 🔧 Configuration
|
|
243
|
+
|
|
244
|
+
### Environment Variables
|
|
245
|
+
|
|
246
|
+
| Variable | Description | Required | Default |
|
|
247
|
+
|----------|-------------|----------|---------|
|
|
248
|
+
| `WP_ACCESS_TOKEN` | WhatsApp Business API access token | Yes | - |
|
|
249
|
+
| `WP_PHONE_ID` | WhatsApp phone number ID | Yes | - |
|
|
250
|
+
| `WP_BID` | WhatsApp Business ID | Yes | - |
|
|
251
|
+
| `REDIS_URL` | Redis connection URL | Yes | `redis://localhost:6379` |
|
|
252
|
+
| `LOG_LEVEL` | Application log level | No | `INFO` |
|
|
253
|
+
| `ENVIRONMENT` | Environment (dev/prod) | No | `development` |
|
|
254
|
+
|
|
255
|
+
### Redis Configuration
|
|
256
|
+
|
|
257
|
+
The application uses Redis for:
|
|
258
|
+
- **User profiles** (24-hour TTL)
|
|
259
|
+
- **Interactive states** (10-minute TTL)
|
|
260
|
+
- **Message history** (7-day TTL)
|
|
261
|
+
- **Application statistics** (persistent)
|
|
262
|
+
|
|
263
|
+
## 🎯 Use Cases
|
|
264
|
+
|
|
265
|
+
This example demonstrates patterns useful for:
|
|
266
|
+
|
|
267
|
+
### Business Applications
|
|
268
|
+
- **Customer support** with interactive menus
|
|
269
|
+
- **Order management** with button workflows
|
|
270
|
+
- **Appointment booking** with list selections
|
|
271
|
+
- **Product catalogs** with media sharing
|
|
272
|
+
|
|
273
|
+
### Educational Applications
|
|
274
|
+
- **Interactive tutorials** with step-by-step guidance
|
|
275
|
+
- **Quiz systems** with button-based answers
|
|
276
|
+
- **File sharing** for educational resources
|
|
277
|
+
- **Location sharing** for campus navigation
|
|
278
|
+
|
|
279
|
+
### E-commerce Applications
|
|
280
|
+
- **Product browsing** with media catalogs
|
|
281
|
+
- **Order confirmation** with interactive buttons
|
|
282
|
+
- **Payment flows** with CTA buttons
|
|
283
|
+
- **Delivery tracking** with location updates
|
|
284
|
+
|
|
285
|
+
## 📚 Learning Resources
|
|
286
|
+
|
|
287
|
+
### Wappa Framework
|
|
288
|
+
- [Documentation](https://wappa.mimeia.com/docs)
|
|
289
|
+
- [GitHub Repository](https://github.com/mimeia/wappa)
|
|
290
|
+
- [API Reference](https://wappa.mimeia.com/docs/api)
|
|
291
|
+
|
|
292
|
+
### WhatsApp Business API
|
|
293
|
+
- [Official Documentation](https://developers.facebook.com/docs/whatsapp)
|
|
294
|
+
- [Message Types](https://developers.facebook.com/docs/whatsapp/cloud-api/messages)
|
|
295
|
+
- [Interactive Messages](https://developers.facebook.com/docs/whatsapp/cloud-api/messages/interactive-messages)
|
|
296
|
+
|
|
297
|
+
## 🤝 Contributing
|
|
298
|
+
|
|
299
|
+
This example is part of the Wappa framework project. To contribute:
|
|
300
|
+
|
|
301
|
+
1. Fork the repository
|
|
302
|
+
2. Create a feature branch
|
|
303
|
+
3. Make your changes
|
|
304
|
+
4. Add tests if applicable
|
|
305
|
+
5. Submit a pull request
|
|
306
|
+
|
|
307
|
+
## 📝 License
|
|
308
|
+
|
|
309
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
310
|
+
|
|
311
|
+
## 🙋♀️ Support
|
|
312
|
+
|
|
313
|
+
- **Documentation**: [wappa.mimeia.com](https://wappa.mimeia.com)
|
|
314
|
+
- **Issues**: [GitHub Issues](https://github.com/mimeia/wappa/issues)
|
|
315
|
+
- **Community**: [Discord](https://discord.gg/wappa)
|
|
316
|
+
- **Email**: support@mimeia.com
|
|
317
|
+
|
|
318
|
+
---
|
|
319
|
+
|
|
320
|
+
**Built with ❤️ using the Wappa Framework**
|
|
321
|
+
|
|
322
|
+
**This comprehensive example showcases production-ready patterns for building sophisticated WhatsApp Business applications. Use it as a foundation for your own projects and explore the full potential of conversational interfaces.**
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# ================================================================
|
|
2
|
+
# WAPPA FULL EXAMPLE - DOCKER COMPOSE CONFIGURATION
|
|
3
|
+
# ================================================================
|
|
4
|
+
# Production-ready deployment with Redis, health checks, and scaling
|
|
5
|
+
# ================================================================
|
|
6
|
+
|
|
7
|
+
version: '3.8'
|
|
8
|
+
|
|
9
|
+
services:
|
|
10
|
+
# ================================================================
|
|
11
|
+
# Redis Cache Service
|
|
12
|
+
# ================================================================
|
|
13
|
+
redis:
|
|
14
|
+
image: redis:7.2-alpine
|
|
15
|
+
container_name: wappa-redis
|
|
16
|
+
restart: unless-stopped
|
|
17
|
+
command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru
|
|
18
|
+
ports:
|
|
19
|
+
- "6379:6379"
|
|
20
|
+
volumes:
|
|
21
|
+
- redis_data:/data
|
|
22
|
+
- ./redis.conf:/etc/redis/redis.conf:ro
|
|
23
|
+
networks:
|
|
24
|
+
- wappa-network
|
|
25
|
+
healthcheck:
|
|
26
|
+
test: ["CMD", "redis-cli", "ping"]
|
|
27
|
+
interval: 10s
|
|
28
|
+
timeout: 3s
|
|
29
|
+
retries: 3
|
|
30
|
+
start_period: 10s
|
|
31
|
+
logging:
|
|
32
|
+
driver: "json-file"
|
|
33
|
+
options:
|
|
34
|
+
max-size: "10m"
|
|
35
|
+
max-file: "3"
|
|
36
|
+
|
|
37
|
+
# ================================================================
|
|
38
|
+
# Wappa Application Service
|
|
39
|
+
# ================================================================
|
|
40
|
+
wappa-app:
|
|
41
|
+
build:
|
|
42
|
+
context: .
|
|
43
|
+
dockerfile: Dockerfile
|
|
44
|
+
args:
|
|
45
|
+
BUILD_DATE: ${BUILD_DATE:-2024-01-01}
|
|
46
|
+
VCS_REF: ${VCS_REF:-dev}
|
|
47
|
+
image: wappa-full-example:latest
|
|
48
|
+
container_name: wappa-app
|
|
49
|
+
restart: unless-stopped
|
|
50
|
+
ports:
|
|
51
|
+
- "8000:8000"
|
|
52
|
+
environment:
|
|
53
|
+
# Production environment variables
|
|
54
|
+
ENVIRONMENT: PROD
|
|
55
|
+
LOG_LEVEL: INFO
|
|
56
|
+
PORT: 8000
|
|
57
|
+
|
|
58
|
+
# Redis configuration
|
|
59
|
+
REDIS_URL: redis://redis:6379/
|
|
60
|
+
REDIS_MAX_CONNECTIONS: 64
|
|
61
|
+
|
|
62
|
+
# WhatsApp API credentials (from .env file)
|
|
63
|
+
WP_ACCESS_TOKEN: ${WP_ACCESS_TOKEN}
|
|
64
|
+
WP_PHONE_ID: ${WP_PHONE_ID}
|
|
65
|
+
WP_BID: ${WP_BID}
|
|
66
|
+
WHATSAPP_WEBHOOK_VERIFY_TOKEN: ${WHATSAPP_WEBHOOK_VERIFY_TOKEN}
|
|
67
|
+
|
|
68
|
+
# Optional AI tools
|
|
69
|
+
OPENAI_API_KEY: ${OPENAI_API_KEY:-}
|
|
70
|
+
|
|
71
|
+
# Framework configuration
|
|
72
|
+
BASE_URL: https://graph.facebook.com/
|
|
73
|
+
API_VERSION: v23.0
|
|
74
|
+
TIME_ZONE: America/Bogota
|
|
75
|
+
volumes:
|
|
76
|
+
# Persistent logs
|
|
77
|
+
- app_logs:/app/logs
|
|
78
|
+
# Media files (if you want to persist them)
|
|
79
|
+
- app_media:/app/media
|
|
80
|
+
networks:
|
|
81
|
+
- wappa-network
|
|
82
|
+
depends_on:
|
|
83
|
+
redis:
|
|
84
|
+
condition: service_healthy
|
|
85
|
+
healthcheck:
|
|
86
|
+
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
|
|
87
|
+
interval: 30s
|
|
88
|
+
timeout: 10s
|
|
89
|
+
retries: 3
|
|
90
|
+
start_period: 40s
|
|
91
|
+
logging:
|
|
92
|
+
driver: "json-file"
|
|
93
|
+
options:
|
|
94
|
+
max-size: "50m"
|
|
95
|
+
max-file: "5"
|
|
96
|
+
|
|
97
|
+
# ================================================================
|
|
98
|
+
# Nginx Reverse Proxy (Optional - for SSL termination)
|
|
99
|
+
# ================================================================
|
|
100
|
+
nginx:
|
|
101
|
+
image: nginx:alpine
|
|
102
|
+
container_name: wappa-nginx
|
|
103
|
+
restart: unless-stopped
|
|
104
|
+
ports:
|
|
105
|
+
- "80:80"
|
|
106
|
+
- "443:443"
|
|
107
|
+
volumes:
|
|
108
|
+
- ./nginx.conf:/etc/nginx/nginx.conf:ro
|
|
109
|
+
- ./ssl:/etc/ssl/certs:ro
|
|
110
|
+
- nginx_logs:/var/log/nginx
|
|
111
|
+
networks:
|
|
112
|
+
- wappa-network
|
|
113
|
+
depends_on:
|
|
114
|
+
- wappa-app
|
|
115
|
+
profiles:
|
|
116
|
+
- nginx
|
|
117
|
+
logging:
|
|
118
|
+
driver: "json-file"
|
|
119
|
+
options:
|
|
120
|
+
max-size: "10m"
|
|
121
|
+
max-file: "3"
|
|
122
|
+
|
|
123
|
+
# ================================================================
|
|
124
|
+
# Networks
|
|
125
|
+
# ================================================================
|
|
126
|
+
networks:
|
|
127
|
+
wappa-network:
|
|
128
|
+
driver: bridge
|
|
129
|
+
name: wappa-network
|
|
130
|
+
|
|
131
|
+
# ================================================================
|
|
132
|
+
# Persistent Volumes
|
|
133
|
+
# ================================================================
|
|
134
|
+
volumes:
|
|
135
|
+
redis_data:
|
|
136
|
+
driver: local
|
|
137
|
+
name: wappa-redis-data
|
|
138
|
+
app_logs:
|
|
139
|
+
driver: local
|
|
140
|
+
name: wappa-app-logs
|
|
141
|
+
app_media:
|
|
142
|
+
driver: local
|
|
143
|
+
name: wappa-app-media
|
|
144
|
+
nginx_logs:
|
|
145
|
+
driver: local
|
|
146
|
+
name: wappa-nginx-logs
|
|
147
|
+
|
|
148
|
+
# ================================================================
|
|
149
|
+
# DEPLOYMENT COMMANDS:
|
|
150
|
+
# ================================================================
|
|
151
|
+
# Development:
|
|
152
|
+
# docker-compose up -d
|
|
153
|
+
#
|
|
154
|
+
# Production:
|
|
155
|
+
# docker-compose --profile nginx up -d
|
|
156
|
+
#
|
|
157
|
+
# Scaling:
|
|
158
|
+
# docker-compose up --scale wappa-app=3 -d
|
|
159
|
+
#
|
|
160
|
+
# Monitoring:
|
|
161
|
+
# docker-compose logs -f wappa-app
|
|
162
|
+
# docker-compose ps
|
|
163
|
+
#
|
|
164
|
+
# Health Checks:
|
|
165
|
+
# curl http://localhost:8000/health
|
|
166
|
+
# docker-compose exec wappa-app curl http://localhost:8000/health/detailed
|
|
167
|
+
#
|
|
168
|
+
# Cleanup:
|
|
169
|
+
# docker-compose down -v
|
|
170
|
+
# ================================================================
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# ================================================================
|
|
2
|
+
# NGINX REVERSE PROXY CONFIGURATION FOR WAPPA FULL EXAMPLE
|
|
3
|
+
# ================================================================
|
|
4
|
+
|
|
5
|
+
events {
|
|
6
|
+
worker_connections 1024;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
http {
|
|
10
|
+
include /etc/nginx/mime.types;
|
|
11
|
+
default_type application/octet-stream;
|
|
12
|
+
|
|
13
|
+
# Logging
|
|
14
|
+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
|
15
|
+
'$status $body_bytes_sent "$http_referer" '
|
|
16
|
+
'"$http_user_agent" "$http_x_forwarded_for"';
|
|
17
|
+
|
|
18
|
+
access_log /var/log/nginx/access.log main;
|
|
19
|
+
error_log /var/log/nginx/error.log warn;
|
|
20
|
+
|
|
21
|
+
# Basic settings
|
|
22
|
+
sendfile on;
|
|
23
|
+
tcp_nopush on;
|
|
24
|
+
tcp_nodelay on;
|
|
25
|
+
keepalive_timeout 65;
|
|
26
|
+
types_hash_max_size 2048;
|
|
27
|
+
client_max_body_size 10M;
|
|
28
|
+
|
|
29
|
+
# Gzip compression
|
|
30
|
+
gzip on;
|
|
31
|
+
gzip_vary on;
|
|
32
|
+
gzip_min_length 1024;
|
|
33
|
+
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
|
|
34
|
+
|
|
35
|
+
# Rate limiting
|
|
36
|
+
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
|
|
37
|
+
limit_req_zone $binary_remote_addr zone=webhook:10m rate=50r/s;
|
|
38
|
+
|
|
39
|
+
# Upstream backend
|
|
40
|
+
upstream wappa_backend {
|
|
41
|
+
server wappa-app:8000 max_fails=3 fail_timeout=30s;
|
|
42
|
+
# Add more servers for load balancing:
|
|
43
|
+
# server wappa-app-2:8000 max_fails=3 fail_timeout=30s;
|
|
44
|
+
# server wappa-app-3:8000 max_fails=3 fail_timeout=30s;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
# HTTP server (redirect to HTTPS)
|
|
48
|
+
server {
|
|
49
|
+
listen 80;
|
|
50
|
+
server_name _;
|
|
51
|
+
|
|
52
|
+
# Health check endpoint
|
|
53
|
+
location /nginx-health {
|
|
54
|
+
access_log off;
|
|
55
|
+
return 200 "healthy\n";
|
|
56
|
+
add_header Content-Type text/plain;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
# Redirect all HTTP traffic to HTTPS
|
|
60
|
+
location / {
|
|
61
|
+
return 301 https://$host$request_uri;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
# HTTPS server
|
|
66
|
+
server {
|
|
67
|
+
listen 443 ssl http2;
|
|
68
|
+
server_name your-domain.com; # Replace with your domain
|
|
69
|
+
|
|
70
|
+
# SSL configuration
|
|
71
|
+
ssl_certificate /etc/ssl/certs/cert.pem;
|
|
72
|
+
ssl_certificate_key /etc/ssl/certs/key.pem;
|
|
73
|
+
ssl_session_timeout 1d;
|
|
74
|
+
ssl_session_cache shared:MozTLS:10m;
|
|
75
|
+
ssl_session_tickets off;
|
|
76
|
+
|
|
77
|
+
# Modern SSL configuration
|
|
78
|
+
ssl_protocols TLSv1.2 TLSv1.3;
|
|
79
|
+
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384;
|
|
80
|
+
ssl_prefer_server_ciphers off;
|
|
81
|
+
|
|
82
|
+
# Security headers
|
|
83
|
+
add_header Strict-Transport-Security "max-age=63072000" always;
|
|
84
|
+
add_header X-Frame-Options DENY;
|
|
85
|
+
add_header X-Content-Type-Options nosniff;
|
|
86
|
+
add_header X-XSS-Protection "1; mode=block";
|
|
87
|
+
add_header Referrer-Policy "no-referrer-when-downgrade";
|
|
88
|
+
|
|
89
|
+
# WhatsApp webhook endpoint (high rate limit)
|
|
90
|
+
location /webhook {
|
|
91
|
+
limit_req zone=webhook burst=100 nodelay;
|
|
92
|
+
|
|
93
|
+
proxy_pass http://wappa_backend;
|
|
94
|
+
proxy_http_version 1.1;
|
|
95
|
+
proxy_set_header Upgrade $http_upgrade;
|
|
96
|
+
proxy_set_header Connection 'upgrade';
|
|
97
|
+
proxy_set_header Host $host;
|
|
98
|
+
proxy_set_header X-Real-IP $remote_addr;
|
|
99
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
100
|
+
proxy_set_header X-Forwarded-Proto $scheme;
|
|
101
|
+
proxy_cache_bypass $http_upgrade;
|
|
102
|
+
proxy_read_timeout 90;
|
|
103
|
+
proxy_send_timeout 90;
|
|
104
|
+
proxy_connect_timeout 30;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
# API endpoints (standard rate limit)
|
|
108
|
+
location /api {
|
|
109
|
+
limit_req zone=api burst=20 nodelay;
|
|
110
|
+
|
|
111
|
+
proxy_pass http://wappa_backend;
|
|
112
|
+
proxy_http_version 1.1;
|
|
113
|
+
proxy_set_header Host $host;
|
|
114
|
+
proxy_set_header X-Real-IP $remote_addr;
|
|
115
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
116
|
+
proxy_set_header X-Forwarded-Proto $scheme;
|
|
117
|
+
proxy_read_timeout 90;
|
|
118
|
+
proxy_send_timeout 90;
|
|
119
|
+
proxy_connect_timeout 30;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
# Health check endpoint
|
|
123
|
+
location /health {
|
|
124
|
+
proxy_pass http://wappa_backend;
|
|
125
|
+
proxy_http_version 1.1;
|
|
126
|
+
proxy_set_header Host $host;
|
|
127
|
+
access_log off;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
# Documentation and static files
|
|
131
|
+
location /docs {
|
|
132
|
+
proxy_pass http://wappa_backend;
|
|
133
|
+
proxy_http_version 1.1;
|
|
134
|
+
proxy_set_header Host $host;
|
|
135
|
+
proxy_set_header X-Real-IP $remote_addr;
|
|
136
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
137
|
+
proxy_set_header X-Forwarded-Proto $scheme;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
# Default location
|
|
141
|
+
location / {
|
|
142
|
+
limit_req zone=api burst=10 nodelay;
|
|
143
|
+
|
|
144
|
+
proxy_pass http://wappa_backend;
|
|
145
|
+
proxy_http_version 1.1;
|
|
146
|
+
proxy_set_header Host $host;
|
|
147
|
+
proxy_set_header X-Real-IP $remote_addr;
|
|
148
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
149
|
+
proxy_set_header X-Forwarded-Proto $scheme;
|
|
150
|
+
proxy_read_timeout 90;
|
|
151
|
+
proxy_send_timeout 90;
|
|
152
|
+
proxy_connect_timeout 30;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
# Block common bot requests
|
|
156
|
+
location ~ /\.(git|svn|hg) {
|
|
157
|
+
deny all;
|
|
158
|
+
return 404;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
location ~ /\.(env|log)$ {
|
|
162
|
+
deny all;
|
|
163
|
+
return 404;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
# ================================================================
|
|
169
|
+
# CONFIGURATION NOTES:
|
|
170
|
+
# ================================================================
|
|
171
|
+
# 1. Replace 'your-domain.com' with your actual domain
|
|
172
|
+
# 2. Add SSL certificates to ./ssl/cert.pem and ./ssl/key.pem
|
|
173
|
+
# 3. For Let's Encrypt: use certbot with nginx plugin
|
|
174
|
+
# 4. Scale backend servers by adding more upstream entries
|
|
175
|
+
# 5. Adjust rate limits based on your WhatsApp API quotas
|
|
176
|
+
# 6. Monitor nginx logs for performance tuning
|
|
177
|
+
# ================================================================
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# ================================================================
|
|
2
|
+
# RAILWAY CONFIGURATION FOR WAPPA FULL EXAMPLE
|
|
3
|
+
# ================================================================
|
|
4
|
+
|
|
5
|
+
[build]
|
|
6
|
+
builder = "dockerfile"
|
|
7
|
+
dockerfilePath = "Dockerfile"
|
|
8
|
+
|
|
9
|
+
[deploy]
|
|
10
|
+
healthcheckPath = "/health"
|
|
11
|
+
healthcheckTimeout = 300
|
|
12
|
+
restartPolicyType = "on_failure"
|
|
13
|
+
restartPolicyMaxRetries = 10
|
|
14
|
+
|
|
15
|
+
# ================================================================
|
|
16
|
+
# RAILWAY ENVIRONMENT VARIABLES (Set via Railway Dashboard)
|
|
17
|
+
# ================================================================
|
|
18
|
+
# Required variables to set in Railway:
|
|
19
|
+
#
|
|
20
|
+
# WP_ACCESS_TOKEN=your_whatsapp_access_token
|
|
21
|
+
# WP_PHONE_ID=your_phone_number_id
|
|
22
|
+
# WP_BID=your_business_id
|
|
23
|
+
# WHATSAPP_WEBHOOK_VERIFY_TOKEN=your_webhook_token
|
|
24
|
+
# REDIS_URL=redis://redis.railway.internal:6379
|
|
25
|
+
# OPENAI_API_KEY=your_openai_key (optional)
|
|
26
|
+
#
|
|
27
|
+
# Railway automatically sets:
|
|
28
|
+
# PORT (dynamic port assignment)
|
|
29
|
+
# RAILWAY_ENVIRONMENT (production/staging)
|
|
30
|
+
# ================================================================
|