Several workflows with Telegram trigger

Hello :wave: :ru:
Im using N8N for some months and my needs is growing.

Telegram trigger

It was my first workflow. Now it’s big and have many “IF” inside. I didn not sure, that I doing things right.
My purpose is to use one telegram bot for different cases in different chat groups.

Dividing my cases to different workflows. It’s possible?

To make structure, I want to separate my tasks to workspaces, but when tryed I get issues with no triggering node “Telegram trigger”.

What happend

Telegram node generating webhooks which we can see here: https://api.telegram.org/bot<token>/getWebhookInfo
When was only one node with bot webhook it’s all was good. When I starting second node, webhook is rewriting to new one and first node can not receive updates.

Some guides?

Maybe I need for one general workflow, which triggers throught “IF” execution of other workflows? Or maybe I can find some config options to cancel generation of new webhooks?

Hi @N8N_userN, glad to hear n8n is useful for you! From taking a quick look at the Telegram Bot API documentation it sounds indeed like they only allow one webhook per bot.

So with this limitation in mind you would indeed need a single “master” workflow receiving the webhooks. To keep things more manageable you can try the following:

  1. Use the Switch node instead of the IF node. The Switch node provides four outputs instead of the two outputs the IF node provides. If you have more than four cases you’d need to use additional Switch nodes for now (but you might want to consider voting on this feature request: Add more outputs to Switch Node - #8 by maxT).
  2. Put some of your logic in child workflows where possible and call them from your master workflow using the Execute Workflow node. This way you can avoid having multiple complex or lengthy branches in a single workflow.

Hope this already provides some help with cleaning up your big workflow :slight_smile:

1 Like

Wow. It was very fast! Thank you.

  1. Is it good idea to connect “Telegram trigger” directly with subworkflows execution? And those workflows using “IF” deciding to deal or not? I mean “Switch” or “IF” must be only on master workflow?

And about “Switch” for my opinion this more readable:

  1. Maybe there is way to activate pont-and-click interface to manage input parameters for nodes in subworkflow? At screenshot I have pasted them.

Is it good idea to connect “Telegram trigger” directly with subworkflows execution? And those workflows using “IF” deciding to deal or not? I mean “Switch” or “IF” must be only on master workflow?

Interesting approach! I haven’t thought of that, but it should work. The information received by the Telegram Trigger will be passed on to the Start node of the child workflow in this case.

Maybe there is way to activate pont-and-click interface to manage input parameters for nodes in subworkflow?

This is not available at the moment unfortunately. What I usually do is using a Set or Function node while building my sub-workflow that provides some example data. This let’s me use the expression editor from your left in subsequent nodes (this would only work for actual items though, not for parameters - node parameters from the parent workflow aren’t available in the sub-workflow):

image

Example Workflow
{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return [{\n  json: {\n    message: {\n      chat: {\n        id: 123\n      },\n      text: \"Hello, World!\"\n    }\n  }\n}]\n"
      },
      "name": "Set Example Data",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "value": "={{$json[\"message\"][\"text\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Example Expression",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Set Example Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Example Data": {
      "main": [
        [
          {
            "node": "Example Expression",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like