f145ab8830
Implements Baileys PR #2190 with InfiniteAPI enhancement for Brazilian phone numbers. ## Changes Implemented: ### 1. Caller Phone Number Support (src/Types/Call.ts) - Added `callerPn?: string` field to WACallEvent type - Enables programmatic identification of incoming callers - Documented as sanitized to fix decoder bugs ### 2. Phone Number Extraction (src/Socket/messages-recv.ts:1656-1670) - Extract `caller_pn` attribute from call offer events - Apply sanitization before storing - Preserve callerPn across call state updates (fallback logic) ### 3. Brazilian Landline Bug Fix (CRITICAL ENHANCEMENT) Implemented `sanitizeCallerPn()` helper function (lines 1606-1631): **Problem:** WhatsApp decoder has off-by-one error for Brazilian landlines - 12-digit numbers incorrectly get trailing zero - Example: 551738025555 → 5517380255550 (breaks JID validation) **Solution:** - Detects 13-digit numbers starting with '55' (Brazil country code) - Removes trailing zero to restore correct 12-digit format - Logs sanitization for debugging - Returns undefined for missing/invalid numbers **Impact:** ```typescript // Before sanitization: callerPn: "5517380255550" // ❌ Invalid - 13 digits with extra zero // After sanitization: callerPn: "551738025555" // ✅ Valid - correct 12 digits ``` ## Benefits: - ✅ Caller identification for call filtering (blacklist/whitelist) - ✅ CRM integration via phone number lookup - ✅ Call analytics and logging - ✅ Automated call routing/handling - ✅ Fixes known decoder bug for Brazilian users - ✅ Parité with Baileys upstream - ✅ Backward compatible (optional field) ## Testing Notes: ### Standard Numbers (Working): - Mobile: 10-11 digits → stored as-is - International: varying lengths → stored as-is ### Brazilian Landlines (Fixed): - Input: "5517380255550" (13 digits with bug) - Output: "551738025555" (12 digits corrected) - Log: "Sanitized Brazilian landline number" ### Edge Cases Handled: - undefined/null → returns undefined - Non-Brazilian → no sanitization - Correct length → no sanitization ## References: - Baileys PR: https://github.com/WhiskeySockets/Baileys/pull/2190 - Bug Report: CDPPF comment on landline off-by-one error - Country Code: +55 (Brazil) https://claude.ai/code/session_01TvSrN9JmHZDdKMZDFWEcUS
17 lines
401 B
TypeScript
17 lines
401 B
TypeScript
export type WACallUpdateType = 'offer' | 'ringing' | 'timeout' | 'reject' | 'accept' | 'terminate'
|
|
|
|
export type WACallEvent = {
|
|
chatId: string
|
|
from: string
|
|
isGroup?: boolean
|
|
groupJid?: string
|
|
id: string
|
|
date: Date
|
|
isVideo?: boolean
|
|
status: WACallUpdateType
|
|
offline: boolean
|
|
latencyMs?: number
|
|
/** Phone number of the caller (sanitized to fix Brazilian landline bug) */
|
|
callerPn?: string
|
|
}
|