mirror of
https://dev.azure.com/globalhealthx/EMR/_git/helix-engage-server
synced 2026-05-18 20:08:19 +00:00
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>
This commit is contained in:
@@ -13,7 +13,7 @@ export class MessagingController {
|
||||
|
||||
@Post('webhook')
|
||||
async webhook(@Body() body: any) {
|
||||
this.logger.log(`[WA-WEBHOOK] Received: ${JSON.stringify(body).substring(0, 300)}`);
|
||||
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');
|
||||
|
||||
@@ -72,9 +72,15 @@ export class MessagingService {
|
||||
|
||||
// 3. Load conversation history
|
||||
const history = await this.conversation.getHistory(phone);
|
||||
// For interactive replies, include the selection ID so the AI can
|
||||
// extract structured data (e.g. "doc:{uuid}:{name}" → doctorId)
|
||||
let userContent = text;
|
||||
if (message.type === 'interactive_reply' && message.interactiveReply?.id) {
|
||||
userContent = `[Selected: ${message.interactiveReply.title}] (selection_id: ${message.interactiveReply.id})`;
|
||||
}
|
||||
const messages = [
|
||||
...history.map(h => ({ role: h.role as 'user' | 'assistant', content: h.content })),
|
||||
{ role: 'user' as const, content: text },
|
||||
{ role: 'user' as const, content: userContent },
|
||||
];
|
||||
|
||||
// 4. Build system prompt
|
||||
|
||||
@@ -47,12 +47,14 @@ export class GupshupProvider extends MessagingProvider {
|
||||
}
|
||||
|
||||
if (msgType === 'button_reply' || msgType === 'list_reply') {
|
||||
// Gupshup sends postbackText (our ID), id can be empty string
|
||||
const replyId = payload.payload?.postbackText || payload.payload?.id || payload.payload?.reply || '';
|
||||
return {
|
||||
phone, name,
|
||||
text: payload.payload?.title ?? '',
|
||||
type: 'interactive_reply',
|
||||
interactiveReply: {
|
||||
id: payload.payload?.id ?? payload.payload?.postbackText ?? '',
|
||||
id: replyId,
|
||||
title: payload.payload?.title ?? '',
|
||||
},
|
||||
rawPayload: body,
|
||||
|
||||
Reference in New Issue
Block a user