Files
helix-engage-server/src/messaging/messaging.controller.ts
saridsa2 c4c437abd6 fix(messaging): parse postbackText from Gupshup list_reply, pass selection ID to AI
Gupshup list_reply has empty id field — postbackText carries our ID.
Fixed ?? to || fallback. Also inject selection_id into user message so
AI can extract doctorId from "doc:{uuid}:{name}" format.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-20 15:25:35 +05:30

37 lines
1.3 KiB
TypeScript

import { Controller, Post, Body, Logger } from '@nestjs/common';
import { MessagingProvider } from './providers/messaging-provider.interface';
import { MessagingService } from './messaging.service';
@Controller('api/messaging')
export class MessagingController {
private readonly logger = new Logger(MessagingController.name);
constructor(
private readonly provider: MessagingProvider,
private readonly messaging: MessagingService,
) {}
@Post('webhook')
async webhook(@Body() body: any) {
this.logger.log(`[WA-WEBHOOK] Received: ${JSON.stringify(body).substring(0, 500)}`);
if (!this.provider.validateWebhook(body)) {
this.logger.warn('[WA-WEBHOOK] Validation failed — ignoring');
return { status: 'ignored', reason: 'validation failed' };
}
const message = this.provider.parseInbound(body);
if (!message) {
this.logger.log('[WA-WEBHOOK] Non-message event — skipped');
return { status: 'ok', type: body?.type ?? 'unknown' };
}
// Handle async — don't block webhook response
this.messaging.handleInbound(message).catch(err => {
this.logger.error(`[WA-WEBHOOK] handleInbound failed: ${err.message}`);
});
return { status: 'ok' };
}
}