audit follow-up: burn down lint hotspots and dedupe channel gating flows
This commit is contained in:
@@ -17,7 +17,13 @@ import type {
|
||||
ChannelAdapter,
|
||||
ChannelStatus,
|
||||
} from '../types.js';
|
||||
import { buildResetInboundMessage, normalizeResetCommandText, splitMessage } from '../utils.js';
|
||||
import {
|
||||
allowTrustedOrPairedSender,
|
||||
buildResetInboundMessage,
|
||||
normalizeResetCommandText,
|
||||
shouldIgnoreForMissingMention,
|
||||
splitMessage,
|
||||
} from '../utils.js';
|
||||
import type { PairingManager } from '../pairing.js';
|
||||
|
||||
/** Configuration for the WhatsApp channel adapter. */
|
||||
@@ -224,15 +230,15 @@ export class WhatsAppAdapter implements ChannelAdapter {
|
||||
}
|
||||
|
||||
// Mention requirement in group chats
|
||||
const requireMention = this.config.requireMention ?? true;
|
||||
if (requireMention) {
|
||||
if (this.botId && shouldIgnoreForMissingMention({
|
||||
requireMention: this.config.requireMention,
|
||||
defaultRequireMention: true,
|
||||
mentionsBot: message.body?.includes(`@${this.botId.replace(/@c\.us$/, '')}`) ||
|
||||
(message as unknown as { mentionedIds?: string[] }).mentionedIds?.some((id) => id === this.botId) === true,
|
||||
})) {
|
||||
// WhatsApp mentions use @phone_number format in body
|
||||
// Also check for mentions in the message mentionedIds
|
||||
const mentionsBot = this.botId
|
||||
? message.body?.includes(`@${this.botId.replace(/@c\.us$/, '')}`) ||
|
||||
(message as any).mentionedIds?.some((id: string) => id === this.botId)
|
||||
: false;
|
||||
if (!mentionsBot) {return;}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,24 +250,18 @@ export class WhatsAppAdapter implements ChannelAdapter {
|
||||
this.config.allowedNumbers.length > 0 &&
|
||||
!this.config.allowedNumbers.includes(phoneNumber)
|
||||
) {
|
||||
// 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 {
|
||||
const allowed = await allowTrustedOrPairedSender({
|
||||
pairingManager: this.config.pairingManager,
|
||||
channel: 'whatsapp',
|
||||
senderId: phoneNumber,
|
||||
text: message.body ?? '',
|
||||
isTrusted: false,
|
||||
onPaired: async () => {
|
||||
if (!this.client) {return;}
|
||||
await this.client.sendMessage(from, 'Pairing successful! You can now chat with Flynn.');
|
||||
},
|
||||
});
|
||||
if (!allowed) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user