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:
2026-04-20 15:25:35 +05:30
parent b1922809d0
commit c4c437abd6
3 changed files with 11 additions and 3 deletions

View File

@@ -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