-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathsubagente-citas.json
More file actions
586 lines (586 loc) · 24.4 KB
/
Copy pathsubagente-citas.json
File metadata and controls
586 lines (586 loc) · 24.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
{
"name": "subagenteCitas",
"nodes": [
{
"parameters": {
"httpMethod": "POST",
"path": "00000000-0000-0000-0000-000000000000",
"responseMode": "lastNode",
"options": {}
},
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
288,
0
],
"id": "35ba4482-3fe6-459c-bfff-2476e8fb50e1",
"name": "Webhook",
"webhookId": "00000000-0000-0000-0000-000000000000"
},
{
"parameters": {
"model": "minimax/minimax-m2.5",
"options": {}
},
"type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
"typeVersion": 1,
"position": [
624,
240
],
"id": "69291e19-4ccb-4588-bb76-7e34652caac0",
"name": "OpenRouter Chat Model",
"credentials": {
"openRouterApi": {
"id": "your-openrouter-cred",
"name": "OpenRouter account"
}
}
},
{
"parameters": {
"sessionIdType": "customKey",
"sessionKey": "={{ $('Webhook').item.json.body.telefono }}/{{ $('Webhook').item.json.body.ycbmUrl }}"
},
"type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
"typeVersion": 1.3,
"position": [
768,
240
],
"id": "b3e62623-0fac-44fa-8da9-5aa8c0ded989",
"name": "Simple Memory"
},
{
"parameters": {
"schemaType": "manual",
"inputSchema": "{\n \"type\": \"array\",\n \"items\": {\n \"type\": \"object\",\n \"properties\": {\n \"date\": { \"type\": \"string\", \"description\": \"AAAA-MM-DD\" },\n \"start\": { \"type\": \"string\", \"description\": \"HH:mm\" },\n \"end\": { \"type\": \"string\", \"description\": \"HH:mm\" },\n \"exact\": { \"type\": \"boolean\", \"description\": \"true si la frase incluye hora exacta\" }\n },\n \"required\": [\"date\",\"start\",\"end\",\"exact\"]\n }\n}\n"
},
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"typeVersion": 1.2,
"position": [
912,
240
],
"id": "9461ec9c-aa3d-4be5-a85f-253e0af5fa6f",
"name": "Structured Output Parser"
},
{
"parameters": {
"jsCode": "// 1) Entradas del webhook\nconst ycbmUrl = $input.first().json.body.ycbmUrl\n// 2) Separamos host y query\nconst [beforeQuery, afterQuery = ''] = ycbmUrl.split('?');\nconst host = beforeQuery.split('//')[1].split('/')[0]; // \"santifer-citav2-componentes.youcanbook.me\"\nconst subdomain = host.split('.')[0]; // \"santifer-citav2-componentes\"\n\n// 3) Parseamos la query string (clave=valor&...)\nconst queryVars = {};\nif (afterQuery) {\n afterQuery.split('&').forEach(pair => {\n const [rawKey, rawVal = ''] = pair.split('=');\n const key = rawKey.toUpperCase();\n const val = decodeURIComponent(rawVal.replace(/\\+/g, ' '));\n queryVars[key] = val;\n });\n}\n\n// … tu lógica de parsing …\n\nconst result = {\n subdomain,\n queryVars\n};\n\n// Devuelve un único string (JSON), no un objeto\nreturn result;\n"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
480,
0
],
"id": "ab3a237f-9b14-4573-a99a-e6789171377a",
"name": "ParseURL"
},
{
"parameters": {
"method": "POST",
"url": "https://api.youcanbook.me/v1/intents",
"authentication": "genericCredentialType",
"genericAuthType": "httpBasicAuth",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Content-Type",
"value": "application/json"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"subdomain\": \"{{ $('ParseURL').item.json.subdomain}}\"\n}",
"options": {}
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
1024,
0
],
"id": "56c6833f-9b7a-4795-afa1-bb79663cd013",
"name": "CreateIntent",
"credentials": {
"httpBasicAuth": {
"id": "your-ycbm-cred",
"name": "YCBM"
}
}
},
{
"parameters": {
"url": "=https://api.youcanbook.me/v1/intents/{{$json.id}}/availabilitykey",
"authentication": "genericCredentialType",
"genericAuthType": "httpBasicAuth",
"options": {}
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
1184,
0
],
"id": "0e7f1af1-71a0-4a4c-9f8b-702e7e87edf6",
"name": "availabilityKey",
"credentials": {
"httpBasicAuth": {
"id": "your-ycbm-cred",
"name": "YCBM"
}
}
},
{
"parameters": {
"url": "=https://api.youcanbook.me/v1/availabilities/{{$json.key }}",
"authentication": "genericCredentialType",
"genericAuthType": "httpBasicAuth",
"options": {}
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
1344,
0
],
"id": "5af74f3c-e477-49bf-a066-ed120158f59e",
"name": "GetAvailabilities",
"credentials": {
"httpBasicAuth": {
"id": "your-ycbm-cred",
"name": "YCBM"
}
}
},
{
"parameters": {
"jsCode": "// 1) Ranges que devolvió tu Agente IA\nconst ranges = Array.isArray($('AnalizarDisponibilidad').first().json.output)\n ? $('AnalizarDisponibilidad').first().json.output\n : [];\n\n// 2) Disponibilidades (cada item con freeUnits y startsAt)\nconst availItems = $input.first().json.slots\n\n// 3) Formatters para fecha y hora en Europe/Madrid\nconst fmtDate = new Intl.DateTimeFormat('sv', {\n timeZone: 'Europe/Madrid',\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n}); \nconst fmtTime = new Intl.DateTimeFormat('en-GB', {\n timeZone: 'Europe/Madrid',\n hour12: false,\n hour: '2-digit',\n minute: '2-digit',\n});\n\nconst slots = [];\n\n// 4) Por cada rango, filtramos\nfor (const r of ranges) {\n for (const o of availItems) {\n const ts = Number(o.startsAt);\n const d = new Date(ts);\n\n // 4.1 Obtener fecha local en España: \"YYYY-MM-DD\"\n const localDate = fmtDate.format(d); \n\n if (localDate !== r.date) continue;\n\n // 4.2 Obtener hora local en España: [\"HH\",\"mm\"]\n const [hour, minute] = fmtTime.format(d).split(':');\n const localTime = `${hour}:${minute}`;\n\n // 4.3 Comparar con r.start y r.end (ambos \"HH:mm\")\n if (localTime >= r.start && localTime < r.end) {\n slots.push({\n date: r.date,\n timestamp: ts,\n start: localTime,\n });\n }\n }\n}\n\n// 5) Emitir resultado\n// Devuelve SIEMPRE un array de items:\n// - si slots.length===0 → [], \n// - si slots.length===1 → [el único slot], \n// - si slots.length>1 → [todos los slots]\nreturn [\n {\n json: {\n slots // el array completo, aunque sea []\n }\n }\n];"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1504,
0
],
"id": "9ded1ff9-0e76-4fbc-aab3-3484a7c2b6dd",
"name": "FilterSlots"
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict",
"version": 2
},
"conditions": [
{
"id": "74ebf21d-d956-45b9-9fb3-7bbaea1d3df8",
"leftValue": "={{ $json.slots.length }}",
"rightValue": 1,
"operator": {
"type": "number",
"operation": "equals"
}
}
],
"combinator": "and"
},
"options": {}
},
"type": "n8n-nodes-base.if",
"typeVersion": 2.2,
"position": [
1664,
0
],
"id": "3cec61e1-5aff-4cd1-8ac1-a4dd48aea930",
"name": "If"
},
{
"parameters": {
"promptType": "define",
"text": "=preferenciaHoraria = \"{{ $('Webhook').item.json.body.preferencia }}\"",
"hasOutputParser": true,
"options": {
"systemMessage": "=Eres un micro-servicio que convierte frases de preferencia horaria fecha y hora (español de España)\nen un array JSON de rangos.\n\nREGLAS DE NEGOCIO\n1. Rangos por defecto:\n – mañana = 10:00-14:00\n – tarde = 17:00-21:00\n – “todo el día” = 10:00-21:00\n2. `exact` será true **solo** si el usuario da una hora puntual que termine en 00 o 30 (ej. “lunes a las 10” o \"martes a las 17:30\" pero no \"miércoles a las 10:15\").\n Si menciona un rango (“martes de 10 a 12”) ⇒ `exact:false`.\n3. Horas con minutos ≠ 00 ó 30 se redondean:\n - Redondea **hacia abajo** al múltiplo de 30 min anterior.\n - Crea un rango de 1 hora a partir de esa hora redondeada\n (ej. 10:15 ⇒ 10:00-11:00, exact:true porque originalmente era puntual).\n4. La fecha actual es {{ $now.format('yyyy-MM-dd HH:mm') }} (Europe/Madrid).\n5. Acepta varias peticiones separadas por “y”, comas o punto y coma.\n6. Devuelve EXCLUSIVAMENTE una llamada de función con esta forma:\n\n\n{\n \"name\": \"slots\",\n \"arguments\": {\n \"slots\": [\n { \"date\":\"AAAA-MM-DD\",\"start\":\"HH:mm\",\"end\":\"HH:mm\",\"exact\":true/false }\n ]\n }\n}\n\n6.1 Si la frase incluye “mañana” sin especificar parte del día \n (p.ej. “mañana en cualquier momento”, “para mañana”), \n trátalo como «todo el día» de mañana, usando el horario de \n negocio completo (10:00–21:00) del día siguiente. \n\n\n7. Si el usuario usa un término PLURAL (“mañanas”, “tardes”, \"jueves por la mañana\", \"martes por las mañanas y jueves por las tardes\")\n y no especifica fecha concreta, devuelve las próximas N=3 franjas\n que encajen con ese bloque horario:\n – Incluye el día de hoy si la franja aún no ha terminado;\n – Si ya pasó, empieza mañana;\n – Usa los rangos por defecto (mañana 10-14 h, tarde 17-21 h)\n\n8. El negocio sólo abre **de lunes a viernes**. \n Nunca devuelvas slots en sábado (Sa) ni domingo (Do).\n9. Si la frase contiene conectores condicionales (“o”, “o bien”,\n “o si no”, “sino”, “de lo contrario”), trátalos como\n **preferencias alternativas**. Devuelve los slots en el\n mismo orden en que aparecen en la frase.\n\n10. “A partir de [día]” significa:\n – usa el rango “todo el día” (10:00-21:00) en el día indicado;\n – incluye las siguientes N-1 fechas laborables consecutivas;\n – respeta la regla de no incluir sábados ni domingos.\n\n11. El parámetro N=5 por defecto (configurable).\n\n12. Si especifica un día concreto (por ejemplo, este viernes), dar sólo las horas de ese día\n\n13. “Esta semana / algún día de esta semana / cualquier día de esta semana” \n ⇒ LISTA TODAS las franjas laborables (Lu-Vi) que resten hasta el domingo incluido. \n\n14. PLURALES (“mañanas”, “tardes”, “días”) \n ⇒ DEVUELVE las PRÓXIMAS **3** franjas que encajen, empezando por hoy si aún no ha pasado.\n\n// Añadir al final del systemMessage:\n\"15. Si no se proporciona ninguna preferencia horaria o la frase está vacía:\\n\" +\n\" - Devuelve slots para los próximos 3 días laborables\\n\" +\n\" - Usa el rango 'todo el día' (10:00-21:00) para cada día\\n\" +\n\" - exact: false\\n\\n\" +\n\"Input: \\\"\\\"\\n\" +\n\"Output:\\n\" +\n\"{\\\"slots\\\":[\\n\" +\n\" {\\\"date\\\":\\\"{{ $now.format('yyyy-MM-dd') }}\\\",\\\"start\\\":\\\"10:00\\\",\\\"end\\\":\\\"21:00\\\",\\\"exact\\\":false},\\n\" +\n\" {\\\"date\\\":\\\"{{ $now.plus({days:1}).format('yyyy-MM-dd') }}\\\",\\\"start\\\":\\\"10:00\\\",\\\"end\\\":\\\"21:00\\\",\\\"exact\\\":false},\\n\" +\n\" {\\\"date\\\":\\\"{{ $now.plus({days:2}).format('yyyy-MM-dd') }}\\\",\\\"start\\\":\\\"10:00\\\",\\\"end\\\":\\\"21:00\\\",\\\"exact\\\":false}\\n\" +\n\"]}\"\n\n# EJEMPLOS\nInput: \"mañana por la mañana\"\nOutput:\n{\"slots\":[{\"date\":\"{{ $now.plus({days:1}).format('yyyy-MM-dd') }}\",\"start\":\"10:00\",\"end\":\"14:00\",\"exact\":false}]}\n\nInput: \"jueves por la tarde\"\nOutput:\n{\"slots\":[{\"date\":\"2025-29-05\",\"start\":\"17:00\",\"end\":\"21:00\",\"exact\":false}]}\n\nInput: \"martes de 10 a 12 y viernes todo el día\"\nOutput:\n{\"slots\":[\n {\"date\":\"2025-05-27\",\"start\":\"10:00\",\"end\":\"12:00\",\"exact\":false},\n {\"date\":\"2025-05-30\",\"start\":\"10:00\",\"end\":\"21:00\",\"exact\":false}\n]}\n\nInput: \"lunes a las 10\"\nOutput:\n{\"slots\":[{\"date\":\"2025-26-05\",\"start\":\"10:00\",\"end\":\"11:00\",\"exact\":true}]}\n\nInput: \"hoy a las 10:15\"\nOutput:\n{\"slots\":[{\"date\":\"{{ $now.format('yyyy-MM-dd') }}\",\"start\":\"10:00\",\"end\":\"11:00\",\"exact\":false}]}"
}
},
"type": "@n8n/n8n-nodes-langchain.agent",
"typeVersion": 2,
"position": [
672,
0
],
"id": "12c55f2f-24f6-4613-87a8-a305709e9bf7",
"name": "AnalizarDisponibilidad"
},
{
"parameters": {
"jsCode": "// 1) Datos de entrada\nconst queryVars = $('ParseURL').first().json.queryVars || {};\nconst subdomain = $('ParseURL').first().json.subdomain || {};\nconst timestamp = $('FilterSlots').first().json.slots[0].timestamp\nconst email = $('Webhook').first().json.body.email;\nconst telefono = $('Webhook').first().json.body.telefono;\nconst comentarios = $('Webhook').first().json.body.comentarios;\nconst textDiag= 'Diagnóstico';\n\n// 2) Creamos el body plano\n// … tu lógica para timestamp, queryVars, email y telefono …\nconst body = {\n startsAt: timestamp,\n form: [\n { id: \"EMAIL\", value: email },\n { id: \"Q2\", value: telefono },\n { id: \"Q5\", value: true },\n // y ahora los campos de queryVars dinámicos:\n ...Object.entries(queryVars).map(([k,v]) => ({ id: k, value: v })),\n ]\n};\n\nif (subdomain.includes('diagnostico')) {\n const comentarios2 = 'Cita de diagnóstico tomada por Jacobo: ' + comentarios\n body.form.push({ id: 'Q6', value: comentarios2 ?? '' });\n body.form.push({ id: 'REP', value: textDiag ?? '' });\n}\n\nreturn [{ json: body }];\n\n\n// si mañana tienes OTRACOSA en queryVars, añade otro if...\n\n// 4) Devolvemos un único item con el body listo para el HTTP Request\nreturn [\n { json: body }\n];"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1888,
-96
],
"id": "f955981e-cc50-43a9-a2e0-03426f707dc9",
"name": "preparePatchBody"
},
{
"parameters": {
"method": "PATCH",
"url": "=https://api.youcanbook.me/v1/intents/{{ $('CreateIntent').item.json.id }}/selections",
"authentication": "genericCredentialType",
"genericAuthType": "httpBasicAuth",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Content-Type",
"value": "application/json"
}
]
},
"sendBody": true,
"specifyBody": "=json",
"bodyParameters": {
"parameters": [
{}
]
},
"jsonBody": "={{ $json }}",
"options": {}
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
2400,
-96
],
"id": "41f8b9bb-efcb-436e-9fab-454cd15dd8d2",
"name": "patchSelections",
"credentials": {
"httpBasicAuth": {
"id": "your-ycbm-cred",
"name": "YCBM"
}
}
},
{
"parameters": {
"method": "PATCH",
"url": "=https://api.youcanbook.me/v1/intents/{{ $('CreateIntent').item.json.id }}/confirm",
"authentication": "genericCredentialType",
"genericAuthType": "httpBasicAuth",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "{}",
"options": {}
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
2624,
-96
],
"id": "5742de86-ab64-4842-8014-278f7a0e6782",
"name": "patchConfirm",
"credentials": {
"httpBasicAuth": {
"id": "your-ycbm-cred",
"name": "YCBM"
}
}
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict",
"version": 2
},
"conditions": [
{
"id": "72b36a1e-4d07-47d4-b0a9-7d63a736894d",
"leftValue": "={{ $json.form[0].value }}",
"rightValue": "",
"operator": {
"type": "string",
"operation": "notEmpty",
"singleValue": true
}
}
],
"combinator": "and"
},
"options": {}
},
"type": "n8n-nodes-base.if",
"typeVersion": 2.2,
"position": [
2112,
-96
],
"id": "12037677-cda5-4ac5-a977-08050c57c0b5",
"name": "emailCheck"
},
{
"parameters": {
"jsCode": "// Function node: pide al cliente su email para confirmar la cita\nreturn [\n {\n json: {\n message: \"INSTRUCCIONES AL AGENTE: Solicita el email al usuario para poder confirmar la cita.\"\n }\n }\n];\n"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
2640,
192
],
"id": "9a80f0f0-816b-4697-8da0-3072ca982bb9",
"name": "pedirEmail"
},
{
"parameters": {
"jsCode": "// Function node: pide al cliente su email para confirmar la cita\nreturn [\n {\n json: {\n message: \"INSTRUCCIONES AL AGENTE: La cita está confirmada y le llegará un whatsapp y correo con la confirmación, informa al usuario\"\n }\n }\n];\n"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
2880,
-96
],
"id": "8d969658-6d42-4553-a4ec-35519f32d5da",
"name": "confirmarCita"
},
{
"parameters": {
"jsCode": "// 0) Capturar la petición original (ajusta el nombre del nodo y campo si fuese necesario)\nconst peticionInicial = $('Webhook').first().json.body.preferencia || \"\";\n\n// 1) Aplanar todos los slots entrantes en un solo array\nlet flatSlots = [];\n$input.all().forEach(item => {\n const j = item.json;\n if (Array.isArray(j.slots)) {\n flatSlots = flatSlots.concat(j.slots);\n } else if (j.date && j.start) {\n flatSlots.push({ date: j.date, start: j.start });\n }\n});\n\n// 2) Agrupar los slots por fecha\nconst agrupadoPorFecha = flatSlots.reduce((acum, { date, start }) => {\n if (!acum[date]) acum[date] = [];\n acum[date].push(start);\n return acum;\n}, {});\n\n// 3) Construir el array de disponibilidad con nombres de campo en español\nconst disponibilidad = Object.entries(agrupadoPorFecha).map(([fecha, horas]) => ({\n fecha,\n horas\n}));\n\n// 4) Generar el mensaje con instrucciones para el agente IA\nlet mensaje = \"\";\nif (peticionInicial && disponibilidad.length > 0) {\n mensaje = \n \"INSTRUCCIONES AL AGENTE:\\n\" +\n \"– Existe una petición inicial (“peticionInicial” no está vacía) y hay disponibilidad.\\n\" +\n \"– Debes solicitar al usuario que elija entre las franjas disponibles listadas en “disponibilidad”.\";\n} else if (peticionInicial && disponibilidad.length === 0) {\n mensaje = \n \"INSTRUCCIONES AL AGENTE:\\n\" +\n \"– Existe una petición inicial pero no hay disponibilidad en esa fecha.\\n\" +\n \"– Debes informar al usuario que no falta disponibilidad en la fecha solicitada y ofrecerle otras fechas distintas que aparecen en “disponibilidad” (que estará vacío).\";\n} else if (!peticionInicial && disponibilidad.length > 0) {\n mensaje = \n \"INSTRUCCIONES AL AGENTE:\\n\" +\n \"– El usuario no indicó preferencia horaria.\\n\" +\n \"– Debes mostrar las próximas franjas disponibles que se encuentran en \" + disponibilidad + \".\\n\" +\n \"– Pregunta amablemente al usuario qué día y hora le viene mejor de las opciones disponibles.\";\n} else { // !peticionInicial && disponibilidad.length === 0\n mensaje = \n \"INSTRUCCIONES AL AGENTE:\\n\" +\n \"– No hay petición inicial y tampoco hay disponibilidad.\\n\" +\n \"– Debes informar al usuario de que no hay huecos libres en este momento y sugerirle que intente más adelante.\";\n}\n\n// 5) Devolver un único objeto JSON con claves descriptivas\nreturn [{\n json: {\n peticionInicial,\n disponibilidad,\n mensaje\n }\n}];\n"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
2320,
320
],
"id": "0c109b63-5802-4f44-994c-22962de53945",
"name": "escogerHora"
}
],
"pinData": {},
"connections": {
"Webhook": {
"main": [
[
{
"node": "ParseURL",
"type": "main",
"index": 0
}
]
]
},
"OpenRouter Chat Model": {
"ai_languageModel": [
[
{
"node": "AnalizarDisponibilidad",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Simple Memory": {
"ai_memory": [
[
{
"node": "AnalizarDisponibilidad",
"type": "ai_memory",
"index": 0
}
]
]
},
"Structured Output Parser": {
"ai_outputParser": [
[
{
"node": "AnalizarDisponibilidad",
"type": "ai_outputParser",
"index": 0
}
]
]
},
"ParseURL": {
"main": [
[
{
"node": "AnalizarDisponibilidad",
"type": "main",
"index": 0
}
]
]
},
"CreateIntent": {
"main": [
[
{
"node": "availabilityKey",
"type": "main",
"index": 0
}
]
]
},
"availabilityKey": {
"main": [
[
{
"node": "GetAvailabilities",
"type": "main",
"index": 0
}
]
]
},
"GetAvailabilities": {
"main": [
[
{
"node": "FilterSlots",
"type": "main",
"index": 0
}
]
]
},
"FilterSlots": {
"main": [
[
{
"node": "If",
"type": "main",
"index": 0
}
]
]
},
"If": {
"main": [
[
{
"node": "preparePatchBody",
"type": "main",
"index": 0
}
],
[
{
"node": "escogerHora",
"type": "main",
"index": 0
}
]
]
},
"AnalizarDisponibilidad": {
"main": [
[
{
"node": "CreateIntent",
"type": "main",
"index": 0
}
]
]
},
"preparePatchBody": {
"main": [
[
{
"node": "emailCheck",
"type": "main",
"index": 0
}
]
]
},
"patchSelections": {
"main": [
[
{
"node": "patchConfirm",
"type": "main",
"index": 0
}
]
]
},
"emailCheck": {
"main": [
[
{
"node": "patchSelections",
"type": "main",
"index": 0
}
],
[
{
"node": "pedirEmail",
"type": "main",
"index": 0
}
]
]
},
"patchConfirm": {
"main": [
[
{
"node": "confirmarCita",
"type": "main",
"index": 0
}
]
]
},
"confirmarCita": {
"main": [
[]
]
},
"pedirEmail": {
"main": [
[]
]
},
"escogerHora": {
"main": [
[]
]
}
},
"active": true,
"settings": {
"executionOrder": "v1"
},
"versionId": "00000000-0000-0000-0000-000000000000",
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "your-n8n-instance-id"
},
"id": "WORKFLOW_ID",
"tags": []
}