ChatbotX icon indicating copy to clipboard operation
ChatbotX copied to clipboard

Five of the 22 conditions the Triggers screen offers can never match: the WhatsApp call group falls through to the evaluator's default

Open rawdaymx opened this issue 2 months ago • 0 comments

Summary

The Triggers screen offers 22 conditions. Five of them — the WhatsApp call group — can never match, so a rule built on any of them never fires. Not with an error, not with a log line: ConditionEvaluator.evaluate has no case for them, they reach default: return false at condition-evaluator.ts:66-67, and TriggerMatcher turns one non-matching condition into a non-matching rule at trigger-matcher.service.ts:93.

What isolates it. Three things say this is a wiring gap rather than a feature that was never built:

  1. The events are emitted, from real handlers, all five of them (see the table below). Nothing is missing on the producing side.
  2. The webhook payload builder maps all five (webhook-payload.builder.ts:46-50 and :196-212), so the same five events do reach outgoing webhooks. It is only the Triggers path that drops them.
  3. Upstream already knows how to hide a condition it does not support. The ticket and commerce conditions are commented out in add-condition.tsx:161 onwards, so they never reach the picker. The five call conditions are not commented out — they are offered.

And the neighbours work, which is what makes the gap specific rather than general: the two referral conditions in the same return true group are handled by the evaluator and emitted (ref.ts:298-307), so the group this patch extends is a live code path, not dead code.

Environment

Measured against upstream/main = e4913ef2a
How Read and ran the repository. Behaviour established by running the evaluator, not by reading alone

Measurement

triggerEventTypes (packages/database/src/partials/trigger.ts:22-62) declares 39 event types. ConditionEvaluator.evaluate has a case for 17; the other 22 reach default: return false.

Of the 22 the screen offers (add-condition.tsx), 5 are in that unhandled set — all five calls:

Condition offered Emitted at Evaluator
incomingCall apps/worker/src/integration/handlers/whatsapp-call.ts:369 falls to default
missedAudioCall apps/worker/src/integration/handlers/shared/whatsapp-call-finalize.ts:414 falls to default
callEnded apps/worker/src/integration/handlers/shared/whatsapp-call-finalize.ts:409 falls to default
callRecorded apps/worker/src/integration/handlers/whatsapp-call-recording.ts:121 falls to default
callTranscribed whatsapp-call-native-transcript.ts:235, whatsapp-call-transcribe.ts:144 falls to default

The remaining 17 unhandled types are the ticket and commerce events, which the screen keeps commented out — consistent with them not being evaluated.

Evidence

Five cases added to your condition-evaluator.test.ts, one per condition, plus a control.

Against e4913ef2a unmodified — exit 1:

 × incomingCall matches the event that carries it
 × missedAudioCall matches the event that carries it
 × callEnded matches the event that carries it
 × callRecorded matches the event that carries it
 × callTranscribed matches the event that carries it
 Test Files  1 failed (1)

With the patch — exit 0, Tests 23 passed (23).

The control is the part that makes the five green mean something: a condition the screen does not offer (ticketCreated) must still not match. It passes in both runs, so the patch did not simply make evaluate return true for everything.

Full worker suite with the patch, --force: 263 files / 3199 cases passed. Two files / 5 cases fail, and they are the Windows path-separator defects reported separately in #1397 — identical to this base commit's baseline measured the same day, so this change introduces no regression. check-types across the workspace: 59 of 59.

Where it comes from

  • apps/worker/src/trigger/services/condition-evaluator.ts:19-68 — the switch; :66-67 is the default: return false the five land on
  • apps/worker/src/trigger/services/trigger-matcher.service.ts:80-98 — if (!isMatch) { return false }, so one unmatched condition fails the whole rule
  • apps/builder/src/features/triggers/add-condition.tsx:130-159 — the five offered under the WhatsApp group, each with createDefaultFn(type) and no source or operator

Why we think this is a defect rather than the intended design

The obvious alternative reading is "calls are not supported by Triggers yet". Three measurements argue against it:

  • The repository's way of expressing "not supported yet" in this exact file is a comment block, and it is used for tickets and commerce — not for calls.
  • The events are emitted and consumed elsewhere (webhooks), so this is not a half-built feature with no producer.
  • We looked for a test or comment pinning the default branch as deliberate for calls, and there is none: condition-evaluator.test.ts covers contactInfoUpdated, dateTimeBasedTrigger and customFieldValueChanged, and says nothing about the unhandled types.

If calls are in fact meant to be unavailable for now, the fix is the opposite one — comment them out of add-condition.tsx like the others — and we would rather you tell us that than guess. The patch assumes the picker is right.

Suggested fix

Add the five to the group of conditions that match on the event alone, which is what the screen already treats them as (no source, no operator):

       case triggerEventTypes.enum.contactReferredANewContact:
       case triggerEventTypes.enum.contactReferredExistingContact:
+      case triggerEventTypes.enum.incomingCall:
+      case triggerEventTypes.enum.missedAudioCall:
+      case triggerEventTypes.enum.callEnded:
+      case triggerEventTypes.enum.callRecorded:
+      case triggerEventTypes.enum.callTranscribed:
         return true

PR attached, with the five tests and the control.

What we did not verify

  • We did not place a real WhatsApp call. The defect and the fix are established at the evaluator, where the decision is made, plus the emission sites read from the tree. We did not drive a call end-to-end through a connected WhatsApp number and watch a rule fire.
  • We did not check whether the active-rule cache in packages/events/src/trigger/cache.ts has its own path for these events; it gates whether the emitter runs at all and is orthogonal to the match decision, but we did not measure it.
  • We did not audit whether the metadata each call event carries is enough for a future condition that does filter (by duration, say). This patch deliberately matches on the event alone, because that is all the screen collects today.
  • The 17 ticket and commerce types were not investigated beyond confirming they are commented out of the picker.

Related issues - none of these describes it

Searched this repository's issues for trigger conditions, call conditions and incomingCall; nothing open covers it. The search instrument was confirmed against a query that does return results, so the empty results are real absences.

rawdaymx avatar Oct 02 '26 20:10 rawdaymx