From 4b8fabc204fa71abfd2c79eaf6be95d9bfeddb7a Mon Sep 17 00:00:00 2001 From: Martin Porwoll Date: Mon, 2 Mar 2026 16:12:04 +0000 Subject: [PATCH] feat: make WhatsApp platform/account IDs configurable via env vars WHATSAPP_PLATFORM_ID and WHATSAPP_ACCOUNT_ID can now be set in .env to match CMS entity IDs on different environments (dev vs production). Co-Authored-By: Claude Opus 4.6 --- src/config.ts | 4 ++++ src/payload/InteractionWriter.ts | 22 +++++++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/config.ts b/src/config.ts index 702905e..50f6a29 100644 --- a/src/config.ts +++ b/src/config.ts @@ -29,6 +29,10 @@ const envSchema = z.object({ // CCS Tenant CCS_TENANT_ID: z.coerce.number().default(10), + + // CMS entity IDs (may differ between Dev and Production) + WHATSAPP_PLATFORM_ID: z.coerce.number().default(4), + WHATSAPP_ACCOUNT_ID: z.coerce.number().default(1), }) export type Config = z.infer diff --git a/src/payload/InteractionWriter.ts b/src/payload/InteractionWriter.ts index 448247a..1bab11a 100644 --- a/src/payload/InteractionWriter.ts +++ b/src/payload/InteractionWriter.ts @@ -1,3 +1,4 @@ +import { getConfig } from '../config.js' import { getLogger } from '../lib/logger.js' import type { NormalizedMessage } from '../whatsapp/types.js' import type { LLMResponse } from '../llm/LLMProvider.js' @@ -5,12 +6,15 @@ import type { PayloadClient } from './PayloadClient.js' const log = getLogger('interaction-writer') -// WhatsApp platform + account IDs in CMS -const WHATSAPP_PLATFORM_ID = 4 -const WHATSAPP_ACCOUNT_ID = 1 - export class InteractionWriter { - constructor(private payloadClient: PayloadClient) {} + private platformId: number + private accountId: number + + constructor(private payloadClient: PayloadClient) { + const config = getConfig() + this.platformId = config.WHATSAPP_PLATFORM_ID + this.accountId = config.WHATSAPP_ACCOUNT_ID + } async init(): Promise { log.info('InteractionWriter initialized (REST API mode)') @@ -22,8 +26,8 @@ export class InteractionWriter { ): Promise { try { const data: Record = { - platform: WHATSAPP_PLATFORM_ID, - socialAccount: WHATSAPP_ACCOUNT_ID, + platform: this.platformId, + socialAccount: this.accountId, type: 'dm', externalId: message.messageId, author: { @@ -62,8 +66,8 @@ export class InteractionWriter { const doc = await this.payloadClient.create<{ id: number }>( 'community-interactions', { - platform: WHATSAPP_PLATFORM_ID, - socialAccount: WHATSAPP_ACCOUNT_ID, + platform: this.platformId, + socialAccount: this.accountId, type: 'dm', externalId: `bot-reply-${Date.now()}`, author: {