diff --git a/src/messaging/flow/default-flows/appointment-booking.json b/src/messaging/flow/default-flows/appointment-booking.json index 1a1bc43..8ebabe9 100644 --- a/src/messaging/flow/default-flows/appointment-booking.json +++ b/src/messaging/flow/default-flows/appointment-booking.json @@ -21,7 +21,8 @@ { "id": "v13", "name": "docListResult", "type": "object" }, { "id": "v14", "name": "slotListResult", "type": "object" }, { "id": "v15", "name": "aiGreeting", "type": "string" }, - { "id": "v16", "name": "reason", "type": "string" } + { "id": "v16", "name": "reason", "type": "string" }, + { "id": "v17", "name": "scheduledDateTime", "type": "string" } ], "groups": [ { @@ -189,6 +190,13 @@ "type": "input", "inputType": "any", "variableId": "selectedSlot" + }, + { + "id": "b17a", + "type": "set_variable", + "variableId": "scheduledDateTime", + "value": "selectedSlot", + "expression": "extract_datetime" } ] }, @@ -253,7 +261,7 @@ "phoneNumber": "{{_phone}}", "department": "{{selectedDepartmentTitle}}", "doctorName": "{{selectedDoctor_title}}", - "scheduledAt": "{{selectedSlot}}", + "scheduledAt": "{{scheduledDateTime}}", "reason": "{{reason}}" }, "outputVariableId": "bookingResult" @@ -312,7 +320,7 @@ { "id": "e6", "from": { "blockId": "b13", "conditionId": "c4" }, "to": { "groupId": "g4a" } }, { "id": "e7", "from": { "blockId": "b14" }, "to": { "groupId": "g5" } }, { "id": "e8", "from": { "blockId": "b15" }, "to": { "groupId": "g5" } }, - { "id": "e9", "from": { "blockId": "b17" }, "to": { "groupId": "g6" } }, + { "id": "e9", "from": { "blockId": "b17a" }, "to": { "groupId": "g6" } }, { "id": "e10", "from": { "blockId": "b19" }, "to": { "groupId": "g7" } }, { "id": "e11", "from": { "blockId": "b22", "conditionId": "c5" }, "to": { "groupId": "g8" } }, { "id": "e12", "from": { "blockId": "b22", "conditionId": "c6" }, "to": { "groupId": "g9" } } diff --git a/src/messaging/flow/flow-types.ts b/src/messaging/flow/flow-types.ts index 31656ec..7f0d1e9 100644 --- a/src/messaging/flow/flow-types.ts +++ b/src/messaging/flow/flow-types.ts @@ -81,7 +81,7 @@ export type SetVariableBlock = { type: 'set_variable'; variableId: string; value: string; - expression?: 'extract_id' | 'date_tomorrow' | 'date_day_after'; + expression?: 'extract_id' | 'extract_datetime' | 'date_tomorrow' | 'date_day_after'; }; export type ToolCallBlock = { diff --git a/src/messaging/flow/flow-variable.service.ts b/src/messaging/flow/flow-variable.service.ts index 0a20066..6c5d96e 100644 --- a/src/messaging/flow/flow-variable.service.ts +++ b/src/messaging/flow/flow-variable.service.ts @@ -25,10 +25,16 @@ export class FlowVariableService { evaluateExpression(expression: string, value: string, variables: Record): any { switch (expression) { case 'extract_id': { - // Extract UUID from "doc:{uuid}:{name}" or "dept:{name}" or "slot:{id}:{datetime}" + // Extract second segment: "doc:{uuid}:{name}" → uuid, "dept:{name}" → name const parts = value.split(':'); return parts.length >= 2 ? parts[1] : value; } + case 'extract_datetime': { + // Extract datetime from "slot:{doctorId}:{datetime}" → "2026-04-21T14:00:00" + const parts = value.split(':'); + // Rejoin from index 2 onwards (datetime contains colons: 2026-04-21T14:00:00) + return parts.length >= 3 ? parts.slice(2).join(':') : value; + } case 'date_tomorrow': { const d = new Date(Date.now() + 86400000); return d.toISOString().split('T')[0];