Telecaller & Leads
Lead Ingestion
Call Source Mapping

Call Source Mapping

The CallSourceBO.cs (Business Object) manages the mapping between incoming Direct Inward Dial (DID) phone numbers and internal call source records. This module enables the system to identify which project, campaign, or business unit a call originated from, which is critical for proper lead routing, analytics, and attribution.

Core Business Logic

DID to CallSource Mapping

DID (Direct Inward Dial) is a telephone service that allows a company to receive calls on individual phone numbers without maintaining separate physical lines. When a call arrives on a specific DID number:

  1. Call Arrives: Incoming call on DID (e.g., +91-9876-543-210)
  2. DID Lookup: System queries CallSourceBLMapping or CallSource table
  3. Find Project: Maps DID to specific project, campaign, or business line
  4. Route & Log: Call is routed to appropriate staff and logged to correct source

CallSource Table Structure

FieldTypePurpose
CallSourceIdPK, IntUnique identifier for this call source
SourceNameStringHuman-readable name (e.g., "Home Loan Campaign Q1")
DIDNumberStringIncoming phone number (e.g., "+91-9876-543-210")
IsActiveBooleanWhether this call source accepts new calls
ProjectIdFK, IntLinks to project/campaign configuration
CreatedDateDateTimeWhen this mapping was created
LastModifiedDateTimeLast update timestamp
DescriptionStringNotes about the source
AllocationRuleStringRound-robin, skill-based, manager-assigned
DefaultStaffIdFK, IntFallback staff if normal allocation fails

Caching Strategy

To optimize performance, CallSource data is cached using these strategies:

  1. Application Startup: Load all active CallSource records into memory
  2. Cache Key: CallSource_<ProjectId> and DID_<PhoneNumber>
  3. TTL (Time To Live): 1 hour, or manual refresh on configuration change
  4. Invalidation: When CallSource record is updated or status changed
  5. Lookup Speed: Dictionary/HashMap lookup in O(1) time

Usage in Lead Assignment

When a new lead arrives (from any source):

Lead arrives with CallSourceId or DID number

Lookup CallSource from cache

Get Project, AllocationRule, DefaultStaff

Apply allocation logic to assign staff

Insert lead record with CallSourceId for attribution

DID Lookup Flow Diagram

CallSource Database Entity Relationship Diagram

CallSource Lookup Sequence Diagram

Caching Implementation Details

Cache Structure

Dictionary<string, CallSourceCache>

Key Pattern:
  - "DID_+91-9876-543-210" → CallSourceId
  - "CALLSOURCE_<CallSourceId>" → Full record

Value:
{
  CallSourceId: 42,
  SourceName: "Home Loans Q1 2026",
  ProjectId: 5,
  AllocationRule: "RoundRobin",
  DefaultStaffId: 12,
  IsActive: true,
  CacheTime: DateTime.Now,
  TTL: 3600 (seconds)
}

Cache Invalidation Triggers

TriggerAction
CallSource status changedInvalidate immediately
DID number reassignedInvalidate old mapping
Project updatedInvalidate related sources
Manual cache clearAdmin initiated
TTL expiredAuto-refresh on next access

Performance Characteristics

OperationTimeNotes
Cache hitunder 1msDictionary lookup
Cache miss + DB query~50-100msSQL index on DIDNumber
Full cache load~500msOne-time on startup
Cache refresh~1-2 secBackground async

Configuration Example

<!-- Application Configuration -->
<CallSourceConfig>
  <Caching>
    <Enabled>true</Enabled>
    <TTLSeconds>3600</TTLSeconds>
    <PreloadOnStartup>true</PreloadOnStartup>
  </Caching>
 
  <CallSources>
    <CallSource>
      <SourceName>Home Loans Q1</SourceName>
      <DIDNumber>+91-9876-543-210</DIDNumber>
      <ProjectId>5</ProjectId>
      <AllocationRule>RoundRobin</AllocationRule>
      <IsActive>true</IsActive>
    </CallSource>
 
    <CallSource>
      <SourceName>Personal Loans Q1</SourceName>
      <DIDNumber>+91-9876-543-211</DIDNumber>
      <ProjectId>6</ProjectId>
      <AllocationRule>SkillBased</AllocationRule>
      <IsActive>true</IsActive>
    </CallSource>
  </CallSources>
</CallSourceConfig>

Error Handling

DID Not Found

ScenarioHandling
Unknown DID arrivesLog unknown_did event, use default project
DID inactiveReject call, notify manager
Database errorFall back to cache, retry query
Cache corruptionClear cache, reload from database

Integration Points

  • Call Handler: Maps incoming calls to correct staff and project
  • Lead Assignment: CallSourceId used to track lead source for analytics
  • Project Manager: Can create/modify CallSource-DID mappings
  • Analytics Dashboard: Queries CallLog for source attribution
  • Staff Allocation: Uses AllocationRule from CallSource

Database Maintenance

Regular Tasks

  1. Cleanup: Archive old/inactive CallSource records quarterly
  2. Audit: Verify DID assignments match active projects
  3. Cache: Monitor cache hit rates, adjust TTL if needed
  4. Orphaned Records: Remove CallSources with no active calls for 30 days

Monitoring

  • Cache hit/miss ratio
  • Average DID lookup time
  • Number of active CallSources
  • Unmatched DIDs (unknown calls)

Related Components

  • Project Management: Defines projects that CallSources belong to
  • Staff Allocation: Uses CallSource AllocationRule for assignment
  • Call Logger: Records CallSourceId for every call
  • Analytics Engine: Aggregates by CallSource for reporting
  • Lead Assignment: External and Facebook leads use CallSourceId