8
n8n 中文网amn8n.com

MS_最佳餐厅

中级

这是一个Miscellaneous领域的自动化工作流,包含 12 个节点。主要使用 Function, Telegram, HttpRequest, TelegramTrigger 等节点。 通过 SerpAPI 使用 Google 地图查找高评分餐厅的 Telegram 机器人

前置要求
  • Telegram Bot Token
  • 可能需要目标 API 的认证凭证

分类

工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "d0e1NBA4VBYDxN8n",
  "meta": {
    "instanceId": "c92a0c76586da37fb3ac600956b62e842bfa4bd5f52acc7feb4e8a6e75ca1381",
    "templateCredsSetupCompleted": true
  },
  "name": "MS_BEST_RESTURANTS",
  "tags": [],
  "nodes": [
    {
      "id": "f8ce8570-13f0-4a6f-9b45-6ae95d011e0a",
      "name": "Telegram触发器",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -640,
        -80
      ],
      "webhookId": "95ec8c95-f3b3-48c5-82ff-803c0187bef1",
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {
          "chatIds": "={{ $env.telegram_channel_id }}"
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "OymlVCuTPYhVa2B9",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "03d40b05-8552-43d5-8daa-bb7bf0755e31",
      "name": "解析区域",
      "type": "n8n-nodes-base.function",
      "position": [
        -260,
        -80
      ],
      "parameters": {
        "functionCode": "// expects a message like “/rest Tahrir”\nconst txt = $json.message?.text || '';\nconst area = txt.replace(/^(\\/rest\\s*)/i, '').trim() || 'Cairo';\nreturn [{ area }];"
      },
      "typeVersion": 1
    },
    {
      "id": "91bf1506-aa76-4db4-8cbf-aa7cc17e3c91",
      "name": "查找餐厅(SerpAPI)",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        420,
        -80
      ],
      "parameters": {
        "url": "https://serpapi.com/search.json",
        "options": {
          "response": {
            "response": {
              "responseFormat": "json"
            }
          }
        },
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "engine",
              "value": "Maps"
            },
            {
              "name": "q",
              "value": "={{ $env.country_name }}+{{$node[\"Parse Area\"].json.area}}+restaurants"
            },
            {
              "name": "hl",
              "value": "=en"
            },
            {
              "name": "type",
              "value": "search"
            },
            {
              "name": "api_key",
              "value": "{{ $env.serp_api_key }}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "0f1dd436-0472-47fa-af80-6ba706c6668f",
      "name": "地理编码(Nominatim)",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        80,
        -80
      ],
      "parameters": {
        "url": "https://nominatim.openstreetmap.org/search",
        "options": {
          "response": {
            "response": {
              "responseFormat": "json"
            }
          }
        },
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "format",
              "value": "json"
            },
            {
              "name": "limit",
              "value": "1"
            },
            {
              "name": "q",
              "value": "={{$node['Parse Area'].json.area}}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "b201467a-20ad-465a-87d2-3040ca7f8c18",
      "name": "格式化回复",
      "type": "n8n-nodes-base.function",
      "position": [
        760,
        -80
      ],
      "parameters": {
        "functionCode": "/********************************************************************\n * Build a slick Telegram message from SerpAPI → Google Maps results *\n ********************************************************************/\n\nconst area = $node['Parse Area'].json.area;\n\n// helper for ✅ / ❌\nconst icon = v => v ? '✅' : '❌';\n\nconst list = ($json.local_results || [])\n  .sort((a, b) => (b.rating || 0) - (a.rating || 0))\n  .slice(0, 5)\n  .map((p, i) => {\n\n    // Build a Maps link that *doesn’t* hit SerpAPI again\n    const { latitude: lat, longitude: lng } = p.gps_coordinates || {};\n    const mapUrl = lat && lng\n      ? `https://maps.google.com/?q=${lat},${lng}`\n      : (p.link || '');\n\n    // Service-options (English keys from Google)\n    const dineIn   = icon(p.service_options?.dine_in);\n    const takeAway = icon(p.service_options?.takeaway);\n\n    // Compose one restaurant block\n    return `${i + 1}. *${p.title}* ⭐${p.rating || '-'}\\n`\n         + `${p.type || ''} | ${p.open_state || ''}\\n`\n         + `☎️ ${p.phone || '—'} ${p.website ? `| 🌐 ${p.website}` : ''}\\n`\n         + `🍽️ Dine-in: ${dineIn} | Takeaway: ${takeAway}\\n`\n         + `📍 [On the Map](${mapUrl})`;\n  })\n  .join('\\n\\n');\n\nreturn [{\n  chat_id: $node['Telegram Trigger'].json.message.chat.id,\n  text: `🍽 *Best Restaurants in ${area} – Top 5*\\n\\n${list}`,\n  parse_mode: 'Markdown'\n}];"
      },
      "typeVersion": 1
    },
    {
      "id": "7eeb9f6c-b01e-4201-a50e-9879d5808577",
      "name": "发送到 Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1100,
        -80
      ],
      "webhookId": "4dba9350-6959-4847-b4a7-eecac7461e50",
      "parameters": {
        "text": "={{$json.text}}",
        "chatId": "={{ $json.chat_id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "OymlVCuTPYhVa2B9",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "694181f1-fa81-491e-9961-39a6714a2d4f",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -320,
        -160
      ],
      "parameters": {
        "color": 4,
        "width": 220,
        "height": 260,
        "content": "## 解析区域"
      },
      "typeVersion": 1
    },
    {
      "id": "599a57fb-977c-42c6-867d-d9fe96665095",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        20,
        -160
      ],
      "parameters": {
        "color": 5,
        "width": 220,
        "height": 260,
        "content": "## 地理编码"
      },
      "typeVersion": 1
    },
    {
      "id": "20c03a86-19fe-4202-ae35-3fdd3c6cad20",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        360,
        -160
      ],
      "parameters": {
        "color": 6,
        "width": 220,
        "height": 260,
        "content": "## 搜索"
      },
      "typeVersion": 1
    },
    {
      "id": "b4e32a1d-fbb7-4e8b-ab1f-7c8cbeb82987",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        700,
        -160
      ],
      "parameters": {
        "color": 7,
        "width": 220,
        "height": 260,
        "content": "## 响应"
      },
      "typeVersion": 1
    },
    {
      "id": "57a0f6ff-af36-4620-ba1c-a0ae0c6bdb0a",
      "name": "便签说明4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1040,
        -160
      ],
      "parameters": {
        "color": 2,
        "width": 220,
        "height": 260,
        "content": "## 回复"
      },
      "typeVersion": 1
    },
    {
      "id": "bbe6544a-0f7e-41a0-86ae-5a9cfed7947d",
      "name": "便签说明5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -700,
        -300
      ],
      "parameters": {
        "color": 3,
        "width": 320,
        "height": 120,
        "content": "## 先决条件"
      },
      "typeVersion": 1
    }
  ],
  "active": true,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "cce0fe1d-4849-42c9-8932-6b1044ff0cd3",
  "connections": {
    "Parse Area": {
      "main": [
        [
          {
            "node": "Geocode (Nominatim)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Reply": {
      "main": [
        [
          {
            "node": "Send to Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Parse Area",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Geocode (Nominatim)": {
      "main": [
        [
          {
            "node": "Find Restaurants (SerpAPI)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find Restaurants (SerpAPI)": {
      "main": [
        [
          {
            "node": "Format Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - 杂项

需要付费吗?

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

工作流信息
难度等级
中级
节点数量12
分类1
节点类型5
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

外部链接
在 n8n.io 查看

分享此工作流