🤖 Slackbot avanzado (n8n)

Avanzado

Este es unEngineering, Building Blocks, IT Opsflujo de automatización del dominio deautomatización que contiene 34 nodos.Utiliza principalmente nodos como If, Set, Code, Merge, Slack. 🤖 Slackbot avanzado (n8n)

Requisitos previos
  • Bot Token de Slack o URL de Webhook
  • Punto final de HTTP Webhook (n8n generará automáticamente)
  • Información de conexión de la base de datos PostgreSQL
  • Pueden requerirse credenciales de autenticación para la API de destino
Vista previa del flujo de trabajo
Visualización de las conexiones entre nodos, con soporte para zoom y panorámica
Exportar flujo de trabajo
Copie la siguiente configuración JSON en n8n para importar y usar este flujo de trabajo
{
  "nodes": [
    {
      "id": "8e0a3745-348b-42db-82cc-55676c897ad7",
      "name": "Iniciar hilo",
      "type": "n8n-nodes-base.slack",
      "position": [
        1260,
        180
      ],
      "parameters": {
        "text": "=🧵 Got request to `{{ $json.command }}` from @{{$json.user}}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "name",
          "value": "={{ $json.alerts_channel }}"
        },
        "otherOptions": {
          "link_names": true
        }
      },
      "credentials": {
        "slackApi": {
          "id": "26",
          "name": "Cloudbot bot token"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "ee413d6c-dad3-4e57-b08d-ffd0f84c682e",
      "name": "Enviar ayuda",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        880,
        560
      ],
      "parameters": {
        "url": "={{ $json.response_url }}",
        "options": {},
        "requestMethod": "POST",
        "jsonParameters": true,
        "responseFormat": "string",
        "bodyParametersJson": "={\n\"attachments\": [\n{\n\"text\": \"ℹ️ <{{ $json.help_docs_url }}|You can find help page here>\"\n}\n]\n}"
      },
      "typeVersion": 1
    },
    {
      "id": "47c146f9-1223-46a7-bfd6-0fa6ff701efe",
      "name": "Validar token Slack",
      "type": "n8n-nodes-base.if",
      "position": [
        320,
        280
      ],
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.slack_token }}",
              "value2": "={{ $json.request_token }}"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "7733505c-d02c-4cb2-be78-f2272e5b7d6e",
      "name": "Nota adhesiva 3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -440,
        -140
      ],
      "parameters": {
        "color": 5,
        "width": 549.1826144791862,
        "height": 326.46772464213774,
        "content": "## 👨‍🎤 Setup\n1. Add Slack command and point it up to the webhook\n2. Add the following to the **Set config** node\n- `alerts_channel` with alerts channel to start threads on\n- `instance_url` with this instance url to make it easy to debug\n- `slack_token` with slack bot token to validate request\n- `slack_secret_signature` with slack secret signature to validate request\n- `help_docs_url` with help url to help users understand the commands \n3. Build other workflows to call and add them to `commands` in **Set Config**. Each command must be mapped to a workflow id with an `Execute Workflow Trigger` node\n4. Activate workflow 🚀"
      },
      "typeVersion": 1
    },
    {
      "id": "30355072-5d75-4deb-af67-909ba59e6eb3",
      "name": "Responder al usuario que el comando fue recibido",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueRegularOutput",
      "position": [
        500,
        40
      ],
      "parameters": {
        "url": "={{ $json.response_url }}",
        "options": {},
        "requestMethod": "POST",
        "jsonParameters": true,
        "responseFormat": "string",
        "bodyParametersJson": "={\n\"attachments\": [\n{\n\"text\": \"ℹ️ Got command `{{ $json.command_name }} {{ $json.command_text }}`\"\n}\n]\n}"
      },
      "typeVersion": 1
    },
    {
      "id": "a2217c45-700e-4923-96e4-455a733bc1e4",
      "name": "si tiene flujo de trabajo",
      "type": "n8n-nodes-base.if",
      "position": [
        740,
        280
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "d0a35e4f-3141-4e94-bb1a-fe7747a58dfc",
              "operator": {
                "type": "object",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.workflow }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "7ff12aa4-680f-42af-aa2f-c9dd6a733976",
      "name": "Configurar parámetros",
      "type": "n8n-nodes-base.set",
      "position": [
        -100,
        280
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "ba8fd958-188a-4e27-bdf1-928de8ae7d4f",
              "name": "commands",
              "type": "object",
              "value": "={{\n{\n  \"info\": { workflowId: 142, startThread: false },\n  \"delete-user\": { workflowId: \"pTh9HMZVYcQNXypJ\" }\n}\n}}"
            },
            {
              "id": "105d2881-72b7-4547-a076-83ddb0966256",
              "name": "alerts_channel",
              "type": "string",
              "value": "#adore_bot_test"
            },
            {
              "id": "9672bea2-3a6a-4162-9966-107bf2ddbee5",
              "name": "instance_url",
              "type": "string",
              "value": "https://x.app.n8n.cloud/"
            },
            {
              "id": "52b53b37-5f69-4fb8-9569-f62788d91af1",
              "name": "slack_token",
              "type": "string",
              "value": "FILL_TOKEN_HERE"
            },
            {
              "id": "4d8d06f2-f1a5-4eb2-a559-42d98ceddffb",
              "name": "slack_secret_signature",
              "type": "string",
              "value": "FILL_SECRET_HERE"
            },
            {
              "id": "c2c7de20-a264-495e-934e-dda1a0bc64b9",
              "name": "help_docs_url",
              "type": "string",
              "value": "ADD_LINK_HERE"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.3
    },
    {
      "id": "4c730be9-d3f5-45ee-8f2b-b6bfd685ea78",
      "name": "Enviar URL de depuración",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueRegularOutput",
      "position": [
        1260,
        440
      ],
      "parameters": {
        "url": "={{ $json.response_url }}",
        "options": {},
        "requestMethod": "POST",
        "jsonParameters": true,
        "responseFormat": "string",
        "bodyParametersJson": "={\n\"attachments\": [\n{\n\"text\": \"<{{ $json.instance_url }}/workflow/{{ $workflow.id }}/executions/{{ $execution.id }}|To debug entry point execution>\"\n}\n]\n}"
      },
      "retryOnFail": false,
      "typeVersion": 2
    },
    {
      "id": "f4ccc237-d703-4963-8112-cc38ae9d6b2a",
      "name": "si crear hilo",
      "type": "n8n-nodes-base.if",
      "position": [
        980,
        280
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "7eadbf0d-f8ec-45cf-abf3-aafb8d7e16b4",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.workflow.startThread }}",
              "rightValue": ""
            },
            {
              "id": "2f28e7dd-6473-4f85-a449-674e00b29b4d",
              "operator": {
                "type": "boolean",
                "operation": "notExists",
                "singleValue": true
              },
              "leftValue": "={{ $json.workflow.startThread }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "ed9f2ed8-5266-42a3-9d47-621050e5bf97",
      "name": "Alertar al usuario que se creó el hilo",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueRegularOutput",
      "position": [
        1260,
        0
      ],
      "parameters": {
        "url": "={{ $json.response_url }}",
        "options": {},
        "requestMethod": "POST",
        "jsonParameters": true,
        "responseFormat": "string",
        "bodyParametersJson": "={\n\"attachments\": [\n{\n\"text\": \"🧵 Thread created on {{ $json.alerts_channel }}\"\n}\n]\n}"
      },
      "retryOnFail": false,
      "typeVersion": 2
    },
    {
      "id": "9904180a-e937-43fd-9b04-627e860d693a",
      "name": "Agregar información de depuración",
      "type": "n8n-nodes-base.slack",
      "position": [
        1540,
        60
      ],
      "parameters": {
        "text": "=<{{ $vars.instance_url }}/workflow/{{ $workflow.id }}/executions/{{ $execution.id }}|To debug entry point execution>",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.channel }}"
        },
        "otherOptions": {
          "thread_ts": {
            "replyValues": {
              "thread_ts": "={{ $json.message.ts }}"
            }
          }
        }
      },
      "credentials": {
        "slackApi": {
          "id": "26",
          "name": "Cloudbot bot token"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "6b385f75-4ebf-46c8-a799-babdb6231f4e",
      "name": "Ejecutar flujo de trabajo objetivo",
      "type": "n8n-nodes-base.executeWorkflow",
      "position": [
        1940,
        500
      ],
      "parameters": {
        "options": {},
        "workflowId": "={{ $json.commands.info.workflowId }}"
      },
      "typeVersion": 1
    },
    {
      "id": "5fde8d57-6ef3-4b01-9422-16fd2f176c5d",
      "name": "Agregar información del hilo",
      "type": "n8n-nodes-base.merge",
      "position": [
        1760,
        320
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combinationMode": "multiplex"
      },
      "typeVersion": 2
    },
    {
      "id": "c4892e34-53af-4d95-a3b6-ca16fdef1aa7",
      "name": "Manejar otros comandos",
      "type": "n8n-nodes-base.switch",
      "position": [
        640,
        620
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "help",
              "conditions": {
                "options": {
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.command }}",
                    "rightValue": "help"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "7dabe06a-8d87-4e68-b8d9-53bf7f29a9ab",
      "name": "Información de hilo desconocida",
      "type": "n8n-nodes-base.set",
      "position": [
        1540,
        240
      ],
      "parameters": {
        "values": {
          "string": [
            {
              "name": "channel_id",
              "value": "={{ $json.channel }}"
            },
            {
              "name": "thread_ts",
              "value": "={{ $json.message.ts }}"
            }
          ]
        },
        "options": {},
        "keepOnlySet": true
      },
      "typeVersion": 1
    },
    {
      "id": "e56875c4-ce2b-4639-aabc-21f1562a3858",
      "name": "Establecer variables",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        880,
        740
      ],
      "parameters": {
        "url": "={{ $json.response_url }}",
        "options": {},
        "requestMethod": "POST",
        "jsonParameters": true,
        "responseFormat": "string",
        "bodyParametersJson": "={\n\"attachments\": [\n{\n\"text\": \"🤷🏽‍♂️ Sorry, unknown command `{{ $json.command }}`\"\n}\n]\n}"
      },
      "typeVersion": 1
    },
    {
      "id": "3fab88ce-4a80-483b-b558-12e111f16c98",
      "name": "__PROTECTED_34__ para llamar al comando __PROTECTED_63__",
      "type": "n8n-nodes-base.set",
      "position": [
        -280,
        280
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "8fa0d712-1076-49b7-82da-e98390182ac6",
              "name": "command_text",
              "type": "string",
              "value": "={{ $json.body.text }}"
            },
            {
              "id": "ef82aa1f-2882-4970-b10a-86e7faef6562",
              "name": "user",
              "type": "string",
              "value": "={{ $json.body.user_name }}"
            },
            {
              "id": "633fe37e-850c-4e95-8728-f19ceb4afe76",
              "name": "response_url",
              "type": "string",
              "value": "={{ $json.body.response_url }}"
            },
            {
              "id": "bbab2bb9-3e90-41c4-b5be-8c7873c61707",
              "name": "request_token",
              "type": "string",
              "value": "={{ $json.body.token }}"
            },
            {
              "id": "3e6dd0e2-fec4-48cb-a44c-1342a8eb619c",
              "name": "command_name",
              "type": "string",
              "value": "={{ $json.body.command }}"
            }
          ]
        }
      },
      "typeVersion": 3.3
    },
    {
      "id": "99cab485-4099-4505-9c9e-33ea389818e5",
      "name": "Responder al usuario directamente",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -480,
        280
      ],
      "webhookId": "a14585bb-b757-410e-a5b2-5f05a087b388",
      "parameters": {
        "path": "a14585bb-b757-410e-a5b2-5f05a087b388",
        "options": {
          "rawBody": true,
          "responseData": "Wait for it...",
          "binaryPropertyName": "data"
        },
        "httpMethod": "POST"
      },
      "typeVersion": 1.1
    },
    {
      "id": "09dc7ecf-a577-427e-a193-ed29d260c5fe",
      "name": "Nota adhesiva",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1460,
        900
      ],
      "parameters": {
        "url": "={{ $json.response_url }}",
        "options": {},
        "requestMethod": "POST",
        "jsonParameters": true,
        "responseFormat": "string",
        "bodyParametersJson": "={\n\"attachments\": [\n{\n\"text\": \"<{{ $json.instance_url }}workflow/{{ $workflow.id }}/executions/{{ $execution.id }}|To debug subworkflow execution>\"\n}\n]\n}"
      },
      "typeVersion": 2,
      "continueOnFail": true
    },
    {
      "id": "a38b3343-8e8e-4d6c-95ef-66efafdfa913",
      "name": "Activador de comando de flujo de trabajo",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1160,
        660
      ],
      "parameters": {
        "width": 1255.4495374151727,
        "height": 655.2393233866135,
        "content": "## Example subworkflow for command WITHOUT Slack thread..\n\n### Build this in a separate workflow\n### and add the id to `commands` in **Set Config**"
      },
      "typeVersion": 1
    },
    {
      "id": "87f764b3-135c-4dc3-8633-b58e2c3a4e2d",
      "name": "si tiene indicador",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "disabled": true,
      "position": [
        1220,
        1020
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "3a52d7e3-ef56-47db-844a-1efb6c20ad35",
      "name": "Si coincide con variable de entorno",
      "type": "n8n-nodes-base.if",
      "position": [
        1400,
        1120
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "d8478e87-6e7c-40ea-a28d-099a3896001b",
              "operator": {
                "type": "array",
                "operation": "contains",
                "rightType": "any"
              },
              "leftValue": "={{ $json.flags }}",
              "rightValue": "--full-info"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "78718555-e266-4f58-ab9d-6e78f50afac2",
      "name": "Usuario encontrado",
      "type": "n8n-nodes-base.if",
      "position": [
        1620,
        1120
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "1ccb9f5d-0e7d-44f9-86e3-d5c0e15cb648",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.env.env }}",
              "rightValue": "prod"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "0ca15a51-2e56-4ef4-8be6-96f45ed17867",
      "name": "Formatear datos en estructura clara",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2220,
        1120
      ],
      "parameters": {
        "url": "={{ $('Command workflow trigger').item.json.response_url }}",
        "options": {},
        "requestMethod": "POST",
        "jsonParameters": true,
        "responseFormat": "string",
        "bodyParametersJson": "={{ $json.slack_message }}"
      },
      "typeVersion": 2,
      "continueOnFail": true
    },
    {
      "id": "ad83305f-9ca5-428f-a731-9afe3a82258a",
      "name": "REEMPLAZAR CON ACTIVADOR",
      "type": "n8n-nodes-base.code",
      "position": [
        2040,
        1120
      ],
      "parameters": {
        "jsCode": "const user = {\n  id: '1',\n  email: 'mutasem@n8n.io',\n  name: 'Mutasem Aldmour',\n  username: 'mutasem',\n  profile_url: 'https://n8n.io/creators/mutasem/',\n}\n\nconst fields = [\n    `*id:*\\n${user.id}`,\n    `*email:*\\n${user.email}`,\n    `*name:*\\n${user.name}`,\n    `*urls:*\\n<${user.profile_url}|creator profile>`\n];\n\n// remember no more than 10 fields per section\nconst output = {\n    \"blocks\":\n    [\n        {\n            \"type\": \"section\",\n            \"text\":\n            {\n                \"type\": \"mrkdwn\",\n                \"text\": `User: *${user.username}*`\n            }\n        },\n        {\n            \"type\": \"section\",\n            \"fields\": fields.map((text) => {\n                    return {\n                        \"type\": \"mrkdwn\",\n                        text,\n                    };\n                })\n        }\n    ]\n}\n\nreturn { slack_message: output };"
      },
      "typeVersion": 1
    },
    {
      "id": "6bdbd120-68ac-46ad-bd34-c43d7a447be4",
      "name": "Eliminar usuario aquí (ejemplo)",
      "type": "n8n-nodes-base.set",
      "position": [
        1240,
        1680
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3.3
    },
    {
      "id": "e2b0b88d-be4a-4b66-be15-3e8c6052d0f7",
      "name": "Obtener usuario aquí (ejemplo)",
      "type": "n8n-nodes-base.postgres",
      "disabled": true,
      "position": [
        1500,
        1800
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "=user"
        },
        "where": {
          "values": [
            {
              "value": "={{ $json.params[0] }}",
              "column": "username"
            }
          ]
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "options": {},
        "operation": "deleteTable",
        "deleteCommand": "delete"
      },
      "typeVersion": 2.3
    },
    {
      "id": "b0dc9a07-4957-4643-972b-49952d6fc001",
      "name": "Confirmar eliminación de usuario",
      "type": "n8n-nodes-base.postgres",
      "disabled": true,
      "position": [
        1840,
        1120
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "test"
        },
        "where": {
          "values": [
            {
              "value": "={{ $json.params[0] }}",
              "column": "username"
            }
          ]
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "options": {},
        "operation": "select"
      },
      "typeVersion": 2.3
    },
    {
      "id": "1f2eff56-a89b-4d6d-af8b-477c81c8bab3",
      "name": "Respondiendo en hilo",
      "type": "n8n-nodes-base.slack",
      "position": [
        1720,
        1800
      ],
      "parameters": {
        "text": "Deleted user  ✅",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Command workflow trigger').item.json.channel_id }}"
        },
        "otherOptions": {
          "thread_ts": {
            "replyValues": {
              "thread_ts": "={{ $('Command workflow trigger').item.json.thread_ts }}"
            }
          }
        }
      },
      "credentials": {
        "slackApi": {
          "id": "26",
          "name": "Cloudbot bot token"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "0c0d0487-a594-4e88-b777-21b4816115cd",
      "name": "Nota adhesiva 2",
      "type": "n8n-nodes-base.slack",
      "position": [
        1500,
        1580
      ],
      "parameters": {
        "text": "=<{{ $json.instance_url }}workflow/{{ $workflow.id }}/executions/{{ $execution.id }}|To debug subworkflow execution>",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.channel_id }}"
        },
        "otherOptions": {
          "thread_ts": {
            "replyValues": {
              "thread_ts": "={{ $json.thread_ts }}"
            }
          }
        }
      },
      "credentials": {
        "slackApi": {
          "id": "26",
          "name": "Cloudbot bot token"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "2c055ef4-4c0a-475d-b521-30002a45950b",
      "name": "Nota adhesiva 1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1160,
        1380
      ],
      "parameters": {
        "width": 961.7738517807816,
        "height": 589.0078772779973,
        "content": "## Example subworkflow for command WITH Slack thread..\n\n### Build this in a second separate workflow\n### and add the id to `commands` in **Set Config**\n\nUsed Edit Fields node here as trigger because you can only have one\nExecute Workflow Trigger per workflow"
      },
      "typeVersion": 1
    },
    {
      "id": "aec1b842-1219-4367-9238-3c7a118ce68f",
      "name": "analizar comando",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -80,
        460
      ],
      "parameters": {
        "color": 7,
        "width": 150,
        "height": 83.26656725254155,
        "content": "### 👆🏽 Set all custom config here "
      },
      "typeVersion": 1
    },
    {
      "id": "dd8f1a00-dfd4-4966-a76c-3c8e2a243bab",
      "name": "Validar firma __PROTECTED_34__",
      "type": "n8n-nodes-base.code",
      "position": [
        560,
        280
      ],
      "parameters": {
        "jsCode": "const text = $input.first().json.command_text;\nconst parts = text.split(' ');\n\n\n// GET COMMAND\n// for example /cloudbot info mutasem\n// should return \"info\"\nconst command = parts[0];\n\n\n// GET FLAGS \n// for example /cloudbot info mutasem --test --flag\n// should return ['--test', '--flag']\nconst flags = parts.filter((part) => part.startsWith('--'));\n\n\n// GET PARAMS\n// for example /cloudbot info mutasem test\n// should return [\"mutasem\", \"test\"]\nlet params = parts\n  .filter((part, i) => i > 0 && !part.startsWith('--'));\nparams = params.filter((param, i) => {\n  if (param === '-e') {\n    return false;\n  }\n  if (params[i - 1] === '-e') {\n    return false;\n  }\n\n  return true;\n});\n\n\n// GET ENV VARS\n// for example /cloudbot info mutasem -e env=prod\n// should return {env: \"prod\"}\nconst env = parts.filter((val, i) => {\n  return i > 0 && parts[i - 1] === '-e';\n})\n  .reduce((accu, opt) => {\n  if (!opt.includes('=')) {\n    return accu;\n  }\n\n  const key = opt.split('=')[0];\n  const val = opt.split('=')[1];\n  \n  accu[key] = clean(val);\n  return accu;\n}, {});\n\n// Add workflow to run\nconst commands = $input.first().json.commands;\nlet workflow;\nif (commands[command]) {\n  workflow = commands[command];\n}\n\nreturn {\n  ...$input.first().json,\n  command,\n  flags,\n  env,\n  params,\n  workflow,\n}\n\nfunction clean(str) {\n  return str.replaceAll(`‘`, '\\'').replaceAll('“', '\"').replaceAll('”', '\"').replaceAll('’', '\\'');\n}"
      },
      "typeVersion": 1
    },
    {
      "id": "22b8502c-dec3-4456-9947-639761517881",
      "name": "Validate webhook signature",
      "type": "n8n-nodes-base.code",
      "position": [
        100,
        280
      ],
      "parameters": {
        "jsCode": "const SIGNING_SECRET = $input.first().json.slack_secret_signature;\nconst item = $('Webhook to call for Slack command').first();\n\nif (!item.binary) {\n  throw new Error('Missing binary data');\n}\n\nconst crypto = require('crypto');\nconst { binary: { data } } = item;\n\nif (\n  !item.json.headers['x-slack-request-timestamp'] ||\n  Math.abs(\n    Math.floor(new Date().getTime() / 1000) -\n      +item.json.headers['x-slack-request-timestamp']\n  ) > 300\n) {\n  throw new Error('Unauthorized, request not fresh');\n}\n\nconst rawBody = Buffer.from(data.data, 'base64').toString()\n\n// compute the basestring\nconst baseStr = `v0:${item.json.headers['x-slack-request-timestamp']}:${rawBody}`;\n\n// extract the received signature from the request headers\nconst receivedSignature = item.json.headers['x-slack-signature'];\n\nconst expectedSignature = `v0=${crypto.createHmac('sha256', SIGNING_SECRET)\n.update(baseStr, 'utf8')\n.digest('hex')}`;\n\n// match the two signatures\nif (expectedSignature !== receivedSignature) {\nthrow new Error('Unauthorized, umatched signatures');\n}\n\nreturn $input.all();"
      },
      "typeVersion": 2
    }
  ],
  "pinData": {},
  "connections": {
    "3fab88ce-4a80-483b-b558-12e111f16c98": {
      "main": [
        [
          {
            "node": "7ff12aa4-680f-42af-aa2f-c9dd6a733976",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "7ff12aa4-680f-42af-aa2f-c9dd6a733976": {
      "main": [
        [
          {
            "node": "22b8502c-dec3-4456-9947-639761517881",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "3a52d7e3-ef56-47db-844a-1efb6c20ad35": {
      "main": [
        [
          {
            "node": "78718555-e266-4f58-ab9d-6e78f50afac2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "8e0a3745-348b-42db-82cc-55676c897ad7": {
      "main": [
        [
          {
            "node": "9904180a-e937-43fd-9b04-627e860d693a",
            "type": "main",
            "index": 0
          },
          {
            "node": "7dabe06a-8d87-4e68-b8d9-53bf7f29a9ab",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "dd8f1a00-dfd4-4966-a76c-3c8e2a243bab": {
      "main": [
        [
          {
            "node": "a2217c45-700e-4923-96e4-455a733bc1e4",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "5fde8d57-6ef3-4b01-9422-16fd2f176c5d": {
      "main": [
        [
          {
            "node": "6b385f75-4ebf-46c8-a799-babdb6231f4e",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "7dabe06a-8d87-4e68-b8d9-53bf7f29a9ab": {
      "main": [
        [
          {
            "node": "5fde8d57-6ef3-4b01-9422-16fd2f176c5d",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "a2217c45-700e-4923-96e4-455a733bc1e4": {
      "main": [
        [
          {
            "node": "f4ccc237-d703-4963-8112-cc38ae9d6b2a",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "c4892e34-53af-4d95-a3b6-ca16fdef1aa7",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "f4ccc237-d703-4963-8112-cc38ae9d6b2a": {
      "main": [
        [
          {
            "node": "8e0a3745-348b-42db-82cc-55676c897ad7",
            "type": "main",
            "index": 0
          },
          {
            "node": "ed9f2ed8-5266-42a3-9d47-621050e5bf97",
            "type": "main",
            "index": 0
          },
          {
            "node": "5fde8d57-6ef3-4b01-9422-16fd2f176c5d",
            "type": "main",
            "index": 1
          }
        ],
        [
          {
            "node": "4c730be9-d3f5-45ee-8f2b-b6bfd685ea78",
            "type": "main",
            "index": 0
          },
          {
            "node": "6b385f75-4ebf-46c8-a799-babdb6231f4e",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "47c146f9-1223-46a7-bfd6-0fa6ff701efe": {
      "main": [
        [
          {
            "node": "30355072-5d75-4deb-af67-909ba59e6eb3",
            "type": "main",
            "index": 0
          },
          {
            "node": "dd8f1a00-dfd4-4966-a76c-3c8e2a243bab",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "c4892e34-53af-4d95-a3b6-ca16fdef1aa7": {
      "main": [
        [
          {
            "node": "ee413d6c-dad3-4e57-b08d-ffd0f84c682e",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "e56875c4-ce2b-4639-aabc-21f1562a3858",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "78718555-e266-4f58-ab9d-6e78f50afac2": {
      "main": [
        [
          {
            "node": "b0dc9a07-4957-4643-972b-49952d6fc001",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "6bdbd120-68ac-46ad-bd34-c43d7a447be4": {
      "main": [
        [
          {
            "node": "0c0d0487-a594-4e88-b777-21b4816115cd",
            "type": "main",
            "index": 0
          },
          {
            "node": "e2b0b88d-be4a-4b66-be15-3e8c6052d0f7",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "87f764b3-135c-4dc3-8633-b58e2c3a4e2d": {
      "main": [
        [
          {
            "node": "09dc7ecf-a577-427e-a193-ed29d260c5fe",
            "type": "main",
            "index": 0
          },
          {
            "node": "3a52d7e3-ef56-47db-844a-1efb6c20ad35",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "b0dc9a07-4957-4643-972b-49952d6fc001": {
      "main": [
        [
          {
            "node": "ad83305f-9ca5-428f-a731-9afe3a82258a",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "22b8502c-dec3-4456-9947-639761517881": {
      "main": [
        [
          {
            "node": "47c146f9-1223-46a7-bfd6-0fa6ff701efe",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "e2b0b88d-be4a-4b66-be15-3e8c6052d0f7": {
      "main": [
        [
          {
            "node": "1f2eff56-a89b-4d6d-af8b-477c81c8bab3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ad83305f-9ca5-428f-a731-9afe3a82258a": {
      "main": [
        [
          {
            "node": "0ca15a51-2e56-4ef4-8be6-96f45ed17867",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "99cab485-4099-4505-9c9e-33ea389818e5": {
      "main": [
        [
          {
            "node": "3fab88ce-4a80-483b-b558-12e111f16c98",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
Preguntas frecuentes

¿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 - Ingeniería, Bloques de construcción, Operaciones de TI

¿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.

Información del flujo de trabajo
Nivel de dificultad
Avanzado
Número de nodos34
Categoría3
Tipos de nodos12
Descripción de la dificultad

Adecuado para usuarios avanzados, flujos de trabajo complejos con 16+ nodos

Enlaces externos
Ver en n8n.io

Compartir este flujo de trabajo

Categorías

Categorías: 34