8
n8n 中文网amn8n.com

用于捕获CRM联系人的Telegram机器人

高级

这是一个自动化工作流,包含 27 个节点。主要使用 If, Set, Code, Merge, Crypto 等节点。 使用Telegram和Gemini AI捕获和存储CRM联系人

前置要求
  • Telegram Bot Token
  • Google Sheets API 凭证
  • Google Gemini API Key

分类

-
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "KmdYybT84NNAa1yM",
  "meta": {
    "instanceId": "fc8c505a7d97c0ad5142b508476a4b135c5d385dc29af946d69365fb9717edee",
    "templateCredsSetupCompleted": true
  },
  "name": "用于捕获 CRM 联系人的 Telegram 机器人",
  "tags": [
    {
      "id": "0fVOYNM7WPnd6GTh",
      "name": "public",
      "createdAt": "2025-10-14T10:25:40.579Z",
      "updatedAt": "2025-10-14T10:25:40.579Z"
    }
  ],
  "nodes": [
    {
      "id": "baf521e1-ad2c-40cf-bdd6-78c1872987d7",
      "name": "Telegram 触发器",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -720,
        -48
      ],
      "webhookId": "054bbadb-2087-44d6-bb77-35b446394037",
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {
          "download": true,
          "imageSize": "large"
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "LeL8GGIOucbE798n",
          "name": "n8n_crm_bot"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "acd4c00f-ab7d-4c20-925f-7f8e827bbf17",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -832,
        368
      ],
      "parameters": {
        "width": 816,
        "height": 800,
        "content": "## 用于捕获联系人的 Telegram 机器人"
      },
      "typeVersion": 1
    },
    {
      "id": "62ece471-e4b4-4ed8-ae54-338a6acd02e4",
      "name": "AI 代理",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        384,
        1168
      ],
      "parameters": {
        "text": "={{ $json.userMessage }}",
        "options": {
          "systemMessage": "You are a helpful personal assistant. You are direct and don't talk much.\nYour job is to create and update contacts in the CRM system. User communicates with you via text, audio (transcribed) and images (recognized).\n\nIt is mandatory to extract the following information:\n- first name\n- last name\n- email\n- company name\n\nWhenever possible extract as well:\n- phone number \n- job title\n- meeting notes\n\nYou may ask up to 3 questions about each new contact. Always confirm extracted information using the following format.\n\nExample of confirmation when all mandatory data is extracted, but there are no meeting notes:\n\"\"\"\n✅ First name: {first_name}\n✅ Last name: {last_name}\n✅ Email: {email}\n✅ Company: {company}\n\nDo you have any other info or meeting notes?\n\"\"\"\n\nExample of confirmation when some data is missing:\n\"\"\"\n✅ First name: {first_name}\n❓ Last name:\n✅ Email: {email}\n❓ Company:\n\nDo you know the last name and the company name?\n\"\"\"\n\nExample of confirmation when all mandatory data, as well as some extra data and meeting notes are extracted:\n\"\"\"\n✅ First name: {first_name}\n✅ Last name: {last_name}\n✅ Email: {email}\n✅ Company: {company}\n✅ Title: {job_title}\n✅ Phone: {phone}\n\nDo you have any other info?\n\"\"\"\n\nOnce all the information for a contact is collected, search the CRM for an existing contact by email. If the contact is not found, create a new contact. If the contact exists, ask user whether to create a new contact or update the existing one.\n\nIMPORTANT:\nIf phone number begins with \"+\", prepend it with \"'\" (single quote symbol) when saving. The CRM expects the phone in this format. \n\nUser may send `/new` command which indicates beginning of a fresh chat session. In this case simply confirm that you are waiting for a new contact."
        },
        "promptType": "define"
      },
      "typeVersion": 2.2
    },
    {
      "id": "791fd96b-9808-4573-af52-226695245cf5",
      "name": "Google Gemini 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        192,
        1392
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "id": "0C0iIvVLweHKZMa6",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "c3feefb6-c757-42aa-b78a-af8cc1b8026c",
      "name": "发送短信",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1104,
        1168
      ],
      "webhookId": "b043688f-41dd-4310-96d6-115cabe763f7",
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "LeL8GGIOucbE798n",
          "name": "n8n_crm_bot"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "510e5fa0-1ab1-44be-9338-12ceef3474bb",
      "name": "获取会话 ID",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        192,
        -208
      ],
      "parameters": {
        "limit": 1,
        "filters": {
          "conditions": [
            {
              "keyName": "chatID",
              "keyValue": "={{ $json.message.chat.id }}"
            }
          ]
        },
        "matchType": "allConditions",
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "list",
          "value": "Y6od4eTrxRkUbtyC",
          "cachedResultUrl": "/projects/ZnaXyIe6Nbrn9Af2/datatables/Y6od4eTrxRkUbtyC",
          "cachedResultName": "telegram-crm-example"
        }
      },
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "id": "d320aae4-14ec-4682-8b79-3f320ca58c24",
      "name": "生成会话 ID",
      "type": "n8n-nodes-base.crypto",
      "position": [
        752,
        -208
      ],
      "parameters": {
        "action": "generate",
        "dataPropertyName": "sessionID"
      },
      "typeVersion": 1
    },
    {
      "id": "96f9ff1d-c25a-471e-ab11-ac6985ac61c0",
      "name": "插入/更新行",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        1008,
        -208
      ],
      "parameters": {
        "columns": {
          "value": {
            "chatID": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
            "sessionID": "={{ $json.sessionID }}"
          },
          "schema": [
            {
              "id": "chatID",
              "type": "number",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "chatID",
              "defaultMatch": false
            },
            {
              "id": "sessionID",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "sessionID",
              "defaultMatch": false
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "sessionID"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "filters": {
          "conditions": [
            {
              "keyName": "chatID",
              "keyValue": "={{ $('Telegram Trigger').item.json.message.chat.id }}"
            }
          ]
        },
        "matchType": "allConditions",
        "operation": "upsert",
        "dataTableId": {
          "__rl": true,
          "mode": "list",
          "value": "Y6od4eTrxRkUbtyC",
          "cachedResultUrl": "/projects/ZnaXyIe6Nbrn9Af2/datatables/Y6od4eTrxRkUbtyC",
          "cachedResultName": "telegram-crm-example"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "5f7ce514-bccc-414d-8337-1d051cf03538",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        160,
        -304
      ],
      "parameters": {
        "color": 6,
        "width": 1024,
        "height": 256,
        "content": "## 获取现有会话 ID 或创建新会话 ID"
      },
      "typeVersion": 1
    },
    {
      "id": "cd95f448-16aa-4746-b9bc-89966dbcd1c6",
      "name": "如果没有会话 ID 或输入 /new",
      "type": "n8n-nodes-base.if",
      "position": [
        496,
        -208
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "aa9bdac4-3246-4a92-98ed-695640ff93d7",
              "operator": {
                "type": "object",
                "operation": "empty",
                "singleValue": true
              },
              "leftValue": "={{ $json }}",
              "rightValue": ""
            },
            {
              "id": "92c64c2d-5a97-4f07-a98d-b4035930bb56",
              "operator": {
                "type": "string",
                "operation": "notExists",
                "singleValue": true
              },
              "leftValue": "={{ $json.sessionID }}",
              "rightValue": ""
            },
            {
              "id": "b4e2e2b1-63de-4c57-9218-27bb29e3f18d",
              "operator": {
                "type": "string",
                "operation": "startsWith"
              },
              "leftValue": "={{ $('Telegram Trigger').item.json.message.text }}",
              "rightValue": "/new"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "5281020e-eb31-426c-b123-eb4e1fb0df07",
      "name": "简单记忆",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        336,
        1424
      ],
      "parameters": {
        "sessionKey": "={{ $('Add sessionID to input').item.json.sessionID }}",
        "sessionIdType": "customKey",
        "contextWindowLength": 10
      },
      "typeVersion": 1.3
    },
    {
      "id": "a292b5ef-a1d7-48dd-b806-f6a154a1a8a9",
      "name": "切换",
      "type": "n8n-nodes-base.switch",
      "position": [
        432,
        192
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "audio input",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "c0814978-ad52-4537-bdfb-c83b83955df4",
                    "operator": {
                      "type": "object",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.message.voice }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "image input",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "cc1fd7ef-c1cf-4682-8cad-65833275ff23",
                    "operator": {
                      "type": "array",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.message.photo }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "text input",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "aeff368c-421b-4823-aeec-dc4473d9ff76",
                    "operator": {
                      "type": "string",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.message.text }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra"
        }
      },
      "typeVersion": 3.3
    },
    {
      "id": "f0f58425-7e6c-4ec7-bd21-849dc6471e1e",
      "name": "将会话 ID 添加到输入",
      "type": "n8n-nodes-base.merge",
      "position": [
        208,
        224
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combineBy": "combineByPosition"
      },
      "typeVersion": 3.2
    },
    {
      "id": "4661d734-4f58-412f-bb74-9789eb11feb6",
      "name": "便签 2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        400,
        48
      ],
      "parameters": {
        "color": 6,
        "width": 992,
        "height": 944,
        "content": "## 处理各种类型的用户消息"
      },
      "typeVersion": 1
    },
    {
      "id": "532435f7-2ed0-4c4c-a783-cd3e2d7761d0",
      "name": "参数",
      "type": "n8n-nodes-base.set",
      "position": [
        -192,
        -48
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "8c23a9c4-8623-41b6-bbe0-e34f0d500611",
              "name": "spreadsheet_document_id",
              "type": "string",
              "value": ""
            },
            {
              "id": "309e133e-faa1-47d3-83f6-77f153da7239",
              "name": "sheet_name",
              "type": "string",
              "value": "Sheet1"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "7ac77e30-faf2-4f88-bdee-0bf3e4fcbbe5",
      "name": "创建新联系人",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        656,
        1488
      ],
      "parameters": {
        "columns": {
          "value": {
            "Email": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Email__using_to_match_', `Contact's email`, 'string') }}",
            "Phone": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Phone', `Contact's phone number`, 'string') }}",
            "Company": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Company', `Company name`, 'string') }}",
            "Full name": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Full_name', `Contact's full name (first name + last name)`, 'string') }}",
            "Job title": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Job_title', `Contact's job title`, 'string') }}",
            "Meeting notes": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Meeting_notes', `Notes from the meeting with contact`, 'string') }}"
          },
          "schema": [
            {
              "id": "Full name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Full name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Email",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Phone",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Phone",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Company",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Company",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Job title",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Job title",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Meeting notes",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Meeting notes",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Email"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {
          "useAppend": true
        },
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "={{ $('parameters').item.json.sheet_name }}"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('parameters').item.json.spreadsheet_document_id }}"
        },
        "authentication": "serviceAccount",
        "descriptionType": "manual",
        "toolDescription": "Create a new contact in CRM"
      },
      "credentials": {
        "googleApi": {
          "id": "fwodZhVNzRxPPDoX",
          "name": "Google Sheets account"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "005acc6f-eb10-47cf-a45f-c8fbe7e0ed01",
      "name": "更新现有联系人",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        816,
        1504
      ],
      "parameters": {
        "columns": {
          "value": {
            "Email": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Email__using_to_match_', `Contact's email`, 'string') }}",
            "Phone": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Phone', `Contact's phone number`, 'string') }}",
            "Company": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Company', `Company name`, 'string') }}",
            "Full name": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Full_name', `Contact's full name (first name + last name)`, 'string') }}",
            "Job title": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Job_title', `Contact's job title`, 'string') }}",
            "Meeting notes": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Meeting_notes', `Notes from the meeting with contact`, 'string') }}"
          },
          "schema": [
            {
              "id": "Full name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Full name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Email",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Phone",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Phone",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Company",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Company",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Job title",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Job title",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Meeting notes",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Meeting notes",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Email"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "={{ $('parameters').item.json.sheet_name }}"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('parameters').item.json.spreadsheet_document_id }}"
        },
        "authentication": "serviceAccount",
        "descriptionType": "manual",
        "toolDescription": "Update existing contact in CRM"
      },
      "credentials": {
        "googleApi": {
          "id": "fwodZhVNzRxPPDoX",
          "name": "Google Sheets account"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "f842b387-64bb-4555-95aa-43deedb813cb",
      "name": "搜索联系人",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        496,
        1456
      ],
      "parameters": {
        "options": {},
        "filtersUI": {
          "values": [
            {
              "lookupValue": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('values0_Value', `Contact's email`, 'string') }}",
              "lookupColumn": "Email"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "={{ $('parameters').item.json.sheet_name }}"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('parameters').item.json.spreadsheet_document_id }}"
        },
        "authentication": "serviceAccount",
        "descriptionType": "manual",
        "toolDescription": "Search for an exisitng contact in CRM (by email)"
      },
      "credentials": {
        "googleApi": {
          "id": "fwodZhVNzRxPPDoX",
          "name": "Google Sheets account"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "9fbf58e9-4e04-4cdf-99b9-962cc1659232",
      "name": "发送\"正在输入...\"",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -464,
        -256
      ],
      "webhookId": "9e763cc2-de3e-46be-920e-008b9ec3bc5c",
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "operation": "sendChatAction"
      },
      "credentials": {
        "telegramApi": {
          "id": "LeL8GGIOucbE798n",
          "name": "n8n_crm_bot"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "6f06a5e9-e54d-4333-b720-4234b95d7fd5",
      "name": "获取音频文件",
      "type": "n8n-nodes-base.telegram",
      "position": [
        752,
        352
      ],
      "webhookId": "d89a5bcf-29c4-47c9-856b-6bd2e05a4af4",
      "parameters": {
        "fileId": "={{ $json.message.voice.file_id }}",
        "resource": "file",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "LeL8GGIOucbE798n",
          "name": "n8n_crm_bot"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "804bfa01-8a62-46ed-b86b-c3c21776acdf",
      "name": "转录音频",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        960,
        352
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "models/gemini-2.5-flash",
          "cachedResultName": "models/gemini-2.5-flash"
        },
        "options": {},
        "resource": "audio",
        "inputType": "binary"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "0C0iIvVLweHKZMa6",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "06564c94-911c-42bc-86a0-9562d02469e4",
      "name": "处理音频转录",
      "type": "n8n-nodes-base.code",
      "position": [
        1168,
        352
      ],
      "parameters": {
        "jsCode": "let new_items = []\nlet index = 0\nfor (const item of $input.all()) {\n  let userMessage = \"<transcribed_audio>\" + item.json.content.parts[0].text + \"</transcribed_audio>\";\n  \n  new_items.push({\n    \"userMessage\": userMessage\n  })\n\n  index += 1;\n}\n\nreturn new_items;"
      },
      "typeVersion": 2
    },
    {
      "id": "5b0e9ade-60c3-46a6-a00f-2d7183750fb1",
      "name": "分析图片",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        752,
        576
      ],
      "parameters": {
        "text": "Extract contact information from this image. Look for the following information:\n- first name\n- last name\n- email\n- phone number\n- company name\n- job title",
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "models/gemini-2.5-flash",
          "cachedResultName": "models/gemini-2.5-flash"
        },
        "options": {},
        "resource": "image",
        "simplify": false,
        "inputType": "binary",
        "operation": "analyze"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "0C0iIvVLweHKZMa6",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "192ac754-ad6c-46c6-9e93-12833cb00751",
      "name": "处理提取的数据",
      "type": "n8n-nodes-base.code",
      "position": [
        960,
        576
      ],
      "parameters": {
        "jsCode": "let new_items = []\nlet index = 0\nfor (const item of $input.all()) {\n  let userMessage = \"<extracted_image_content>\" + item.json.candidates[0].content.parts[0].text + \"</extracted_image_content>\";\n  let text = $('Switch').itemMatching(index).json.message.caption\n  if (text) {\n    userMessage += \"\\n\" + text;\n  }\n  \n  new_items.push({\n    \"userMessage\": userMessage\n  })\n\n  index += 1;\n}\n\nreturn new_items;"
      },
      "typeVersion": 2
    },
    {
      "id": "dba4133a-dd92-4a4f-9170-0b14af98a63d",
      "name": "处理文本输入",
      "type": "n8n-nodes-base.code",
      "position": [
        752,
        784
      ],
      "parameters": {
        "jsCode": "let new_items = []\nfor (const item of $input.all()) {\n  let userMessage = item.json.message.text;\n  \n  new_items.push({\n    \"userMessage\": userMessage\n  })\n}\n\nreturn new_items;"
      },
      "typeVersion": 2
    },
    {
      "id": "2fce79a3-9119-41cc-835a-fe8fb04af738",
      "name": "便签 3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -272,
        -160
      ],
      "parameters": {
        "color": 5,
        "width": 256,
        "height": 272,
        "content": "## 配置"
      },
      "typeVersion": 1
    },
    {
      "id": "085c7e80-bd92-4f6b-ad39-b5a6ee2f13ed",
      "name": "便签 4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        128,
        1072
      ],
      "parameters": {
        "color": 6,
        "width": 832,
        "height": 608,
        "content": "## AI 智能体"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "d978e1d6-316e-41a6-b579-25d8332e4053",
  "connections": {
    "Switch": {
      "main": [
        [
          {
            "node": "Get audio file",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Analyze image",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Process text input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Send a text message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "parameters": {
      "main": [
        [
          {
            "node": "Add sessionID to input",
            "type": "main",
            "index": 1
          },
          {
            "node": "Get sessionID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyze image": {
      "main": [
        [
          {
            "node": "Process extracted data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get sessionID": {
      "main": [
        [
          {
            "node": "If no sessionID or /new",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Upsert row(s)": {
      "main": [
        [
          {
            "node": "Add sessionID to input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get audio file": {
      "main": [
        [
          {
            "node": "Transcribe audio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "parameters",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send \"typing...\"",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Transcribe audio": {
      "main": [
        [
          {
            "node": "Process audio transcript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create new contact": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Generate sessionID": {
      "main": [
        [
          {
            "node": "Upsert row(s)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process text input": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search for contact": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Add sessionID to input": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process extracted data": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If no sessionID or /new": {
      "main": [
        [
          {
            "node": "Generate sessionID",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Add sessionID to input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update existing contact": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Process audio transcript": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

高级

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
高级
节点数量27
分类-
节点类型15
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

作者

I help businesses implement innovative AI/ML solutions, redesign existing systems to cut costs and boost reliability, and conduct applied R&D. I specialize in AI automation, agents, LLMs, Generative AI and Computer Vision. Need help customizing workflows? Just find me on Upwork.

外部链接
在 n8n.io 查看

分享此工作流