Skip to main content

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 in settings.py:
inventario/settings.py

Environment Variables

Add these to your .env file:
.env
You must verify your domain in Resend before sending emails. Unverified domains are limited to test mode.

Setting Up Resend

1

Create Resend Account

Sign up at resend.com and create a new account.
2

Verify Your Domain

Add your domain and configure DNS records:
  • SPF record
  • DKIM records
  • DMARC record (optional but recommended)
3

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.
4

Test Email Sending

Use the email service to send a test email:

Email Service Implementation

The email service is implemented in applications/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 the enviar_email() function:

SMS Notifications (Twilio)

Inventario uses Twilio for SMS messaging, enabling customer campaigns and alerts.

Configuration

Twilio settings in settings.py:
inventario/settings.py

Environment Variables

Add these to your .env file:
.env
Twilio phone numbers must be in E.164 format (e.g., +57 for Colombia). SMS messaging rates apply.

Setting Up Twilio

1

Create Twilio Account

Sign up at twilio.com and verify your email.
2

Get a Phone Number

Purchase a phone number with SMS capabilities for your country.For Colombia: Look for numbers starting with +57.
3

Copy Credentials

From the Twilio Console dashboard:
  • Copy Account SID
  • Copy Auth Token
  • Copy your Twilio Phone Number
Add these to your .env file.
4

Test SMS Sending

Use the SMS service to send a test message:

SMS Service Implementation

The SMS provider is implemented in applications/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

  1. Create a template in Django admin:
  2. Create a campaign and select customers
  3. Send SMS campaign:

SMS Logging

All SMS messages are logged in the SMSLog 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

  1. Verify your domain is confirmed in Resend dashboard
  2. Check DNS records are properly configured
  3. Verify RESEND_API_KEY in .env is correct
  4. Check application logs for error messages
Test manually:
Common issues:
  1. Invalid phone number format: Must be E.164 format (e.g., +573001234567)
  2. Unverified number (trial accounts): Add recipient to verified numbers
  3. Insufficient balance: Check Twilio account balance
  4. Wrong phone number: Verify TWILIO_PHONE_NUMBER is your Twilio number
Check error messages in SMSLog.error_mensaje field.
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