mirror of
https://github.com/complexcaresolutions/whatsapp-bot.git
synced 2026-03-17 17:24:06 +00:00
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:
parent
c471e42592
commit
4b8fabc204
2 changed files with 17 additions and 9 deletions
|
|
@ -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<typeof envSchema>
|
||||
|
|
|
|||
|
|
@ -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<void> {
|
||||
log.info('InteractionWriter initialized (REST API mode)')
|
||||
|
|
@ -22,8 +26,8 @@ export class InteractionWriter {
|
|||
): Promise<number> {
|
||||
try {
|
||||
const data: Record<string, unknown> = {
|
||||
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: {
|
||||
|
|
|
|||
Loading…
Reference in a new issue