Skip to content

irkky/Autodialer-AI-Powered-Calling-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“ž Autodialer - AI-Powered Calling System

Ruby Version Rails Version License Twilio Gemini

An intelligent, automated calling system built with Ruby on Rails

Features β€’ Installation β€’ Configuration β€’ Usage β€’ Deployment


🌟 Overview

Autodialer is a powerful Ruby on Rails application that revolutionizes outbound calling by combining:

  • πŸ€– AI-Powered Commands - Natural language processing with Google Gemini
  • πŸ“ž Twilio Integration - Reliable voice call delivery
  • ⚑ Background Processing - Async job handling with Sidekiq
  • πŸ“Š Real-Time Tracking - Live call status monitoring
  • 🎯 Smart Scripting - AI-generated call scripts

⚠️ Important: This application is designed for testing with verified numbers only. Always obtain proper consent before calling real people.


✨ Features

πŸ“‹ Bulk Upload System

  • Multiple Input Methods: Paste numbers directly or upload .txt/.csv files
  • Smart Validation: Automatic format checking and duplicate removal
  • Batch Processing: Queue up to 100 numbers at once
  • International Support: Handles country codes and various formats

πŸ€– AI Command Center

Natural language interface powered by Google Gemini:

βœ… "Call +1 800 555 0100"
βœ… "Dial the last number"
βœ… "Call the third number from history"
βœ… "Dial the last 5 numbers"
βœ… "Call the previous number again"

Smart Features:

  • Intent recognition and phone number extraction
  • Historical reference tracking (last, previous, nth number)
  • Context-aware script generation
  • Fallback to direct number parsing

πŸ“ž Twilio Voice Integration

  • Automated Calling: Programmable voice calls via Twilio API
  • Status Tracking: Real-time updates (queued, ringing, completed, failed)
  • Custom Scripts: AI-generated or default voice messages
  • Multiple Voices: Support for various Polly voices
  • Webhook Processing: Async status callbacks

πŸ—„οΈ Comprehensive Logging

  • Call Timeline: Chronological view of all attempts
  • Status Details: Duration, timestamps, and outcomes
  • Success Metrics: Track completion rates
  • Filterable Records: Search by status, number, or date

βš™οΈ Background Processing

  • Sidekiq Workers: Async call processing
  • Redis Integration: Job queue management
  • Auto-retry Logic: Configurable retry attempts
  • Development Mode: Inline processing for easy testing

πŸ“Š Real-Time Status Modal

  • Live Updates: Automatic status polling every 2 seconds
  • Visual Feedback: Color-coded status badges
  • Progress Tracking: Per-number call status
  • Non-blocking: Continue browsing while calls process

πŸš€ Installation

Prerequisites

  • Ruby: 3.4.7 or higher
  • PostgreSQL: 12 or higher
  • Redis: 6 or higher (for production Sidekiq)
  • Twilio Account: For voice calling
  • Google Gemini API Key: For AI features

Step 1: Clone the Repository

git clone https://github.com/irkky/autodialer.git
cd autodialer

Step 2: Install Dependencies

bundle install

Step 3: Database Setup

# Create and migrate database
rails db:create
rails db:migrate

# Optional: Load seed data
rails db:seed

Step 4: Environment Configuration

Create a .env file from the example:

cp .env.example .env

Edit .env with your credentials (see Configuration section).


βš™οΈ Configuration

Environment Variables

Create a .env file in the project root with the following variables:

# ======================
# TWILIO CREDENTIALS
# Get these from: https://console.twilio.com
# ======================
TWILIO_ACCOUNT_SID=ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
TWILIO_AUTH_TOKEN=your_auth_token_here
TWILIO_PHONE_NUMBER=+18005551234

# ======================
# GEMINI API KEY
# Get from: https://ai.google.dev/
# ======================
GEMINI_API_KEY=AIzaSyXXXXXXXXXXXXXXXXXXXXXXXXXX

# ======================
# BASE URL
# Must be publicly accessible by Twilio
# Use ngrok for local development:
# ngrok http 3000
# ======================
BASE_URL=https://yourapp.ngrok-free.app

# ======================
# REDIS CONFIG
# For Sidekiq background jobs
# ======================
REDIS_URL=redis://localhost:6379/0

# ======================
# RAILS ENVIRONMENT
# ======================
RAILS_ENV=development

# ======================
# DATABASE (Optional)
# PostgreSQL password if required
# ======================
AUTODIALER_DATABASE_PASSWORD=your_password

# ======================
# SIDEKIQ (Optional)
# Set to false to use Redis in development
# ======================
SIDEKIQ_INLINE=true

Twilio Setup

  1. Create a Twilio Account: Sign up at twilio.com

  2. Get a Phone Number: Purchase or use a trial number

  3. Configure Webhooks: In Twilio Console β†’ Phone Numbers β†’ Active Numbers β†’ Configure

    Setting URL
    Voice URL https://your-domain.com/twilio/voice_response
    Status Callback https://your-domain.com/twilio/status_callback
    HTTP Method POST
  4. Verify Numbers (Trial Account): Add test numbers to your Verified Caller IDs

Google Gemini Setup

  1. Visit Google AI Studio
  2. Create a new API key
  3. Add the key to your .env file as GEMINI_API_KEY

Ngrok for Local Development

To expose your local Rails server to Twilio:

# Install ngrok
brew install ngrok  # macOS
# or download from https://ngrok.com/download

# Start ngrok
ngrok http 3000

# Copy the HTTPS URL to your .env file as BASE_URL
# Example: https://abc123.ngrok-free.app

🎯 Usage

Starting the Application

1. Start Rails Server

rails server

Visit: http://localhost:3000

2. Start Sidekiq (Production/Staging)

# In development, jobs run inline by default
# To use Redis + Sidekiq:
SIDEKIQ_INLINE=false rails server

# In a separate terminal:
bundle exec sidekiq -C config/sidekiq.yml

3. Start Ngrok (Local Development)

ngrok http 3000

Application Workflow

Method 1: Bulk Upload

  1. Navigate to Upload Numbers (/calls/new)
  2. Choose your input method:
    • Paste: Enter numbers (one per line)
    • Upload: Select a .txt or .csv file
  3. Click Start Dialing
  4. View real-time status in the modal
  5. Check Call Logs for detailed results

Method 2: AI Commands

  1. Navigate to AI Command Center (/ai)
  2. Enter a natural language command:
    • Call +1 800 555 0100
    • Dial the previous number
    • Call the last 3 numbers
  3. Gemini extracts the intent and number
  4. System queues and processes the call
  5. View results in Call Logs

AI Command Examples

Direct Number Calling:

Call +1 800 555 0100
Dial 9876543210
Ring +91 98765 43210 now

Historical References:

Call the previous number
Dial the last number again
Call the same number
Ring the second last number
Call the before last number

Ordinal References:

Call the first number
Dial the third entry
Ring the 5th number from the list

Bulk Historical:

Call the last two numbers
Dial the last 5 numbers
Ring last three numbers

Viewing Logs

Navigate to Call Logs (/logs) to see:

  • πŸ“Š Status: Completed, Failed, Busy, No-answer
  • ⏱️ Duration: Call length in seconds
  • πŸ• Timestamps: Start and end times
  • πŸ“ž Number: Called phone number
  • πŸ”„ Updates: Real-time status changes

πŸ› οΈ Rake Tasks

Useful commands for testing and maintenance:

Generate Test Logs

rake autodialer:generate_test_logs

Creates 10 fake call records with random statuses.

Clear All Logs

rake autodialer:clear_logs

Deletes all call records from the database.

Simulate a Call

TEST_NUMBER=+18001234567 rake autodialer:simulate_call

Creates a simulated call record without actually calling.


πŸ“ Project Structure

autodialer/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   β”œβ”€β”€ ai_controller.rb          # AI command processing
β”‚   β”‚   β”œβ”€β”€ calls_controller.rb        # Bulk upload handling
β”‚   β”‚   β”œβ”€β”€ logs_controller.rb         # Call log display
β”‚   β”‚   └── twilio_controller.rb       # Webhook handlers
β”‚   β”‚
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   └── call_record.rb             # Call data model
β”‚   β”‚
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ gemini_ai.rb               # AI integration
β”‚   β”‚   └── twilio_service.rb          # Twilio API wrapper
β”‚   β”‚
β”‚   β”œβ”€β”€ workers/
β”‚   β”‚   β”œβ”€β”€ dialer_worker.rb           # Call processing job
β”‚   β”‚   └── twilio_status_sync_worker.rb  # Status polling
β”‚   β”‚
β”‚   └── views/
β”‚       β”œβ”€β”€ ai/                        # AI command interface
β”‚       β”œβ”€β”€ calls/                     # Upload pages
β”‚       └── logs/                      # Log display
β”‚
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ initializers/
β”‚   β”‚   β”œβ”€β”€ sidekiq.rb                 # Redis config
β”‚   β”‚   β”œβ”€β”€ sidekiq_inline.rb          # Development mode
β”‚   β”‚   └── twilio.rb                  # Twilio setup
β”‚   β”‚
β”‚   └── routes.rb                      # Application routes
β”‚
β”œβ”€β”€ db/
β”‚   └── migrate/
β”‚       └── create_call_records.rb     # Database schema
β”‚
└── lib/
    └── tasks/
        └── autodialer.rake            # Custom rake tasks

🚒 Deployment

Recommended Platforms

Pre-deployment Checklist

  1. Set Environment Variables: All production credentials
  2. Configure Redis: For Sidekiq job processing
  3. Setup PostgreSQL: Production database
  4. Compile Assets: rails assets:precompile
  5. Run Migrations: rails db:migrate
  6. Update BASE_URL: Point to production domain
  7. Configure Twilio Webhooks: Use production URLs
  8. Enable HTTPS: Required for Twilio webhooks

Environment Variables for Production

RAILS_ENV=production
SECRET_KEY_BASE=<generated_key>
TWILIO_ACCOUNT_SID=<your_sid>
TWILIO_AUTH_TOKEN=<your_token>
TWILIO_PHONE_NUMBER=<your_number>
GEMINI_API_KEY=<your_key>
BASE_URL=https://your-production-domain.com
REDIS_URL=redis://your-redis-url:6379/0
DATABASE_URL=postgresql://user:pass@host:5432/dbname

Generate SECRET_KEY_BASE:

rails secret

Render.com Deployment

  1. Connect your GitHub repository
  2. Set environment as Web Service
  3. Add environment variables
  4. Set build command: bundle install && rails assets:precompile && rails db:migrate
  5. Set start command: bundle exec puma -C config/puma.rb
  6. Add Redis addon
  7. Deploy!

πŸ”’ Security Best Practices

βœ… Development

  • βœ… Use test/verified numbers only
  • βœ… Store credentials in .env (never commit)
  • βœ… Enable CSRF protection
  • βœ… Validate phone number formats
  • βœ… Rate limit API calls

βœ… Production

  • βœ… Enable HTTPS/SSL
  • βœ… Secure environment variables
  • βœ… Use strong SECRET_KEY_BASE
  • βœ… Restrict Sidekiq dashboard access
  • βœ… Monitor Twilio usage and costs
  • βœ… Implement authentication for admin pages
  • βœ… Add CAPTCHA for public-facing forms
  • βœ… Set up request rate limiting

⚠️ Important Reminders

  • Never call real people without explicit consent
  • Comply with TCPA regulations (US) and local laws
  • Respect Do Not Call lists
  • Include opt-out mechanisms in scripts
  • Monitor for abuse and suspicious patterns
  • Secure webhook endpoints (verify Twilio signatures)

πŸ› Troubleshooting

Common Issues

1. Twilio "Not Authorized" Error

Problem: Calls fail with 403 or authorization errors

Solution:

  • Verify TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN in .env
  • Check that credentials match your Twilio console
  • Ensure phone number format includes country code

2. "Unable to Reach" - Webhook Error

Problem: Twilio can't reach your voice_response endpoint

Solution:

  • Confirm BASE_URL is publicly accessible
  • Check ngrok is running for local dev
  • Verify webhook URLs in Twilio console
  • Ensure Rails server is running

3. Calls Stuck in "Queued" Status

Problem: Status never updates from "queued"

Solution:

  • Check Sidekiq is running (production)
  • Verify Redis connection
  • Check logs: tail -f log/development.log
  • Ensure TwilioStatusSyncWorker is executing

4. Gemini AI Not Extracting Numbers

Problem: AI commands don't trigger calls

Solution:

  • Verify GEMINI_API_KEY is set correctly
  • Check API quota/billing on Google Cloud
  • Ensure number is in E.164 format
  • Review GeminiAi.process_command logic

5. Database Connection Errors

Problem: Can't connect to PostgreSQL

Solution:

  • Start PostgreSQL: brew services start postgresql
  • Check database exists: rails db:create
  • Verify database.yml credentials
  • Ensure PostgreSQL is running on port 5432

πŸ“š API Documentation

Twilio Webhooks

Voice Response Endpoint

POST /twilio/voice_response

Receives initial call connection request from Twilio.

Parameters:

  • CallSid - Unique call identifier

Response: TwiML voice instructions

Status Callback Endpoint

POST /twilio/status_callback

Receives call status updates from Twilio.

Parameters:

  • CallSid - Unique call identifier
  • CallStatus - Current status (queued, ringing, in-progress, completed, failed)
  • To - Destination phone number
  • StartTime - Call start timestamp
  • EndTime - Call end timestamp
  • CallDuration - Duration in seconds

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Guidelines

  • Follow Ruby style guide
  • Write meaningful commit messages
  • Add tests for new features
  • Update documentation
  • Keep dependencies up to date

πŸ“ License

This project is licensed under the MIT License. See the LICENSE file for details.


πŸ™ Acknowledgments

Built with these amazing technologies:


Made with ❀️ using Ruby on Rails

⬆ Back to Top

About

Autodialer is a powerful Ruby on Rails application that transforms outbound calling through seamless AI-driven automation. It combines intelligence, reliability, and performance to streamline large-scale call workflows.

Topics

Resources

License

Stars

Watchers

Forks

Contributors