Skip to main content

AutoDialerCampaign Model

The AutoDialerCampaign model represents an outbound dialing campaign with configuration for routing, scheduling, rate limiting, AMD actions, and Caller ID pooling.

Table: auto_dialer_campaigns
Model: App\Models\AutoDialerCampaign
Resource: App\Http\Resources\AutoDialerCampaignResource

Database Schema​

ColumnTypeNullableDefaultDescription
idbigint unsignedNoautoPrimary key
organization_idbigint unsignedNo-Foreign key to organizations
namevarchar(255)No-Campaign name
descriptiontextYesnullCampaign description
statusenumNodraftdraft, active, paused, completed, archived
auto_startbooleanNofalseAuto-start when ready
routing_destination_typeenumNo-ai_assistant, ai_load_balancer, hangup
routing_destination_idbigint unsignedYesnullTarget destination ID
dial_timeoutsmallint unsignedNo60Seconds to ring before timeout
destination_connectenumNoconnectedconnected or immediately
caller_idvarchar(255)No-Default Caller ID, E.164
caller_id_strategyvarchar(20)Noround_robinDistribution strategy for pool
caller_id_pool_enabledbooleanNofalseWhether pool mode is enabled
max_dial_attemptstinyint unsignedNo1Max attempts per destination (API: 1-5)
concurrent_active_callsint unsignedNo0Max concurrent calls (CAC; API: 1-50)
calls_per_secondtinyint unsignedNo1Call initiation rate (CPS; API: 1-30)
days_activejsonNo-Legacy schedule days
start_timetinyint unsignedYesnullLegacy start hour
end_timetinyint unsignedYesnullLegacy end hour
start_datedateNo-Campaign start date
end_datedateNo-Campaign end date
timezonevarchar(255)NoUTCSchedule timezone
schedulejsonYesnullFull weekly schedule
time_limitmediumint unsignedNo600Max call duration in seconds (API: 30-14400; omitted or null on create, or null on update, stores 600)
record_callsbooleanNofalseEnable recording
action_voicemailvarchar(255)YesnullAMD action for voicemail (HANGUP or CONTINUE)
action_humanvarchar(255)YesnullAMD action for human
action_unknownvarchar(255)YesnullAMD action for unknown
retry_on_voicemailbooleanNofalseRetry a destination that reached voicemail
retry_on_busy_no_answerbooleanNofalseRedial busy / no-answer destinations within max_dial_attempts
retry_delay_minutessmallint unsignedNo15Minutes before the first busy / no-answer retry (1 to 1440); doubles for each further retry, capped at 24 hours
total_destinationsint unsignedNo0Total destinations count
completed_callsint unsignedNo0Completed calls count
failed_callsint unsignedNo0Failed calls count
voicemail_callsint unsignedNo0Voicemail calls count
pending_callsint unsignedNo0Pending calls count
pause_reasonvarchar(255)YesnullReason for pause
resume_attimestampYesnullScheduled resume time
started_attimestampYesnullWhen campaign started
completed_attimestampYesnullWhen campaign completed
created_attimestampYesnullCreation timestamp
updated_attimestampYesnullLast update timestamp

Indexes​

IndexColumns
adc_org_status_idxorganization_id, status
adc_org_auto_start_idxorganization_id, auto_start, status
adc_dates_idxstart_date, end_date
auto_dialer_campaigns_routing_destination_id_foreignrouting_destination_id

organization_id references organizations with ON DELETE CASCADE. routing_destination_id has no foreign key constraint: it points to an AI assistant or an AI load balancer depending on routing_destination_type.

Relationships​

Belongs To​

campaign.organization() → Organization
campaign.aiAssistant() → AiAssistant (routing_destination_id, when routing to an AI assistant)
campaign.aiLoadBalancer() → AiAssistantLoadBalancer (routing_destination_id, when routing to a load balancer)

Has Many​

campaign.lists() → AutoDialerList[] (a campaign can hold several lists)
campaign.destinations() → AutoDialerDestination[] (through its lists)
campaign.callSessions() → AutoDialerCallSession[]
campaign.callerIdStats() → AutoDialerCallerIdStat[]

Belongs To Many​

campaign.callerIds() → DidNumber[]
- Pivot: auto_dialer_campaign_caller_ids
- With pivot: weight, with timestamps

Enums​

CampaignStatus​

CaseValue
DRAFTdraft
ACTIVEactive
PAUSEDpaused
COMPLETEDcompleted
ARCHIVEDarchived

RoutingDestinationType​

CaseValue
AI_ASSISTANTai_assistant
AI_LOAD_BALANCERai_load_balancer
HANGUPhangup

CallerIdStrategy​

CaseValue
ROUND_ROBINround_robin
RANDOMrandom
LEAST_RECENTLY_USEDleast_recently_used

DestinationConnect​

ValueDescription
connectedConnect when call answered
immediatelyConnect immediately

Caller ID Pooling​

Enable Pool Mode​

$campaign->update([
'caller_id_pool_enabled' => true,
'caller_id_strategy' => 'round_robin', // or 'random', 'least_recently_used'
]);

Assign Caller IDs​

$syncData = [
$didId1 => ['weight' => 1],
$didId2 => ['weight' => 1],
];
$campaign->callerIds()->sync($syncData);

Methods​

Scopes​

AutoDialerCampaign::forOrganization($orgId)
AutoDialerCampaign::active()
AutoDialerCampaign::paused()
AutoDialerCampaign::draft()
AutoDialerCampaign::runnable() // Active, with start_date/end_date within one day of today (coarse pre-filter; isRunnable() does the exact, timezone-aware check)

Business Logic​

$campaign->isRunnable(): bool
$campaign->getProgressPercentage(): int
$campaign->getApiIntervalMilliseconds(): float
$campaign->hasValidCac(): bool
$campaign->hasValidCps(): bool
$campaign->hasList(): bool // at least one list assigned
$campaign->canStart(): bool
$campaign->canPause(): bool
$campaign->canAcceptList(): bool
$campaign->listAssignmentRefusal(): ?string // why a list cannot be added now (status, or running), or null
$campaign->getPendingCount(): int // destinations with status pending
$campaign->getRoutingDestinationLabel(): string
$campaign->clearRedisKeys(): void // deletes dialer:cac:{id}:active and campaign:{id}:caller_id_index on the dialer Redis

isRunnable() evaluates the current time in the campaign's timezone and checks the date range and the schedule time ranges for today. getApiIntervalMilliseconds() returns 1000 / calls_per_second. hasValidCac() and hasValidCps() check the MIN_CAC/MAX_CAC (1-50) and MIN_CPS/MAX_CPS (1-30) constants.