feat: complete DM pairing codes with channel adapters, gateway handlers, and TUI command (Tier 4 feature 4)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user