wappa 0.1.6__py3-none-any.whl → 0.1.8__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 (51) hide show
  1. wappa/__init__.py +13 -69
  2. wappa/cli/examples/init/.gitignore +69 -0
  3. wappa/cli/examples/init/pyproject.toml +7 -0
  4. wappa/cli/examples/json_cache_example/.gitignore +69 -0
  5. wappa/cli/examples/json_cache_example/README.md +190 -0
  6. wappa/cli/examples/openai_transcript/.gitignore +10 -0
  7. wappa/cli/examples/openai_transcript/README.md +0 -0
  8. wappa/cli/examples/redis_cache_example/.gitignore +69 -0
  9. wappa/cli/examples/redis_cache_example/README.md +0 -0
  10. wappa/cli/examples/simple_echo_example/.gitignore +69 -0
  11. wappa/cli/examples/simple_echo_example/.python-version +1 -0
  12. wappa/cli/examples/simple_echo_example/README.md +0 -0
  13. wappa/cli/examples/simple_echo_example/pyproject.toml +9 -0
  14. wappa/cli/examples/wappa_full_example/.dockerignore +171 -0
  15. wappa/cli/examples/wappa_full_example/.gitignore +10 -0
  16. wappa/cli/examples/wappa_full_example/Dockerfile +85 -0
  17. wappa/cli/examples/wappa_full_example/RAILWAY_DEPLOYMENT.md +366 -0
  18. wappa/cli/examples/wappa_full_example/README.md +322 -0
  19. wappa/cli/examples/wappa_full_example/docker-compose.yml +170 -0
  20. wappa/cli/examples/wappa_full_example/nginx.conf +177 -0
  21. wappa/cli/examples/wappa_full_example/railway.toml +30 -0
  22. wappa/cli/main.py +346 -22
  23. wappa/cli/templates/__init__.py.template +0 -0
  24. wappa/cli/templates/env.template +37 -0
  25. wappa/cli/templates/gitignore.template +165 -0
  26. wappa/cli/templates/main.py.template +8 -0
  27. wappa/cli/templates/master_event.py.template +8 -0
  28. wappa/core/__init__.py +86 -3
  29. wappa/core/config/settings.py +34 -2
  30. wappa/core/plugins/wappa_core_plugin.py +15 -5
  31. wappa/database/__init__.py +16 -4
  32. wappa/domain/interfaces/media_interface.py +57 -3
  33. wappa/domain/models/media_result.py +43 -0
  34. wappa/messaging/__init__.py +53 -3
  35. wappa/messaging/whatsapp/handlers/whatsapp_media_handler.py +112 -4
  36. wappa/models/__init__.py +103 -0
  37. wappa/persistence/__init__.py +55 -0
  38. wappa/webhooks/__init__.py +53 -4
  39. wappa/webhooks/whatsapp/__init__.py +57 -3
  40. wappa/webhooks/whatsapp/status_models.py +10 -0
  41. {wappa-0.1.6.dist-info → wappa-0.1.8.dist-info}/METADATA +1 -1
  42. {wappa-0.1.6.dist-info → wappa-0.1.8.dist-info}/RECORD +45 -24
  43. wappa/domain/interfaces/webhooks/__init__.py +0 -1
  44. wappa/persistence/json/handlers/__init__.py +0 -1
  45. wappa/persistence/json/handlers/utils/__init__.py +0 -1
  46. wappa/persistence/memory/handlers/__init__.py +0 -1
  47. wappa/persistence/memory/handlers/utils/__init__.py +0 -1
  48. wappa/schemas/webhooks/__init__.py +0 -3
  49. {wappa-0.1.6.dist-info → wappa-0.1.8.dist-info}/WHEEL +0 -0
  50. {wappa-0.1.6.dist-info → wappa-0.1.8.dist-info}/entry_points.txt +0 -0
  51. {wappa-0.1.6.dist-info → wappa-0.1.8.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,171 @@
1
+ # ================================================================
2
+ # DOCKERIGNORE - Optimize Docker Build Context
3
+ # ================================================================
4
+
5
+ # Version Control
6
+ .git
7
+ .gitignore
8
+ .gitattributes
9
+
10
+ # Python
11
+ __pycache__/
12
+ *.py[cod]
13
+ *$py.class
14
+ *.so
15
+ .Python
16
+ env/
17
+ venv/
18
+ ENV/
19
+ env.bak/
20
+ venv.bak/
21
+ .venv/
22
+
23
+ # Distribution / packaging
24
+ .Python
25
+ build/
26
+ develop-eggs/
27
+ dist/
28
+ downloads/
29
+ eggs/
30
+ .eggs/
31
+ lib/
32
+ lib64/
33
+ parts/
34
+ sdist/
35
+ var/
36
+ wheels/
37
+ *.egg-info/
38
+ .installed.cfg
39
+ *.egg
40
+
41
+ # PyInstaller
42
+ *.manifest
43
+ *.spec
44
+
45
+ # Unit test / coverage reports
46
+ htmlcov/
47
+ .tox/
48
+ .coverage
49
+ .coverage.*
50
+ .cache
51
+ nosetests.xml
52
+ coverage.xml
53
+ *.cover
54
+ .hypothesis/
55
+ .pytest_cache/
56
+
57
+ # Environments
58
+ .env.local
59
+ .env.development
60
+ .env.test
61
+ .env.production
62
+
63
+ # IDEs
64
+ .vscode/
65
+ .idea/
66
+ *.swp
67
+ *.swo
68
+ *~
69
+
70
+ # OS generated files
71
+ .DS_Store
72
+ .DS_Store?
73
+ ._*
74
+ .Spotlight-V100
75
+ .Trashes
76
+ ehthumbs.db
77
+ Thumbs.db
78
+
79
+ # Logs (keep structure but ignore actual log files)
80
+ logs/*.log
81
+ logs/*.txt
82
+ *.log
83
+
84
+ # Temporary files
85
+ *.tmp
86
+ *.temp
87
+ .tmp/
88
+ .temp/
89
+
90
+ # Docker (keep Dockerfile for Railway)
91
+ docker-compose*.yml
92
+ nginx.conf
93
+
94
+ # Documentation (included in image via COPY if needed)
95
+ README.md
96
+ docs/
97
+ *.md
98
+
99
+ # Development files
100
+ .editorconfig
101
+ .prettierrc
102
+ .eslintrc*
103
+ .flake8
104
+ .mypy.ini
105
+ tox.ini
106
+
107
+ # CI/CD
108
+ .github/
109
+ .gitlab-ci.yml
110
+ Jenkinsfile
111
+ .travis.yml
112
+
113
+ # Node.js (if any)
114
+ node_modules/
115
+ npm-debug.log*
116
+ yarn-debug.log*
117
+ yarn-error.log*
118
+
119
+ # Media files (selectively copied)
120
+ # Keep app/media/ structure but ignore large files
121
+ app/media/**/*.mov
122
+ app/media/**/*.avi
123
+ app/media/**/*.mkv
124
+ app/media/**/*.mp4
125
+
126
+ # Backup files
127
+ *.bak
128
+ *.backup
129
+ *.old
130
+
131
+ # Database files
132
+ *.sqlite
133
+ *.sqlite3
134
+ *.db
135
+
136
+ # Cache directories
137
+ .cache/
138
+ .npm/
139
+ .yarn/
140
+
141
+ # Coverage reports
142
+ .nyc_output
143
+
144
+ # Runtime data
145
+ pids
146
+ *.pid
147
+ *.seed
148
+ *.pid.lock
149
+
150
+ # Optional npm cache directory
151
+ .npm
152
+
153
+ # Optional REPL history
154
+ .node_repl_history
155
+
156
+ # Output of 'npm pack'
157
+ *.tgz
158
+
159
+ # Yarn Integrity file
160
+ .yarn-integrity
161
+
162
+ # Security files
163
+ *.pem
164
+ *.key
165
+ *.crt
166
+ *.p12
167
+ *.pfx
168
+
169
+ # Configuration overrides
170
+ config.local.*
171
+ .env.override
@@ -0,0 +1,10 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
@@ -0,0 +1,85 @@
1
+ # ================================================================
2
+ # WAPPA FULL EXAMPLE - RAILWAY OPTIMIZED DOCKERFILE
3
+ # ================================================================
4
+ # Simple, single-stage production build optimized for Railway.app
5
+ # ================================================================
6
+
7
+ FROM python:3.12-slim
8
+
9
+ # Set build arguments
10
+ ARG BUILD_DATE
11
+ ARG VCS_REF
12
+
13
+ # Labels for metadata
14
+ LABEL org.opencontainers.image.title="Wappa Full Example"
15
+ LABEL org.opencontainers.image.description="Production-ready WhatsApp Business API application using Wappa framework"
16
+ LABEL org.opencontainers.image.version="1.0.0"
17
+ LABEL org.opencontainers.image.created=$BUILD_DATE
18
+ LABEL org.opencontainers.image.revision=$VCS_REF
19
+ LABEL org.opencontainers.image.vendor="Mimeia"
20
+ LABEL org.opencontainers.image.source="https://github.com/mimeia/wappa"
21
+ LABEL maintainer="contact@mimeia.com"
22
+
23
+ # Install system dependencies
24
+ RUN apt-get update && apt-get install -y \
25
+ curl \
26
+ ca-certificates \
27
+ && rm -rf /var/lib/apt/lists/* \
28
+ && apt-get clean
29
+
30
+ # Install uv for fast Python package management
31
+ RUN pip install --no-cache-dir uv
32
+
33
+ # Create non-root user for security
34
+ RUN groupadd --gid 1000 wappa \
35
+ && useradd --uid 1000 --gid 1000 --create-home --shell /bin/bash wappa
36
+
37
+ # Set working directory
38
+ WORKDIR /app
39
+
40
+ # Copy dependency files
41
+ COPY pyproject.toml ./
42
+ COPY uv.lock ./
43
+
44
+ # Install Python dependencies
45
+ RUN uv venv /opt/venv
46
+ ENV PATH="/opt/venv/bin:$PATH"
47
+ RUN uv pip install --no-cache-dir -r pyproject.toml
48
+
49
+ # Copy application code
50
+ COPY --chown=wappa:wappa . .
51
+
52
+ # Create required directories with proper permissions
53
+ RUN mkdir -p /app/logs /app/media/buttons /app/media/list \
54
+ && chown -R wappa:wappa /app \
55
+ && chmod -R 755 /app
56
+
57
+ # Set environment variables for production
58
+ ENV PYTHONUNBUFFERED=1
59
+ ENV PYTHONDONTWRITEBYTECODE=1
60
+ ENV ENVIRONMENT=PROD
61
+ ENV LOG_LEVEL=INFO
62
+ ENV PORT=8000
63
+
64
+ # Health check configuration
65
+ HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
66
+ CMD curl -f http://localhost:$PORT/health || exit 1
67
+
68
+ # Expose application port
69
+ EXPOSE 8000
70
+
71
+ # Switch to non-root user
72
+ USER wappa
73
+
74
+ # Railway-optimized startup command
75
+ CMD ["uv", "run", "uvicorn", "app.main:app.asgi", "--host", "0.0.0.0", "--port", "8000", "--workers", "1"]
76
+
77
+ # ================================================================
78
+ # RAILWAY DEPLOYMENT NOTES:
79
+ # ================================================================
80
+ # 1. Railway automatically detects this Dockerfile
81
+ # 2. PORT environment variable is automatically set by Railway
82
+ # 3. No need for nginx - Railway handles load balancing
83
+ # 4. Environment variables set via Railway dashboard
84
+ # 5. Redis can be added as a Railway plugin
85
+ # ================================================================
@@ -0,0 +1,366 @@
1
+ # 🚂 Railway Deployment Guide - Wappa Full Example
2
+
3
+ Simple and fast deployment of your Wappa WhatsApp Business application to Railway.app
4
+
5
+ ## 🚀 Quick Railway Deployment
6
+
7
+ ### 1. Prerequisites
8
+
9
+ - Railway CLI installed: `npm install -g @railway/cli`
10
+ - Railway account: [railway.app](https://railway.app)
11
+ - WhatsApp Business API credentials
12
+
13
+ ### 2. One-Command Deployment
14
+
15
+ ```bash
16
+ # Deploy to Railway
17
+ railway up
18
+
19
+ # Follow the prompts to create a new project
20
+ ```
21
+
22
+ ## ⚙️ Environment Variables Setup
23
+
24
+ After deployment, configure these environment variables in Railway Dashboard:
25
+
26
+ ### Required Variables
27
+
28
+ ```bash
29
+ # WhatsApp Business API
30
+ WP_ACCESS_TOKEN=your_access_token_here
31
+ WP_PHONE_ID=your_phone_number_id_here
32
+ WP_BID=your_business_id_here
33
+ WHATSAPP_WEBHOOK_VERIFY_TOKEN=your_webhook_token_here
34
+
35
+ # Redis (if using Railway Redis plugin)
36
+ REDIS_URL=redis://redis.railway.internal:6379
37
+
38
+ # Optional: AI Integration
39
+ OPENAI_API_KEY=your_openai_key_here
40
+ ```
41
+
42
+ ### Railway Auto-Set Variables
43
+
44
+ Railway automatically configures:
45
+ - `PORT` - Dynamic port assignment
46
+ - `RAILWAY_ENVIRONMENT` - Environment detection
47
+ - Domain and SSL certificates
48
+
49
+ ## 📡 Adding Redis
50
+
51
+ ### Option 1: Railway Redis Plugin
52
+
53
+ ```bash
54
+ # Add Redis plugin via CLI
55
+ railway add --plugin redis
56
+
57
+ # Or via Railway Dashboard:
58
+ # Project → Plugins → Add Redis
59
+ ```
60
+
61
+ ### Option 2: External Redis
62
+
63
+ Set `REDIS_URL` to your external Redis provider:
64
+ ```bash
65
+ # Redis Cloud
66
+ REDIS_URL=redis://username:password@redis-host:port
67
+
68
+ # AWS ElastiCache
69
+ REDIS_URL=rediss://cache-cluster.amazonaws.com:6380
70
+
71
+ # Upstash Redis
72
+ REDIS_URL=rediss://username:password@host:port
73
+ ```
74
+
75
+ ## 🔗 Webhook Configuration
76
+
77
+ After deployment, configure your WhatsApp webhook:
78
+
79
+ 1. **Get your Railway URL**: `https://your-app-name.up.railway.app`
80
+
81
+ 2. **Set webhook in Facebook Developer Console**:
82
+ ```
83
+ Webhook URL: https://your-app-name.up.railway.app/webhook/messenger/YOUR_PHONE_ID/whatsapp
84
+ Verify Token: your_webhook_token_here
85
+ ```
86
+
87
+ 3. **Test webhook**:
88
+ ```bash
89
+ curl "https://your-app-name.up.railway.app/health"
90
+ ```
91
+
92
+ ## 📋 Step-by-Step Setup
93
+
94
+ ### Step 1: Login to Railway
95
+
96
+ ```bash
97
+ railway login
98
+ ```
99
+
100
+ ### Step 2: Initialize Project
101
+
102
+ ```bash
103
+ # In your wappa_full_example directory
104
+ railway init
105
+
106
+ # Select "Create new project"
107
+ # Choose a project name
108
+ ```
109
+
110
+ ### Step 3: Deploy
111
+
112
+ ```bash
113
+ railway up
114
+ ```
115
+
116
+ ### Step 4: Configure Environment
117
+
118
+ ```bash
119
+ # Set variables via CLI
120
+ railway variables set WP_ACCESS_TOKEN=your_token
121
+ railway variables set WP_PHONE_ID=your_phone_id
122
+ railway variables set WP_BID=your_business_id
123
+ railway variables set WHATSAPP_WEBHOOK_VERIFY_TOKEN=your_webhook_token
124
+
125
+ # Or use Railway Dashboard for easier management
126
+ ```
127
+
128
+ ### Step 5: Add Redis
129
+
130
+ ```bash
131
+ # Add Redis plugin
132
+ railway add redis
133
+
134
+ # Redis URL will be auto-configured as:
135
+ # REDIS_URL=redis://redis.railway.internal:6379
136
+ ```
137
+
138
+ ### Step 6: Configure Custom Domain (Optional)
139
+
140
+ ```bash
141
+ # Add custom domain
142
+ railway domain
143
+
144
+ # Or via Dashboard: Settings → Domains
145
+ ```
146
+
147
+ ## 🔍 Monitoring & Debugging
148
+
149
+ ### View Logs
150
+
151
+ ```bash
152
+ # Real-time logs
153
+ railway logs
154
+
155
+ # Or via Railway Dashboard: Deployments → View Logs
156
+ ```
157
+
158
+ ### Health Checks
159
+
160
+ ```bash
161
+ # Check application health
162
+ curl https://your-app.up.railway.app/health
163
+
164
+ # Detailed health check
165
+ curl https://your-app.up.railway.app/health/detailed
166
+ ```
167
+
168
+ ### Environment Info
169
+
170
+ ```bash
171
+ # List all variables
172
+ railway variables
173
+
174
+ # Show deployment info
175
+ railway status
176
+ ```
177
+
178
+ ## 🛠️ Development Workflow
179
+
180
+ ### Local Development
181
+
182
+ ```bash
183
+ # Link to Railway project
184
+ railway link
185
+
186
+ # Pull environment variables
187
+ railway run --service your-service-name
188
+
189
+ # Start local development
190
+ uv run python -m app.main
191
+ ```
192
+
193
+ ### Deploy Updates
194
+
195
+ ```bash
196
+ # Deploy latest changes
197
+ railway up
198
+
199
+ # Or enable auto-deploy via GitHub integration
200
+ ```
201
+
202
+ ## 📊 Scaling on Railway
203
+
204
+ Railway automatically handles:
205
+ - **Auto-scaling**: Based on CPU/memory usage
206
+ - **Load balancing**: Multiple instance management
207
+ - **SSL certificates**: Automatic HTTPS
208
+ - **CDN**: Global edge caching
209
+
210
+ ### Manual Scaling
211
+
212
+ ```bash
213
+ # Scale replicas (Pro plan required)
214
+ railway scale --replicas 3
215
+ ```
216
+
217
+ ## 🚨 Troubleshooting
218
+
219
+ ### Common Issues
220
+
221
+ #### 1. Build Fails
222
+
223
+ ```bash
224
+ # Check build logs
225
+ railway logs --deployment
226
+
227
+ # Common fixes:
228
+ # - Ensure Dockerfile is optimized
229
+ # - Check uv.lock exists
230
+ # - Verify Python version compatibility
231
+ ```
232
+
233
+ #### 2. Environment Variables Missing
234
+
235
+ ```bash
236
+ # Check current variables
237
+ railway variables
238
+
239
+ # Set missing variables
240
+ railway variables set VARIABLE_NAME=value
241
+ ```
242
+
243
+ #### 3. Redis Connection Issues
244
+
245
+ ```bash
246
+ # Verify Redis plugin is added
247
+ railway plugins
248
+
249
+ # Check Redis URL format
250
+ railway variables get REDIS_URL
251
+ ```
252
+
253
+ #### 4. Webhook Not Working
254
+
255
+ ```bash
256
+ # Check application logs
257
+ railway logs
258
+
259
+ # Verify webhook URL format:
260
+ # https://your-app.up.railway.app/webhook/messenger/PHONE_ID/whatsapp
261
+
262
+ # Test webhook endpoint
263
+ curl -X GET "https://your-app.up.railway.app/webhook/messenger/YOUR_PHONE_ID/whatsapp?hub.verify_token=YOUR_TOKEN&hub.challenge=test"
264
+ ```
265
+
266
+ ## 💰 Railway Pricing Considerations
267
+
268
+ ### Hobby Plan (Free Tier)
269
+ - $5 credit/month
270
+ - 21 days uptime limit per month
271
+ - 1GB RAM, 1 vCPU
272
+ - Perfect for development/testing
273
+
274
+ ### Pro Plan ($20/month)
275
+ - No usage limits
276
+ - Custom domains
277
+ - Multiple environments
278
+ - Priority support
279
+ - Auto-scaling
280
+
281
+ ## 🔒 Security Best Practices
282
+
283
+ ### Environment Variables
284
+ - Never commit sensitive data to Git
285
+ - Use Railway's encrypted environment variables
286
+ - Rotate access tokens regularly
287
+
288
+ ### Access Control
289
+ - Enable two-factor authentication
290
+ - Use team management for collaboration
291
+ - Set up deployment notifications
292
+
293
+ ## 📚 Useful Railway Commands
294
+
295
+ ```bash
296
+ # Project management
297
+ railway init # Initialize new project
298
+ railway link # Link to existing project
299
+ railway unlink # Unlink from project
300
+
301
+ # Deployment
302
+ railway up # Deploy application
303
+ railway logs # View application logs
304
+ railway status # Show deployment status
305
+
306
+ # Environment
307
+ railway variables # List all variables
308
+ railway variables set KEY=value # Set variable
309
+ railway variables delete KEY # Delete variable
310
+
311
+ # Services
312
+ railway add redis # Add Redis plugin
313
+ railway remove redis # Remove Redis plugin
314
+
315
+ # Domains
316
+ railway domain # Manage custom domains
317
+ railway open # Open deployed application
318
+ ```
319
+
320
+ ## 🎯 Webhook URLs for WhatsApp
321
+
322
+ After Railway deployment, use these URLs:
323
+
324
+ ```bash
325
+ # Primary webhook URL
326
+ https://your-app.up.railway.app/webhook/messenger/YOUR_PHONE_ID/whatsapp
327
+
328
+ # Health check
329
+ https://your-app.up.railway.app/health
330
+
331
+ # API documentation
332
+ https://your-app.up.railway.app/docs
333
+ ```
334
+
335
+ ## ✅ Deployment Checklist
336
+
337
+ ### Pre-Deployment
338
+ - [ ] Railway CLI installed and authenticated
339
+ - [ ] WhatsApp Business API credentials ready
340
+ - [ ] Project tested locally
341
+
342
+ ### Deployment
343
+ - [ ] `railway up` completed successfully
344
+ - [ ] All environment variables configured
345
+ - [ ] Redis plugin added (if needed)
346
+ - [ ] Application health check passes
347
+
348
+ ### Post-Deployment
349
+ - [ ] WhatsApp webhook configured and verified
350
+ - [ ] Test message flow end-to-end
351
+ - [ ] Interactive commands working (buttons, lists)
352
+ - [ ] Monitoring and alerting configured
353
+
354
+ ## 🆘 Getting Help
355
+
356
+ - **Railway Docs**: [docs.railway.app](https://docs.railway.app)
357
+ - **Railway Discord**: [discord.gg/railway](https://discord.gg/railway)
358
+ - **Wappa Framework**: [wappa.mimeia.com](https://wappa.mimeia.com)
359
+
360
+ ---
361
+
362
+ **🚂 Your Wappa app is now live on Railway!**
363
+
364
+ Railway provides the easiest path to production for your WhatsApp Business application with automatic scaling, SSL, and global CDN.
365
+
366
+ **Built with ❤️ using the Wappa Framework**