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 <noreply@anthropic.com>
This commit is contained in:
Martin Porwoll 2026-03-02 16:12:04 +00:00
parent c471e42592
commit 4b8fabc204
2 changed files with 17 additions and 9 deletions

View file

@ -29,6 +29,10 @@ const envSchema = z.object({
// CCS Tenant // CCS Tenant
CCS_TENANT_ID: z.coerce.number().default(10), 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<typeof envSchema> export type Config = z.infer<typeof envSchema>

View file

@ -1,3 +1,4 @@
import { getConfig } from '../config.js'
import { getLogger } from '../lib/logger.js' import { getLogger } from '../lib/logger.js'
import type { NormalizedMessage } from '../whatsapp/types.js' import type { NormalizedMessage } from '../whatsapp/types.js'
import type { LLMResponse } from '../llm/LLMProvider.js' import type { LLMResponse } from '../llm/LLMProvider.js'
@ -5,12 +6,15 @@ import type { PayloadClient } from './PayloadClient.js'
const log = getLogger('interaction-writer') const log = getLogger('interaction-writer')
// WhatsApp platform + account IDs in CMS
const WHATSAPP_PLATFORM_ID = 4
const WHATSAPP_ACCOUNT_ID = 1
export class InteractionWriter { 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<void> { async init(): Promise<void> {
log.info('InteractionWriter initialized (REST API mode)') log.info('InteractionWriter initialized (REST API mode)')
@ -22,8 +26,8 @@ export class InteractionWriter {
): Promise<number> { ): Promise<number> {
try { try {
const data: Record<string, unknown> = { const data: Record<string, unknown> = {
platform: WHATSAPP_PLATFORM_ID, platform: this.platformId,
socialAccount: WHATSAPP_ACCOUNT_ID, socialAccount: this.accountId,
type: 'dm', type: 'dm',
externalId: message.messageId, externalId: message.messageId,
author: { author: {
@ -62,8 +66,8 @@ export class InteractionWriter {
const doc = await this.payloadClient.create<{ id: number }>( const doc = await this.payloadClient.create<{ id: number }>(
'community-interactions', 'community-interactions',
{ {
platform: WHATSAPP_PLATFORM_ID, platform: this.platformId,
socialAccount: WHATSAPP_ACCOUNT_ID, socialAccount: this.accountId,
type: 'dm', type: 'dm',
externalId: `bot-reply-${Date.now()}`, externalId: `bot-reply-${Date.now()}`,
author: { author: {