Overview
Inventario includes a comprehensive notification system supporting both email (via Resend) and SMS (via Twilio) notifications. These notifications are triggered automatically for events like contact form submissions, password resets, and customer campaigns.Email Notifications (Resend)
Inventario uses Resend for reliable email delivery with a simple API.Configuration
Email settings insettings.py:
inventario/settings.py
Environment Variables
Add these to your.env file:
.env
Setting Up Resend
Create Resend Account
Sign up at resend.com and create a new account.
Verify Your Domain
Add your domain and configure DNS records:
- SPF record
- DKIM records
- DMARC record (optional but recommended)
Generate API Key
Go to API Keys in the Resend dashboard and create a new key.Copy the key and add it to your
.env file.Email Service Implementation
The email service is implemented inapplications/cuentas/email_service.py:
applications/cuentas/email_service.py
Email Notification Triggers
Emails are automatically sent for:1. Contact Form Submissions
When users submit the contact form on the home page:applications/cuentas/views.py
2. Password Reset Requests
When users request a password reset, they receive a verification code via email.3. Custom Notifications
Developers can trigger custom emails using theenviar_email() function:
SMS Notifications (Twilio)
Inventario uses Twilio for SMS messaging, enabling customer campaigns and alerts.Configuration
Twilio settings insettings.py:
inventario/settings.py
Environment Variables
Add these to your.env file:
.env
Setting Up Twilio
Create Twilio Account
Sign up at twilio.com and verify your email.
Get a Phone Number
Purchase a phone number with SMS capabilities for your country.For Colombia: Look for numbers starting with
+57.Copy Credentials
From the Twilio Console dashboard:
- Copy Account SID
- Copy Auth Token
- Copy your Twilio Phone Number
.env file.SMS Service Implementation
The SMS provider is implemented inapplications/clientes/sms_providers.py:
applications/clientes/sms_providers.py
Phone Number Formatting
Inventario automatically formats Colombian phone numbers to E.164 format:applications/clientes/utils.py
SMS Campaigns
Inventario includes a customer campaign system (applications/clientes/models.py):
- CampanaSMS: Defines SMS campaigns with templates
- PlantillaSMS: Reusable message templates with variables like
{nombre} - SMSLog: Tracks all sent messages with status and Twilio SID
Creating a Campaign
-
Create a template in Django admin:
- Create a campaign and select customers
-
Send SMS campaign:
SMS Logging
All SMS messages are logged in theSMSLog model:
applications/clientes/models.py
Notification Best Practices
Rate Limiting
Implement delays between bulk SMS to avoid rate limits:
Error Handling
Always check return values and log errors:
Testing
Use Twilio test credentials during development to avoid charges.
Compliance
Ensure customers opt-in to SMS campaigns. Include unsubscribe options.
Troubleshooting
Resend emails not sending
Resend emails not sending
- Verify your domain is confirmed in Resend dashboard
- Check DNS records are properly configured
- Verify
RESEND_API_KEYin.envis correct - Check application logs for error messages
Twilio SMS failing
Twilio SMS failing
Common issues:
- Invalid phone number format: Must be E.164 format (e.g.,
+573001234567) - Unverified number (trial accounts): Add recipient to verified numbers
- Insufficient balance: Check Twilio account balance
- Wrong phone number: Verify
TWILIO_PHONE_NUMBERis your Twilio number
SMSLog.error_mensaje field.Missing environment variables
Missing environment variables
If notifications aren’t working, verify all required variables are set:Empty strings indicate missing environment variables.
Next Steps
AI Features
Enable OpenAI-powered business insights
Integrations
Configure Google OAuth and other services