feat(GRO-106): inbound Telnyx webhook + persistence #378

Merged
groombook-engineer[bot] merged 11 commits from feat/GRO-106-inbound-webhook into dev 2026-05-11 00:43:40 +00:00

11 Commits

Author SHA1 Message Date
Chris Farhood 92ec76efd8 merge: resolve dev merge conflicts in package.json + lockfile
Kept uuid@^11.1.1 (feature branch version, newer than dev's ^11.0.5).
Regenerated pnpm-lock.yaml.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-05-04 21:08:15 +00:00
Chris Farhood 3746c098b5 fix(GRO-982): simplify test mocks to match actual code flow 2026-05-04 04:38:26 +00:00
Chris Farhood fe6357e0fd fix(GRO-982): add missing message insert mock in handleMessageReceived test 2026-05-04 04:36:18 +00:00
Chris Farhood c7f056e38c fix(GRO-982): address QA round 4 blocking failures
- Fix URL in signature tests: use /messaging not full path
- Reorder mocks: businessSettings first, then conversations, clients, messages
- Add mockDb.mockReset in handleMessageFinalized beforeEach
- Remove direction guard: set delivered for any message.finalized
2026-05-04 04:33:46 +00:00
Chris Farhood 932d9bb72a fix(GRO-982): look up or create client by phone before inserting conversation
Fixes FK constraint violation where clientId was set to businessSettings.id
or a random UUID. Now looks up clients.phone = clientPhone first; if no match,
creates a placeholder client with phone as name and a placeholder email.
2026-05-04 04:33:19 +00:00
Chris Farhood efdf3e6ed4 fix(GRO-982): address 5 test failures in inbound webhook
- Fix signature route tests: use /messaging not full mount path
- Fix handleMessageReceived mock order: business lookup first
- Fix stale mock state: add full mockReset in handleMessageFinalized beforeEach
- Fix delivery logic: set delivered for all message.finalized events
- Deduplicate test that was accidentally added twice

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-05-04 04:00:58 +00:00
Chris Farhood 6f98c4aacc chore: add uuid dependency for messaging services 2026-05-04 03:43:46 +00:00
Chris Farhood daba925fc8 fix(GRO-982): address all QA blocking failures
- #7: Extract validateTelnyxSignature in sms.ts as standalone exported fn,
  reuse in TelnyxProvider.validateWebhookSignature and telnyx.ts route
- #1: Replace uuid v4 import with crypto.randomUUID() (built-in, no dep)
- #2: Remove updatedAt from messages update in handleMessageFinalized
  (no such column exists)
- #3: Fix test import path ../../ → ../../../ for telnyx route import
- #4: validateTelnyxSignature accepts string | undefined | null to match
  Hono c.req.header() return type
- #5&6: Add null guards for .returning() results in findOrCreateConversation
  and upsertMessage
- #8: Remove dead buildFindOrCreateConversationParams function
- #9: Remove unused imports (messageDirectionEnum, messageStatusEnum,
  resolveBusinessIdByMessagingNumber in test)
- #10: Wrap upsertMessage insert in try/catch; unique violation returns
  {isNew: false} instead of crashing
- #11: Add EOF newlines to all modified files

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-05-04 03:06:57 +00:00
Chris Farhood c79b5220a4 feat(GRO-106): inbound Telnyx webhook + persistence
- Add POST /api/webhooks/telnyx/messaging route with HMAC signature verification
- Add services/messaging/inbound.ts: findOrCreateConversation, upsertMessage (idempotent on providerMessageId), delivery receipt handling
- Register telnyxWebhooksRouter in index.ts (before auth middleware)
- Add unit tests for signature validation, find-or-create, idempotent insert, delivery receipt

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-05-04 02:38:27 +00:00
Chris Farhood 2e24c371c3 fix(GRO-981): restore journal entries and add DESC to indexes
- _journal.json: restore idx 28 (0028_sms_reminders), add idx 29
  (0029_db_indexes_constraints), renumber 0030_messaging to idx 30
  (was missing 0028 and 0029 entries — they were silently skipped)
- schema.ts: add .desc() to conversations.lastMessageAt and
  messages.createdAt indexes per spec
- 0030_messaging.sql: add DESC to both generated index statements

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-05-04 02:16:25 +00:00
Chris Farhood 5e103a378c feat(GRO-106): messaging schema + migrations
- Add conversations, messages, message_attachments, message_consent_events tables
- Add messagingChannelEnum, messageDirectionEnum, messageStatusEnum, messageConsentKindEnum
- Extend business_settings with messagingPhoneNumber and telnyxMessagingProfileId columns
- Add required indexes and unique constraints with cascade-on-delete FKs
- Add migration 0030_messaging.sql

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-05-04 01:29:32 +00:00