Check if parameter is present

I was trying to find out if the telegram trigger is present with the parameter {{$node[“Telegram Trigger”].data[“message”][“document”][“file_name”]}}

My first try was an IF node checking the regex for .* but that doesn’t seem to work.

What would be the best way to make sure this string exists?

As there is no lodash get functionality it would sadly have to be done the uglier way.
Here two examples with fake data that show how it would once return false and once true depending on if the property exists or not:

{
  "nodes": [
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      message: {\n        document: {\n          file_name: 'my-file.txt'\n        }\n      }\n    }\n  }\n]"
      },
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{!!($node[\"Telegram Trigger\"].data && $node[\"Telegram Trigger\"].data[\"message\"] && $node[\"Telegram Trigger\"].data[\"message\"][\"document\"] && $node[\"Telegram Trigger\"].data[\"message\"][\"document\"][\"file_name\"])}}",
              "value2": true
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        700,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n    }\n  }\n]"
      },
      "name": "Telegram Trigger1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        450,
        500
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{!!($node[\"Telegram Trigger1\"].data && $node[\"Telegram Trigger1\"].data[\"message\"] && $node[\"Telegram Trigger1\"].data[\"message\"][\"document\"] && $node[\"Telegram Trigger1\"].data[\"message\"][\"document\"][\"file_name\"])}}",
              "value2": true
            }
          ]
        }
      },
      "name": "IF1",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        700,
        500
      ]
    }
  ],
  "connections": {
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger1": {
      "main": [
        [
          {
            "node": "IF1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like