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:
- Call Arrives: Incoming call on DID (e.g., +91-9876-543-210)
- DID Lookup: System queries
CallSourceBLMappingorCallSourcetable - Find Project: Maps DID to specific project, campaign, or business line
- Route & Log: Call is routed to appropriate staff and logged to correct source
CallSource Table Structure
| Field | Type | Purpose |
|---|---|---|
| CallSourceId | PK, Int | Unique identifier for this call source |
| SourceName | String | Human-readable name (e.g., "Home Loan Campaign Q1") |
| DIDNumber | String | Incoming phone number (e.g., "+91-9876-543-210") |
| IsActive | Boolean | Whether this call source accepts new calls |
| ProjectId | FK, Int | Links to project/campaign configuration |
| CreatedDate | DateTime | When this mapping was created |
| LastModified | DateTime | Last update timestamp |
| Description | String | Notes about the source |
| AllocationRule | String | Round-robin, skill-based, manager-assigned |
| DefaultStaffId | FK, Int | Fallback staff if normal allocation fails |
Caching Strategy
To optimize performance, CallSource data is cached using these strategies:
- Application Startup: Load all active CallSource records into memory
- Cache Key:
CallSource_<ProjectId>andDID_<PhoneNumber> - TTL (Time To Live): 1 hour, or manual refresh on configuration change
- Invalidation: When CallSource record is updated or status changed
- 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 attributionDID 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
| Trigger | Action |
|---|---|
| CallSource status changed | Invalidate immediately |
| DID number reassigned | Invalidate old mapping |
| Project updated | Invalidate related sources |
| Manual cache clear | Admin initiated |
| TTL expired | Auto-refresh on next access |
Performance Characteristics
| Operation | Time | Notes |
|---|---|---|
| Cache hit | under 1ms | Dictionary lookup |
| Cache miss + DB query | ~50-100ms | SQL index on DIDNumber |
| Full cache load | ~500ms | One-time on startup |
| Cache refresh | ~1-2 sec | Background 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
| Scenario | Handling |
|---|---|
| Unknown DID arrives | Log unknown_did event, use default project |
| DID inactive | Reject call, notify manager |
| Database error | Fall back to cache, retry query |
| Cache corruption | Clear 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
- Cleanup: Archive old/inactive CallSource records quarterly
- Audit: Verify DID assignments match active projects
- Cache: Monitor cache hit rates, adjust TTL if needed
- 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