fix(whatsapp): make every silent disposition observable, stop pure silence for linked senders (#1563)
* fix(whatsapp): make every silent disposition observable, stop pure silence for linked senders (#1552) Silence was a legitimate outcome in seven places and none left a trace a support question could be answered from. Now: - Unknown-sender declines (over quota, quota RPC failure, greeting throttle) persist content-free trace rows: wamid, phone hash, type, disposition. No body, media, raw payload, or profile name; capped at 20 rows per hash and day; deleted by the existing 30-day retention. The wamid dedupe also stops redelivered bad-code/greeting messages from earning a second reply. - Linked-sender deliberate silences (muted, stale tap, ignorable type) record their reason on the skipped row. - Non-policy silences reply: a row missing its media reference sends M18 through the link's reply address, a link revoked between arrival and processing sends the M1 unlinked copy (greeting-throttled). - Outbound rows keep WHY a send failed (Graph error detail), and Meta 'failed' delivery statuses store their error code and title. - The WhatsApp settings panel shows the last inbound event (closed enum, server-derived) and warns when the latest reply never left. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * test(whatsapp): include errorDetail in typed sendText mock results SendTextResult gained errorDetail; vi.mocked call sites must match the widened type or they raise fresh tsc errors over the repo baseline. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(whatsapp): review fixes: fail-closed greeting throttle, cap only declined traces From CodeRabbit's pass on #1563: - greetingThrottled fails closed when the throttle window cannot be read, matching the unknown-sender quota's stance. - The decline-trace day cap applies only to 'skipped' rows (the one unbounded path); 'done' traces always insert so the wamid dedupe keeps preventing duplicate M1/M2 replies even past the cap. Their volume is already bounded upstream by the greeting throttle and the pre-binding quota. - company-question test mocks match the widened SendTextResult. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
Jakob Wennberg
parent
73c63209f1
commit
6c64dd2312
@@ -14,9 +14,11 @@ import { useCallback, useEffect, useState } from 'react'
|
||||
import { useTranslations } from 'next-intl'
|
||||
import { Loader2, ExternalLink } from 'lucide-react'
|
||||
import { WhatsAppMark } from '@/components/extensions/general/WhatsAppMark'
|
||||
import { AttnLine } from '@/components/ui/attn-line'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { useToast } from '@/components/ui/use-toast'
|
||||
import { useCompany } from '@/contexts/CompanyContext'
|
||||
import { useFormat } from '@/lib/hooks/use-format'
|
||||
import {
|
||||
SettingsGroup,
|
||||
SettingsRow,
|
||||
@@ -26,11 +28,28 @@ import {
|
||||
|
||||
const BASE = '/api/extensions/ext/whatsapp-inbox'
|
||||
|
||||
/** Closed enum from the server (lib/last-event.ts); translated here. */
|
||||
const LAST_EVENT_KINDS = new Set([
|
||||
'filed',
|
||||
'handled',
|
||||
'processing',
|
||||
'awaiting_company',
|
||||
'duplicate',
|
||||
'rate_limited',
|
||||
'unsupported',
|
||||
'muted',
|
||||
'declined',
|
||||
'failed',
|
||||
])
|
||||
|
||||
interface LinkStatus {
|
||||
linked: boolean
|
||||
phoneMasked?: string
|
||||
defaultCompanyId?: string | null
|
||||
muted?: boolean
|
||||
lastInboundAt?: string | null
|
||||
lastInboundEvent?: string | null
|
||||
lastReplyFailed?: boolean
|
||||
}
|
||||
|
||||
interface MintedCode {
|
||||
@@ -43,6 +62,7 @@ export function WhatsAppLinkPanel() {
|
||||
const t = useTranslations('settings_whatsapp')
|
||||
const { toast } = useToast()
|
||||
const { companies } = useCompany()
|
||||
const { locale, formatDateLong } = useFormat()
|
||||
|
||||
const [isLoading, setIsLoading] = useState(true)
|
||||
const [loadFailed, setLoadFailed] = useState(false)
|
||||
@@ -167,6 +187,27 @@ export function WhatsAppLinkPanel() {
|
||||
</SettingsRow>
|
||||
) : null}
|
||||
|
||||
{status.lastInboundAt ? (
|
||||
<SettingsRow label={t('last_event_label')}>
|
||||
<div className="space-y-1">
|
||||
<span className="text-sm">
|
||||
{formatDateLong(status.lastInboundAt)}{' '}
|
||||
{new Date(status.lastInboundAt).toLocaleTimeString(
|
||||
locale === 'en' ? 'en-GB' : 'sv-SE',
|
||||
{ hour: '2-digit', minute: '2-digit' },
|
||||
)}
|
||||
{' · '}
|
||||
{t(
|
||||
status.lastInboundEvent && LAST_EVENT_KINDS.has(status.lastInboundEvent)
|
||||
? `last_event_${status.lastInboundEvent}`
|
||||
: 'last_event_handled',
|
||||
)}
|
||||
</span>
|
||||
{status.lastReplyFailed ? <AttnLine>{t('last_reply_failed')}</AttnLine> : null}
|
||||
</div>
|
||||
</SettingsRow>
|
||||
) : null}
|
||||
|
||||
<SettingsRow label={t('default_company_label')} help={t('default_company_help')}>
|
||||
<SettingsSelect
|
||||
aria-label={t('default_company_label')}
|
||||
|
||||
Reference in New Issue
Block a user