Soporte de chat para la autenticación de clientes con OpenAI y gestión de sesiones de Redis
Este es unSupport, AIflujo de automatización del dominio deautomatización que contiene 19 nodos.Utiliza principalmente nodos como Set, Form, Redis, Switch, FormTrigger, combinando tecnología de inteligencia artificial para lograr automatización inteligente. Soporte de chat para autenticación de clientes usando OpenAI y gestión de sesiones de Redis
- •Información de conexión del servidor Redis
- •Clave de API de OpenAI
Nodos utilizados (19)
Categoría
{
"meta": {
"instanceId": "408f9fb9940c3cb18ffdef0e0150fe342d6e655c3a9fac21f0f644e8bedabcd9",
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "0c0090f9-c3a6-421d-8c67-92baeded6007",
"name": "Al recibir mensaje de chat",
"type": "@n8n/n8n-nodes-langchain.chatTrigger",
"position": [
-580,
-160
],
"webhookId": "0fa189dc-16dc-470f-b69d-3e2809d8c071",
"parameters": {
"options": {}
},
"typeVersion": 1.1
},
{
"id": "adf71970-7f0c-4394-bdab-b701eaa7173f",
"name": "LLM",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
-240,
40
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4.1-mini",
"cachedResultName": "gpt-4.1-mini"
},
"options": {}
},
"credentials": {
"openAiApi": {
"id": "8gccIjcuf3gvaoEr",
"name": "OpenAi account"
}
},
"typeVersion": 1.2
},
{
"id": "56318a6e-3a05-4f6b-9eb5-15ad6144144e",
"name": "Memoria",
"type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
"position": [
-120,
40
],
"parameters": {
"sessionKey": "=chat_{{ $('When chat message received').first().json.sessionId }}",
"sessionIdType": "customKey"
},
"typeVersion": 1.3
},
{
"id": "6bde1175-7175-4ccd-ac0b-65ecc8c2d7b3",
"name": "Get Session",
"type": "n8n-nodes-base.redis",
"position": [
-400,
-160
],
"parameters": {
"key": "=chat_{{ $json.sessionId }}",
"keyType": "string",
"options": {},
"operation": "get",
"propertyName": "data"
},
"credentials": {
"redis": {
"id": "zU4DA70qSDrZM1El",
"name": "Redis account (localhost)"
}
},
"typeVersion": 1
},
{
"id": "81f53ae3-22b6-48cd-83b9-3c6c1041818c",
"name": "When Executed by Another Workflow",
"type": "n8n-nodes-base.executeWorkflowTrigger",
"position": [
340,
-120
],
"parameters": {
"workflowInputs": {
"values": [
{
"name": "eventType"
},
{
"name": "data",
"type": "object"
}
]
}
},
"typeVersion": 1.1
},
{
"id": "ade09ef9-b2bc-4cf0-84b5-7121623b4f7b",
"name": "Interruptor",
"type": "n8n-nodes-base.switch",
"position": [
540,
-120
],
"parameters": {
"rules": {
"values": [
{
"outputKey": "Get Auth Url",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "55d3d729-baf4-47ad-8262-5d23fc2d3348",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.eventType }}",
"rightValue": "get_auth_url"
}
]
},
"renameOutput": true
}
]
},
"options": {}
},
"typeVersion": 3.2
},
{
"id": "7ee9de6a-bb37-4adc-87a2-ddb745d17ab7",
"name": "Get Auth Url Response",
"type": "n8n-nodes-base.set",
"position": [
740,
-120
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "cf2b4fb3-cda0-47f9-b9fa-fda3532a04f5",
"name": "auth_url",
"type": "string",
"value": "=https://<your-n8n-url>/form/auth?sessionId={{ $json.data.sessionId }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "880f7506-0947-47f1-ba0d-d08d6d18133b",
"name": "Get Auth URL",
"type": "@n8n/n8n-nodes-langchain.toolWorkflow",
"position": [
40,
40
],
"parameters": {
"workflowId": {
"__rl": true,
"mode": "id",
"value": "={{ $workflow.id }}"
},
"description": "Call this tool to generate a login URL which allows guest users to authenticate as customers.",
"workflowInputs": {
"value": {
"data": "={{\n{\n \"sessionId\": $('When chat message received').first().json.sessionId\n}\n}}",
"eventType": "get_auth_url"
},
"schema": [
{
"id": "eventType",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "eventType",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "data",
"type": "object",
"display": true,
"removed": false,
"required": false,
"displayName": "data",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [],
"attemptToConvertTypes": false,
"convertFieldsToString": false
}
},
"typeVersion": 2.2
},
{
"id": "800be1b0-5bec-4eaf-ac13-e6808b955408",
"name": "Update Session",
"type": "n8n-nodes-base.redis",
"position": [
1620,
-120
],
"parameters": {
"key": "=chat_{{ $('Login Form').first().json.formQueryParameters.sessionId }}",
"ttl": 3600,
"value": "={{ $json.toJsonString() }}",
"expire": true,
"keyType": "string",
"operation": "set"
},
"credentials": {
"redis": {
"id": "zU4DA70qSDrZM1El",
"name": "Redis account (localhost)"
}
},
"typeVersion": 1
},
{
"id": "8b3d4728-2ae2-40dd-98ee-9efb915d06fc",
"name": "Confirm Login Success",
"type": "n8n-nodes-base.form",
"position": [
1800,
-120
],
"webhookId": "d939dc43-e333-4cb6-8bde-d6d8868ec9d3",
"parameters": {
"options": {},
"operation": "completion",
"completionTitle": "Login Successful!",
"completionMessage": "=Welcome back {{ $json.name }},\nYour chat session is now authenticated.\n\nYou may now close this window and chat as a customer."
},
"typeVersion": 1
},
{
"id": "5cb5797a-7f6c-4855-bcaa-4475ef16ec8d",
"name": "Customer Support Agente",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
-200,
-160
],
"parameters": {
"text": "={{ $('When chat message received').item.json.chatInput }}",
"options": {
"systemMessage": "=You are a customer support assistant interacting with both anonymous guests and existing customers.\n* Guest users can ask basic questions about publicly available information.\n* Existing Customers can access their accounts, basket and profile.\n* Guests who ask about their accounts, basket or profile must authenticate as a customer before they can access this information. Provide a login url for the user and ask them to return once authenticated. Remind the user not to close the chat window as this will end the session!\n\n### About the login URL \nThe login url will take the user to an external form which when authenticated, will link their chat session with their customer profile. The user should close the form once done and return to the chat window. Upon their next message, their customer profile will be included in the context.\n* If you haven't already, thank the user for authenticating and welcome them back!\n* If the user claims to have authenticated but is still identified as a guest, then it may be that the login attempt was not successful and the user should be advised politely to try again.\n\n---\nThe current user is {{ $json.data ? 'a customer' : 'a guest' }}.\n{{ $json.data ?? '' }}",
"passthroughBinaryImages": true
},
"promptType": "define"
},
"typeVersion": 1.9
},
{
"id": "1b1f96f6-6f70-4b86-9831-0ac31a65dbdc",
"name": "Nota adhesiva",
"type": "n8n-nodes-base.stickyNote",
"position": [
-640,
-380
],
"parameters": {
"color": 7,
"width": 840,
"height": 560,
"content": "## 1. Create a Conversational Agent with Session Access\n[Learn more about AI Agents](https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.agent)\n\nOur support agent handles both guests and customers, with the latter identified by available session data coming in from Redis. For guests who wish to authenticate as customers, the agent is instructed to generate a login URL to share with the user - this is accomplished using a tool."
},
"typeVersion": 1
},
{
"id": "b41e156c-a70f-422a-a37a-432e5657a999",
"name": "Nota adhesiva1",
"type": "n8n-nodes-base.stickyNote",
"position": [
240,
-380
],
"parameters": {
"color": 7,
"width": 720,
"height": 560,
"content": "## 2. Generate a Login URL via Tool\n[Learn more about Subworkflow Triggers](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.executeworkflowtrigger)\n\nThe login URL is a simple redirect to an form which handles the authentication. For obvious reasons, we've deliberately avoided doing this through the chat as it could have exposed sensitive credentials. The login URL appends the SessionID as a query parameter because this is currently the only way to pre-fill fields in a n8n form."
},
"typeVersion": 1
},
{
"id": "bd10ad35-7c72-480f-86fd-e15ee4011688",
"name": "Nota adhesiva2",
"type": "n8n-nodes-base.stickyNote",
"position": [
1000,
-380
],
"parameters": {
"color": 7,
"width": 1020,
"height": 560,
"content": "## 3. A Login Form to Link Session to Customer Profile\n[Learn more about the Form Trigger](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.formtrigger)\n\nThis login form is pretty standard and takes 3 fields: username, password and sessionId. the idea being that once authenticated successfully, the user's customer profile can be used to associate with the sessionID. Note that I haven't implemented the actual authentication logic - you'll need to do this yourself!"
},
"typeVersion": 1
},
{
"id": "f13700b3-69cb-4809-b982-9204c2766948",
"name": "Get Customer Profile",
"type": "n8n-nodes-base.set",
"position": [
1440,
-120
],
"parameters": {
"mode": "raw",
"options": {},
"jsonOutput": "{\n \"id\": 1,\n \"name\": \"Jim Le\",\n \"email\": \"jim@example.com\",\n \"basket\": [\n \"SanDisk Extreme Portable SSD 1TB (up to 1050 MB/s read, 1,000MB/s write, NVMe SSD, USB-C, External Solid State Drive, IP65 rated for dust and water resistance, Updated Firmware) Black - £84.99\",\n \"eufy X10 Pro Omni Robot Vacuum Cleaner with Mop, All-in-One Station, 8,000Pa Powerful Suction, Dual Mops, AI Obstacle Avoidance, Auto Mop Washing, Auto-Hot-Air-Drying, Auto-Emptying, Auto-Refilling £799.00\"\n ] \n}"
},
"typeVersion": 3.4
},
{
"id": "66c28c7e-7ff1-4aac-8fbf-35e8c8105a65",
"name": "Replace Me!",
"type": "n8n-nodes-base.noOp",
"position": [
1260,
-120
],
"parameters": {},
"typeVersion": 1
},
{
"id": "e58f3c0f-c441-4c89-9a19-2c3459733dee",
"name": "Login Form",
"type": "n8n-nodes-base.formTrigger",
"position": [
1080,
-120
],
"webhookId": "cac0738d-f211-41de-bc6e-6f36103d9c1a",
"parameters": {
"options": {
"path": "auth",
"ignoreBots": true,
"buttonLabel": "Submit"
},
"formTitle": "Authenticate Chat Session",
"formFields": {
"values": [
{
"fieldLabel": "Username",
"requiredField": true
},
{
"fieldLabel": "Password",
"requiredField": true
},
{
"fieldName": "sessionId",
"fieldType": "hiddenField"
}
]
},
"responseMode": "lastNode",
"formDescription": "Please login to validate your current chat session."
},
"typeVersion": 2.2
},
{
"id": "2f965c47-76e3-4100-8c48-2be4dccece49",
"name": "Nota adhesiva3",
"type": "n8n-nodes-base.stickyNote",
"position": [
1220,
60
],
"parameters": {
"color": 5,
"width": 200,
"height": 140,
"content": "### Replace with Authentication Logic!\nThis could be a query to a PostgreSQL database or otherwise."
},
"typeVersion": 1
},
{
"id": "1d5077eb-4a6b-4bcb-9a85-e525a6c013ab",
"name": "Nota adhesiva4",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1160,
-820
],
"parameters": {
"width": 460,
"height": 1160,
"content": "## Try It Out!\n### This n8n template demonstrates one approach to customer authentication via chat agents.\n\nUnlike approaches where you have to authenticate users prior to interacting with the agent, this approach allows guest users to authenticate at any time during the session or not at all.\n\n### How it works\n* A conversational agent is used for this demonstration. The key component is the Redis node just after the chat trigger which acts as the session context.\n* For guests, the session item is blank. for customers, the session item is populated with their customer profile.\n* The agent is instructed to generate a unique login URL only for guests when appropriate or upon request.\n* This login URL redirects the guest user to a simple n8n form also hosted in this template. The login URL has the current sessionID as a query parameter as the way to pass this data to the form.\n* Once login is successful, the matching session item by sessionId is populated with the customer profile. The user can now return to the chat window.\n* Back to the agent, now when the user sends their next message, the Redis node will pick up the session item and the customer profile associated with it. The system prompt is updated with this data which let's the agent know the user is now a customer.\n\n### How to use\n* You'll need to update the \"auth URL\" tool to match the URL of your n8n instance. Better yet, copy the production URL of your form from the trigger.\n* Activate the workflow to turn on production mode which is required for this workflow.\n* Implement the authentication logic in step 3. This could be sending the user and pass to a postgreSQL data for validation.\n\n### Requirements\n* OpenAI for LLM (feel free to swap to any provider)\n* Redis for Cache/Sessions (again, feel free to swap this out for postgresql or other database)\n\n### Customising this workflow\n* Consider not populating the session item with the user data as it can become stale. Instead, just add the userId and instruct the agent to query using tools.\n\n### Need Help?\nJoin the [Discord](https://discord.com/invite/XPKeKXeB7d) or ask in the [Forum](https://community.n8n.io/)!\n\nHappy Hacking!"
},
"typeVersion": 1
}
],
"pinData": {},
"connections": {
"adf71970-7f0c-4394-bdab-b701eaa7173f": {
"ai_languageModel": [
[
{
"node": "Customer Support Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Memory": {
"ai_memory": [
[
{
"node": "Customer Support Agent",
"type": "ai_memory",
"index": 0
}
]
]
},
"Switch": {
"main": [
[
{
"node": "7ee9de6a-bb37-4adc-87a2-ddb745d17ab7",
"type": "main",
"index": 0
}
]
]
},
"e58f3c0f-c441-4c89-9a19-2c3459733dee": {
"main": [
[
{
"node": "66c28c7e-7ff1-4aac-8fbf-35e8c8105a65",
"type": "main",
"index": 0
}
]
]
},
"6bde1175-7175-4ccd-ac0b-65ecc8c2d7b3": {
"main": [
[
{
"node": "Customer Support Agent",
"type": "main",
"index": 0
}
]
]
},
"66c28c7e-7ff1-4aac-8fbf-35e8c8105a65": {
"main": [
[
{
"node": "f13700b3-69cb-4809-b982-9204c2766948",
"type": "main",
"index": 0
}
]
]
},
"880f7506-0947-47f1-ba0d-d08d6d18133b": {
"ai_tool": [
[
{
"node": "Customer Support Agent",
"type": "ai_tool",
"index": 0
}
]
]
},
"800be1b0-5bec-4eaf-ac13-e6808b955408": {
"main": [
[
{
"node": "8b3d4728-2ae2-40dd-98ee-9efb915d06fc",
"type": "main",
"index": 0
}
]
]
},
"f13700b3-69cb-4809-b982-9204c2766948": {
"main": [
[
{
"node": "800be1b0-5bec-4eaf-ac13-e6808b955408",
"type": "main",
"index": 0
}
]
]
},
"When chat message received": {
"main": [
[
{
"node": "6bde1175-7175-4ccd-ac0b-65ecc8c2d7b3",
"type": "main",
"index": 0
}
]
]
},
"81f53ae3-22b6-48cd-83b9-3c6c1041818c": {
"main": [
[
{
"node": "Switch",
"type": "main",
"index": 0
}
]
]
}
}
}¿Cómo usar este flujo de trabajo?
Copie el código de configuración JSON de arriba, cree un nuevo flujo de trabajo en su instancia de n8n y seleccione "Importar desde JSON", pegue la configuración y luego modifique la configuración de credenciales según sea necesario.
¿En qué escenarios es adecuado este flujo de trabajo?
Avanzado - Soporte, Inteligencia Artificial
¿Es de pago?
Este flujo de trabajo es completamente gratuito, puede importarlo y usarlo directamente. Sin embargo, tenga en cuenta que los servicios de terceros utilizados en el flujo de trabajo (como la API de OpenAI) pueden requerir un pago por su cuenta.
Flujos de trabajo relacionados recomendados
Jimleuk
@jimleukFreelance consultant based in the UK specialising in AI-powered automations. I work with select clients tackling their most challenging projects. For business enquiries, send me an email at hello@jimle.uk LinkedIn: https://www.linkedin.com/in/jimleuk/ X/Twitter: https://x.com/jimle_uk
Compartir este flujo de trabajo