feat: complete DM pairing codes with channel adapters, gateway handlers, and TUI command (Tier 4 feature 4)

This commit is contained in:
William Valentin
2026-02-09 18:28:10 -08:00
parent 9d4d440ecf
commit 1e29da4da2
11 changed files with 270 additions and 7 deletions
+23 -1
View File
@@ -18,6 +18,7 @@ import type {
ChannelStatus,
} from '../types.js';
import { splitMessage } from '../utils.js';
import type { PairingManager } from '../pairing.js';
/** Configuration for the WhatsApp channel adapter. */
export interface WhatsAppAdapterConfig {
@@ -29,6 +30,8 @@ export interface WhatsAppAdapterConfig {
requireMention?: boolean;
/** Directory for session persistence (LocalAuth data path). */
dataDir?: string;
/** Optional pairing manager for DM pairing codes. */
pairingManager?: PairingManager;
}
/** Minimal shape of a whatsapp-web.js message. */
@@ -232,7 +235,26 @@ export class WhatsAppAdapter implements ChannelAdapter {
this.config.allowedNumbers.length > 0 &&
!this.config.allowedNumbers.includes(phoneNumber)
) {
return;
// Pairing fallback — check if the sender is approved or sending a valid code
const pm = this.config.pairingManager;
if (pm?.enabled) {
if (pm.isApproved('whatsapp', phoneNumber)) {
// Approved — fall through to normal message handling
} else {
const text = (message.body ?? '').trim();
if (text && pm.validateCode('whatsapp', phoneNumber, text)) {
// Code validated — send confirmation via WhatsApp
if (this.client) {
try {
await this.client.sendMessage(from, 'Pairing successful! You can now chat with Flynn.');
} catch { /* ignore send errors */ }
}
}
return;
}
} else {
return;
}
}
}