← back to Butlr

scripts/inject-test-calls.js

90 lines

#!/usr/bin/env node
// Inject 5 test calls into the queue. Worker (lib/twilio tick) picks
// them up within 5s of the next poll, dials Twilio, drives AI agent
// through IVR, records, finalizes MP3.
//
// Steve approved targets (2026-05-13): pure-automated lines only, no
// humans bothered. Total cost ~$0.10-$0.50 Twilio.
//
// Run on prod:
//   ssh root@45.61.58.125 'cd /root/public-projects/butlr && node scripts/inject-test-calls.js'

const data = require('../lib/data');
const users = require('../lib/users');

const TARGETS = [
  {
    business_name: 'NIST Time Service',
    business_phone: '+13034997111',
    category: 'other',
    category_label: 'Test — automated time service',
    goal: 'This number reads the current time aloud, then hangs up. There is NO IVR menu. Just listen for ~10 seconds, then say nothing and let the call complete naturally. Do not press any digits. Do not speak.',
  },
  {
    business_name: 'Verizon TN Readback',
    business_phone: '+18004444444',
    category: 'other',
    category_label: 'Test — number readback',
    goal: 'This is a Verizon test line that reads back the calling number. Listen for ~10 seconds for the readback, then hang up. Do not press digits. Do not speak.',
  },
  {
    business_name: 'USPS Tracking',
    business_phone: '+18002758777',
    category: 'shipping',
    category_label: 'Test — package tracking IVR',
    goal: 'Navigate the IVR to hear current customer service hours. Listen carefully to the first menu, then press the digit for "hours of operation" or "store information" if offered. If no clear option, press 0 for operator. As soon as you hear the hours announced, hang up.',
  },
  {
    business_name: 'IRS Automated',
    business_phone: '+18008291040',
    category: 'gov',
    category_label: 'Test — federal tax IVR',
    goal: 'Navigate the IRS phone menu to identify the current wait time for individual income tax questions. The first prompt asks for English (press 1) or Spanish (press 2). Press 1 for English. Then listen for menu options and press the digit for individual tax questions. As soon as you hear a wait-time announcement, hang up. Do not wait for an agent.',
  },
  {
    business_name: 'Capital One',
    business_phone: '+18002274825',
    category: 'banking',
    category_label: 'Test — credit card IVR',
    goal: 'Get the current customer-service hours from the IVR. Press 0 or say "representative" if needed to reach a menu that announces hours. As soon as hours are announced (or the IVR says "we are open 24 hours"), hang up. Do not actually wait for a representative.',
  },
];

async function main() {
  // Find the admin user to attach calls to.
  try { users.seedLegacyAdmin(); } catch {}
  const admin = require('fs').readFileSync(require('path').join(__dirname, '..', 'data', 'users.json'), 'utf8');
  const adminUser = JSON.parse(admin).find(u => u.role === 'admin');
  if (!adminUser) { console.error('no admin user'); process.exit(1); }
  console.log(`injecting 5 test calls under admin: ${adminUser.email}`);

  const created = [];
  for (const t of TARGETS) {
    const r = data.addCall({
      ...t,
      callback_phone: '+16067130489',  // Steve's Twilio number — bridge won't fire because goal says hang up after info
      callback_name: 'Steve Abrams',
      callback_email: 'steve@designerwallcoverings.com',
      max_hold_minutes: 2,
      max_spend_cents: 50,
      consent_recording: 'on',
      consent_terms: 'on',
      notify_sms: '',
      notify_email: '',
      notes: 'LIVE TEST — autonomous loop tick 7 — 2026-05-13',
    }, adminUser.id);
    if (!r.ok) {
      console.error(`  ✗ ${t.business_name}: ${(r.errors || []).join('; ')}`);
      continue;
    }
    created.push({ id: r.call.id, business: t.business_name, phone: t.business_phone });
    console.log(`  + ${r.call.id}  ${t.business_name.padEnd(24)}  ${t.business_phone}`);
  }
  console.log('\nqueued 5 calls. worker tick picks them up every 5s.');
  console.log('monitor: pm2 logs butlr --lines 50 | grep -E "twilio|ai-agent|stream"');
  console.log('listen:  https://butlr.agentabrams.com/calls');
  console.log('\ncall ids:', created.map(c => c.id).join(' '));
}

main().catch(e => { console.error('error:', e.message); process.exit(2); });