piepdrive-test

工作流概述

这是一个包含8个节点的中等工作流,主要用于自动化处理各种任务。

工作流源代码

下载
{
  "id": "",
  "meta": {
    "instanceId": "",
    "templateCredsSetupCompleted": true
  },
  "name": "piepdrive-test",
  "tags": [],
  "nodes": [
    {
      "id": "b2838678-c796-4c99-a3da-a2cd1b42ea97",
      "name": "Pipedrive Trigger - An Organization is created",
      "type": "n8n-nodes-base.pipedriveTrigger",
      "position": [
        820,
        380
      ],
      "webhookId": "f5de09a8-6601-4ad5-8bc8-9b3f4b83e997",
      "parameters": {
        "action": "added",
        "object": "organization"
      },
      "credentials": {
        "pipedriveApi": {
          "id": "",
          "name": "Pipedrive Connection"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "5aa05d79-b2fa-4040-b4ca-cad83adf2798",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -20,
        120
      ],
      "parameters": {
        "width": 656.3637637842876,
        "height": 1455.9537026322007,
        "content": "# Enrich Pipedrive's Organization Data with GPT-4o When an Organization is Created in Pipedrive

This workflow **enriches a Pipedrive organization's data by adding a note to the organization object in Pipedrive**. It assumes there is a custom \"website\" field in your Pipedrive setup, as data will be scraped from this website to generate a note using OpenAI.

## ⚠️ Disclaimer
**These workflows use a scraping API. Before using it, ensure you comply with the regulations regarding web scraping in your country or state**.

## Important Notes
- The OpenAI model used is GPT-4o, chosen for its large input token context capacity. However, it is also **the most expensive option**, you should take cost into consideration.

- The system prompt in the OpenAI Node generates output with relevant information, but feel free to improve or **modify it according to your needs**.

## **How It Works**

### Node 1: `Pipedrive Trigger - An Organization is Created`
This is the trigger of the workflow. When **an organization object is created in Pipedrive**, this node is triggered and retrieves the data. Make sure you have a \"website\" custom field (the name of the field in the n8n node will appear as a random ID and not with the Pipedrive custom field name).

### Node 2: `ScrapingBee - Get Organization's Website's Homepage Content`
This node **scrapes the content** from the URL of the website associated with the **Pipedrive Organization** created in Node 1. The workflow uses the [ScrapingBee](https://www.scrapingbee.com/) API, but you can use any preferred API or simply the HTTP request node in n8n.

### Node 3: `OpenAI - Message GPT-4o with Scraped Data`
This node sends HTML-scraped data from the previous node to the **OpenAI GPT-4 model**. The system prompt instructs the model to **extract company data**, such as products or services offered and competitors (if known by the model), and format it as HTML for optimal use in a Pipedrive Note.

### Node 4: `Pipedrive - Create a Note with OpenAI Output`
This node **adds a Note to the Organization created in Pipedrive** using the OpenAI node output. The Note will include the company description, target market, selling products, and competitors (if GPT-4 was able to determine them).

### Node 5 & 6: `HTML To Markdown` & `Code - Markdown to Slack Markdown`
These two nodes **format the HTML output to Slack Markdown**.

The Note created in Pipedrive is in HTML format, **as specified by the System Prompt of the OpenAI Node**. To send it to Slack, it needs to be converted to Markdown and then to Slack-specific Markdown.

### Node 7: `Slack - Notify`
This node **sends a message in Slack containing the Pipedrive Organization Note** created with this workflow.
"
      },
      "typeVersion": 1
    },
    {
      "id": "47ee8bfb-2f9d-4790-a929-1533215d6746",
      "name": "Pipedrive - Create a Note with OpenAI output",
      "type": "n8n-nodes-base.pipedrive",
      "position": [
        1640,
        380
      ],
      "parameters": {
        "content": "={{ $json.message.content }}",
        "resource": "note",
        "additionalFields": {
          "org_id": "={{ $('Pipedrive Trigger - An Organization is created').item.json.meta.id }}"
        }
      },
      "credentials": {
        "pipedriveApi": {
          "id": "",
          "name": "Pipedrive Connection"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "7783b531-0469-4bee-868e-4b26a1bb41ba",
      "name": "Code - Markdown to Slack Markdown",
      "type": "n8n-nodes-base.code",
      "position": [
        2080,
        380
      ],
      "parameters": {
        "jsCode": "const inputMarkdown = items[0].json.data;

function convertMarkdownToSlackFormat(markdown) {
    let slackFormatted = markdown;
    
    // Convert headers
    slackFormatted = slackFormatted.replace(/^# (.*$)/gim, '*$1*');
    slackFormatted = slackFormatted.replace(/^## (.*$)/gim, '*$1*');
    
    // Convert unordered lists
    slackFormatted = slackFormatted.replace(/^\* (.*$)/gim, '➡️ $1');
    
    // Convert tables
    const tableRegex = /\n\|.*\|\n\|.*\|\n((\|.*\|\n)+)/;
    const tableMatch = slackFormatted.match(tableRegex);
    if (tableMatch) {
        const table = tableMatch[0];
        const rows = table.split('\n').slice(3, -1);
        const formattedRows = rows.map(row => {
            const columns = row.split('|').slice(1, -1).map(col => col.trim());
            return `*${columns[0]}*: ${columns[1]}`;
        }).join('\n');
        slackFormatted = slackFormatted.replace(table, formattedRows);
    }
    
    return slackFormatted;
}

const slackMarkdown = convertMarkdownToSlackFormat(inputMarkdown);
console.log(slackMarkdown);

// Return data
return [{ slackFormattedMarkdown: slackMarkdown }];
"
      },
      "typeVersion": 2
    },
    {
      "id": "cf2b02df-07e8-4ebb-ba3d-bfd294dcfab0",
      "name": "Scrapingbee - Get Organization's URL content",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1040,
        380
      ],
      "parameters": {
        "url": "https://app.scrapingbee.com/api/v1",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "api_key",
              "value": "<YOUR_SCRAPINGBEE_API_KEY>"
            },
            {
              "name": "url",
              "value": "={{ $json.current.<random_api_id_custom_website_field> }}"
            },
            {
              "name": "render_js",
              "value": "false"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "906d44f0-7582-4742-9fd8-4c8dfba918e0",
      "name": "HTML To Markdown",
      "type": "n8n-nodes-base.markdown",
      "position": [
        1860,
        380
      ],
      "parameters": {
        "html": "={{ $json.content }}",
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "8c1a5d64-4f38-4f9e-8878-443f750206b7",
      "name": "Slack - Notify ",
      "type": "n8n-nodes-base.slack",
      "position": [
        2300,
        380
      ],
      "parameters": {
        "text": "=*New Organizaton {{ $('Pipedrive Trigger - An Organization is created').item.json.current.name }} created on Pipedrive* :


 {{ $json.slackFormattedMarkdown }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultName": "pipedrive-notification"
        },
        "otherOptions": {},
        "authentication": "oAuth2"
      },
      "credentials": {
        "slackOAuth2Api": {
          "id": "",
          "name": "Slack Connection"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "2414a5d3-1d4b-447b-b401-4b6f823a0cf9",
      "name": "OpenAI - Message GPT-4o with Scraped Data",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        1260,
        380
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "GPT-4O"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "={{ $json.data }}"
            },
            {
              "role": "system",
              "content": "You're an assistant that summarizes website content for CRM entries. The user will provide HTML content from a company's website. Your task is to analyze the HTML content and create a concise summary that includes:

1. A brief description of the company's services or products.
2. Any information about the company's target market or customer base.
3. Key points about the company's unique selling propositions or competitive advantages.
4. Based on the provided information, suggest potential competitors if you know any.

Format your response as HTML.

Example response :

    <h1>Company Description</h1>
    <p>Company1 specializes in services related to electric vehicles. The company focuses on providing resources and information about electric car chargers, battery life, different car brands, and the environmental impact of electric vehicles.</p>

    <h2>Target Market</h2>
    <p>The target market for Company1 includes electric vehicle owners and potential buyers who are interested in making the shift from traditional fossil fuel vehicles to electric cars. The company also targets environmentally conscious consumers who are looking for sustainable mobility solutions.</p>

    <h2>Unique Selling Propositions</h2>
    <ul>
        <li>Comprehensive information about electric vehicle charging solutions, including how to install home charging stations.</li>
        <li>Detailed articles on the advantages of electric vehicles such as ecology and reliability.</li>
        <li>Educational resources on the autonomy and battery life of different electric car models.</li>
        <li>Insights into premier electric vehicle brands.</li>
    </ul>

    <h2>Potential Competitors</h2>
    <table border=\"1\">
        <tr>
            <th>Competitor Name</th>
            <th>Website</th>
        </tr>
        <tr>
            <td>Competitor1</td>
            <td><a href=\"https://www.example1.com\">https://www.example1.com</a></td>
        </tr>
        <tr>
            <td>Competitor2</td>
            <td><a href=\"https://www.example2.com\">https://www.example2.com</a></td>
        </tr>
        <tr>
            <td>Competitor3</td>
            <td><a href=\"https://www.example3.com\">https://www.example3.com</a></td>
        </tr>
        <tr>
            <td>Competitor4</td>
            <td><a href=\"https://www.example4.com\">https://www.example4.com</a></td>
        </tr>
    </table>
"
            }
          ]
        }
      },
      "credentials": {
        "openAiApi": {
          "id": "",
          "name": "OpenAi Connection"
        }
      },
      "typeVersion": 1.3
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "",
  "connections": {
    "HTML To Markdown": {
      "main": [
        [
          {
            "node": "Code - Markdown to Slack Markdown",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code - Markdown to Slack Markdown": {
      "main": [
        [
          {
            "node": "Slack - Notify ",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI - Message GPT-4o with Scraped Data": {
      "main": [
        [
          {
            "node": "Pipedrive - Create a Note with OpenAI output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pipedrive - Create a Note with OpenAI output": {
      "main": [
        [
          {
            "node": "HTML To Markdown",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Scrapingbee - Get Organization's URL content": {
      "main": [
        [
          {
            "node": "OpenAI - Message GPT-4o with Scraped Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pipedrive Trigger - An Organization is created": {
      "main": [
        [
          {
            "node": "Scrapingbee - Get Organization's URL content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

功能特点

  • 自动检测新邮件
  • AI智能内容分析
  • 自定义分类规则
  • 批量处理能力
  • 详细的处理日志

技术分析

节点类型及作用

  • Pipedrivetrigger
  • Stickynote
  • Pipedrive
  • Code
  • Httprequest

复杂度评估

配置难度:
★★★☆☆
维护难度:
★★☆☆☆
扩展性:
★★★★☆

实施指南

前置条件

  • 有效的Gmail账户
  • n8n平台访问权限
  • Google API凭证
  • AI分类服务订阅

配置步骤

  1. 在n8n中导入工作流JSON文件
  2. 配置Gmail节点的认证信息
  3. 设置AI分类器的API密钥
  4. 自定义分类规则和标签映射
  5. 测试工作流执行
  6. 配置定时触发器(可选)

关键参数

参数名称 默认值 说明
maxEmails 50 单次处理的最大邮件数量
confidenceThreshold 0.8 分类置信度阈值
autoLabel true 是否自动添加标签

最佳实践

优化建议

  • 定期更新AI分类模型以提高准确性
  • 根据邮件量调整处理批次大小
  • 设置合理的分类置信度阈值
  • 定期清理过期的分类规则

安全注意事项

  • 妥善保管API密钥和认证信息
  • 限制工作流的访问权限
  • 定期审查处理日志
  • 启用双因素认证保护Gmail账户

性能优化

  • 使用增量处理减少重复工作
  • 缓存频繁访问的数据
  • 并行处理多个邮件分类任务
  • 监控系统资源使用情况

故障排除

常见问题

邮件未被正确分类

检查AI分类器的置信度阈值设置,适当降低阈值或更新训练数据。

Gmail认证失败

确认Google API凭证有效且具有正确的权限范围,重新进行OAuth授权。

调试技巧

  • 启用详细日志记录查看每个步骤的执行情况
  • 使用测试邮件验证分类逻辑
  • 检查网络连接和API服务状态
  • 逐步执行工作流定位问题节点

错误处理

工作流包含以下错误处理机制:

  • 网络超时自动重试(最多3次)
  • API错误记录和告警
  • 处理失败邮件的隔离机制
  • 异常情况下的回滚操作