AutomationFlowsSocial Media › Telegram to Facebook Interest Workflow

Telegram to Facebook Interest Workflow

Original n8n title: Telegram Code

Telegram Code. Uses noOp, telegramTrigger, facebookGraphApi, spreadsheetFile. Event-driven trigger; 11 nodes.

Event trigger★★★★☆ complexity11 nodesTelegram TriggerFacebook Graph ApiSpreadsheet FileTelegram
Social Media Trigger: Event Nodes: 11 Complexity: ★★★★☆ Added:

This workflow follows the Telegram → Telegram Trigger recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "nodes": [
    {
      "id": "9cfeb58b-140f-4941-8442-4e33c671e325",
      "name": "No Operation, do nothing",
      "type": "n8n-nodes-base.noOp",
      "position": [
        440,
        840
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "c4e7c596-4f2a-48e0-a932-ad40157c6282",
      "name": "Get interest name",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        100,
        660
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "69d432d1-4ab1-4059-af5c-ba589dfe16bc",
      "name": "Check message contents",
      "type": "n8n-nodes-base.if",
      "position": [
        280,
        660
      ],
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{ $json.message.chat.id }}",
              "value2": -1001805495093,
              "operation": "equal"
            }
          ],
          "string": [
            {
              "value1": "={{ $json.message.text }}",
              "value2": "#interest",
              "operation": "startsWith"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "345274b6-2d56-4d54-937a-dd9153fd1fdc",
      "name": "Extract message",
      "type": "n8n-nodes-base.code",
      "position": [
        460,
        460
      ],
      "parameters": {
        "jsCode": "let inputData = items[0].json; // get the input data\nlet message = inputData.message; // replace 'message' with the correct field name\n\nlet messageContent = '';\n\nif (message && message.text) {\n  messageContent = message.text;\n}\n\nreturn [\n  {\n    json: {\n      messageContent: messageContent\n    }\n  }\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "cd808029-1a46-4fad-9065-c726960fb427",
      "name": "Split Message",
      "type": "n8n-nodes-base.code",
      "position": [
        660,
        460
      ],
      "parameters": {
        "jsCode": "let inputData = items[0].json; // get the input data\nlet variableContent = String(inputData.messageContent || ''); // replace 'variable' with the correct field name, convert to string and assign empty string if undefined\n\nlet regex = /#(\\w+)\\b(.*)/; // regex to match hashtag word and rest of the content\nlet matches = regex.exec(variableContent);\n\nlet extractedContent = '';\nlet remainingContent = '';\n\nif (matches !== null) {\n  extractedContent = matches[1];\n  remainingContent = matches[2].trim();\n} else {\n  remainingContent = variableContent.trim();\n}\n\nreturn [\n  {\n    json: {\n      extractedContent: extractedContent,\n      remainingContent: remainingContent    }\n  }\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "6f541faf-7756-415e-8391-5470166b8a01",
      "name": "Connect to Graph API",
      "type": "n8n-nodes-base.facebookGraphApi",
      "position": [
        840,
        460
      ],
      "parameters": {
        "edge": "=",
        "node": "=search?type=adinterest&q={{ $json.remainingContent }}\n&limit=1000000&locale=en_US ",
        "options": {},
        "graphApiVersion": "v17.0"
      },
      "credentials": {
        "facebookGraphApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "394a34ce-f56d-4a79-8fbb-f37681cbee76",
      "name": "Split Interests into a Table",
      "type": "n8n-nodes-base.code",
      "position": [
        1020,
        460
      ],
      "parameters": {
        "jsCode": "let inputData = items[0].json; // get the input data\nlet outputData = [];\n\nfor(let key in inputData) {\n    if(inputData.hasOwnProperty(key)) {\n        let itemKey = key;\n        let itemValue = inputData[key];\n        \n        for(let subKey in itemValue) {\n            if(itemValue.hasOwnProperty(subKey)) {\n                let formattedItem = {\n                    'Item': itemKey,\n                    'SubItem': subKey,\n                    'Value': itemValue[subKey]\n                };\n                \n                outputData.push({json: formattedItem});\n            }\n        }\n    }\n}\n\nreturn outputData;"
      },
      "typeVersion": 2
    },
    {
      "id": "1d3f66a4-322f-4398-b887-52ccd2f2f5fe",
      "name": "Get variables",
      "type": "n8n-nodes-base.code",
      "position": [
        1200,
        460
      ],
      "parameters": {
        "jsCode": "let outputData = items.map(item => {\n    let data = item.json.Value;\n    \n    return {\n        json: {\n            'name': data.name,\n            'audience_size_lower_bound': data.audience_size_lower_bound,\n            'audience_size_upper_bound': data.audience_size_upper_bound,\n            'path': data.path,\n            'description': data.description,\n            'topic': data.topic\n        }\n    };\n});\n\nreturn outputData;"
      },
      "typeVersion": 2
    },
    {
      "id": "082ddf0f-29ef-424a-a2a2-4bf9e260657f",
      "name": "Create a Spreadsheet",
      "type": "n8n-nodes-base.spreadsheetFile",
      "position": [
        1380,
        460
      ],
      "parameters": {
        "options": {},
        "operation": "toFile",
        "fileFormat": "csv"
      },
      "typeVersion": 2
    },
    {
      "id": "44e4f97a-cd86-4b60-b761-49dc46f7e36b",
      "name": "Send the Spreadsheet file",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1560,
        460
      ],
      "parameters": {
        "chatId": "-1001805495093",
        "operation": "sendDocument",
        "binaryData": true,
        "additionalFields": {
          "fileName": "report.csv"
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "22bc6129-7d10-46fd-98e2-0f3fc7a93344",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        800,
        340
      ],
      "parameters": {
        "width": 948.6687115198118,
        "height": 296.5325040542755,
        "content": "## Facebook API\n\nTo get the API Key you need to follow these steps:\nhttps://developers.facebook.com/docs/commerce-platform/setup/api-setup/"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Get variables": {
      "main": [
        [
          {
            "node": "Create a Spreadsheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Message": {
      "main": [
        [
          {
            "node": "Connect to Graph API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract message": {
      "main": [
        [
          {
            "node": "Split Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get interest name": {
      "main": [
        [
          {
            "node": "Check message contents",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Connect to Graph API": {
      "main": [
        [
          {
            "node": "Split Interests into a Table",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create a Spreadsheet": {
      "main": [
        [
          {
            "node": "Send the Spreadsheet file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check message contents": {
      "main": [
        [
          {
            "node": "Extract message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Interests into a Table": {
      "main": [
        [
          {
            "node": "Get variables",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

How this works

This workflow streamlines the process of capturing Telegram messages containing Facebook ad interests and organising them into a structured Google Sheet, saving marketers hours of manual data entry. It's designed for digital advertising professionals who frequently receive interest lists via Telegram chats and need quick integration with Facebook's Graph API for validation and expansion. The key step involves extracting and splitting the message content before querying the Graph API to fetch detailed interest data, which is then formatted into a spreadsheet for easy analysis.

Use this workflow when handling ad campaign planning that relies on crowdsourced or team-shared interest suggestions through Telegram, ensuring seamless data flow to your Facebook Ads Manager setup. Avoid it for high-volume or real-time processing needs, as the event-driven trigger suits sporadic messages better than continuous streams. Common variations include adapting the spreadsheet output for direct import into ad set creation tools or adding email notifications for interest validation alerts.

About this workflow

Telegram Code. Uses noOp, telegramTrigger, facebookGraphApi, spreadsheetFile. Event-driven trigger; 11 nodes.

Source: https://github.com/Zie619/n8n-workflows — original creator credit. Request a take-down →

More Social Media workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

Social Media

This n8n workflow is designed to extract specific interests from messages in a Telegram chat and retrieve related information using the Facebook Graph API. It aims to provide a streamlined solution fo

Telegram Trigger, Facebook Graph Api, Spreadsheet File +1
Social Media

13-Convert_YouTube_Videos_to_Shorts_with_Klap___Auto_Post_to_Multiple_Social_Platforms. Uses httpRequest, telegramTrigger, googleSheets, telegram. Event-driven trigger; 36 nodes.

HTTP Request, Telegram Trigger, Google Sheets +1
Social Media

Once set up, simply send any Instagram Reel or Facebook video link to your Telegram bot, and it will automatically: Check if the shared link is valid. Detect whether it’s an Instagram or Facebook link

Telegram Trigger, HTTP Request, Telegram
Social Media

&gt; Download TikTok videos instantly without watermarks via Telegram &gt; Fast, reliable, and user-friendly automated workflow

Telegram Trigger, Telegram, HTTP Request
Social Media

Desafio RPA TikTok - Bot Dinâmico Master. Uses telegramTrigger, httpRequest, telegram, errorTrigger. Event-driven trigger; 21 nodes.

Telegram Trigger, HTTP Request, Telegram +1