How can we Trigger Telegram only on specific word

This option triggers the node for all text like hi, hello, or even any sticker.

How can I trigger it only when the word matches?
Example: Only “Send” should trigger the node

image

Any idea on this @tanay?

You can simply use an IF-Node:

{
  "nodes": [
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1,
      "position": [
        450,
        300
      ],
      "webhookId": "4a718efe-d52b-43f3-bac8-7330200ec6d5",
      "credentials": {
        "telegramApi": "n8ntest2_bot"
      }
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$node[\"Telegram Trigger\"].json[\"message\"][\"text\"]}}",
              "operation": "contains",
              "value2": "hi"
            },
            {
              "value1": "={{$node[\"Telegram Trigger\"].json[\"message\"][\"text\"]}}",
              "operation": "contains",
              "value2": "hello"
            }
          ]
        },
        "combineOperation": "any"
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {},
      "name": "Does not contain text",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        850,
        400
      ]
    },
    {
      "parameters": {},
      "name": "Contains text",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        850,
        190
      ]
    }
  ],
  "connections": {
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "Contains text",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Does not contain text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like

Hey @mcnaveen, I have only tried this with Mattermost before and that was a functionality on their side. Looking at the Telegram Trigger node, I am not sure if this is possible (yet?). I’d use a IF node in front of the trigger node to emulate your use-case. Not sure if this is the best solution, perhaps @jan has some insights here?

Trying… Will update you soon @jan @tanay

What I’m doing wrong here? If the user replies with the Reply Keyboard text. It should send the image. Otherwise, for all words it should reply “Don’t send unwanted messages”

  {
      "nodes": [
        {
          "parameters": {
            "operation": "sendPhoto",
            "chatId": "={{$node[\"Telegram Trigger1\"].json[\"message\"][\"from\"][\"id\"]}}",
            "file": "https://i.redd.it/pmf7ztkytz241.jpg",
            "replyMarkup": "replyKeyboard",
            "replyKeyboard": {
              "rows": [
                {
                  "row": {
                    "buttons": [
                      {
                        "text": "🐶🐶🐶🐶",
                        "additionalFields": {}
                      }
                    ]
                  }
                }
              ]
            },
            "replyKeyboardOptions": {},
            "additionalFields": {}
          },
          "name": "Telegram",
          "type": "n8n-nodes-base.telegram",
          "typeVersion": 1,
          "position": [
            1490,
            110
          ],
          "credentials": {
            "telegramApi": "CheemsBot API"
          }
        },
        {
          "parameters": {
            "chatId": "={{$node[\"Telegram Trigger1\"].json[\"message\"][\"from\"][\"id\"]}}",
            "text": "Don't send unwanted messages",
            "replyMarkup": "replyKeyboard",
            "replyKeyboard": {
              "rows": []
            },
            "replyKeyboardOptions": {},
            "additionalFields": {}
          },
          "name": "Telegram1",
          "type": "n8n-nodes-base.telegram",
          "typeVersion": 1,
          "position": [
            1510,
            320
          ],
          "credentials": {
            "telegramApi": "CheemsBot API"
          }
        },
        {
          "parameters": {},
          "name": "Does not contain text",
          "type": "n8n-nodes-base.noOp",
          "typeVersion": 1,
          "position": [
            1108,
            331
          ]
        },
        {
          "parameters": {},
          "name": "Contains text",
          "type": "n8n-nodes-base.noOp",
          "typeVersion": 1,
          "position": [
            1108,
            121
          ]
        },
        {
          "parameters": {
            "updates": [
              "message"
            ],
            "additionalFields": {}
          },
          "name": "Telegram Trigger1",
          "type": "n8n-nodes-base.telegramTrigger",
          "typeVersion": 1,
          "position": [
            708,
            231
          ],
          "webhookId": "4a718efe-d52b-43f3-bac8-7330200ec6d5",
          "credentials": {
            "telegramApi": "CheemsBot API"
          }
        },
        {
          "parameters": {
            "conditions": {
              "string": [
                {
                  "value1": "={{$node[\"Telegram Trigger1\"].json[\"message\"][\"text\"]}}",
                  "operation": "contains",
                  "value2": "hi"
                },
                {
                  "value1": "={{$node[\"Telegram Trigger1\"].json[\"message\"][\"text\"]}}",
                  "operation": "contains",
                  "value2": "hello"
                }
              ]
            },
            "combineOperation": "any"
          },
          "name": "IF1",
          "type": "n8n-nodes-base.if",
          "typeVersion": 1,
          "position": [
            908,
            231
          ]
        }
      ],
      "connections": {
        "Does not contain text": {
          "main": [
            [
              {
                "node": "Telegram1",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Contains text": {
          "main": [
            [
              {
                "node": "Telegram",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Telegram Trigger1": {
          "main": [
            [
              {
                "node": "IF1",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "IF1": {
          "main": [
            [
              {
                "node": "Contains text",
                "type": "main",
                "index": 0
              }
            ],
            [
              {
                "node": "Does not contain text",
                "type": "main",
                "index": 0
              }
            ]
          ]
        }
      }
    }

That is not what your workflow is doing. If the message contains “hi” or “hello” it does one thing, if not it does something else.

If it contains any of the words(hi, hello) it sends a message with the replyKeyboard and if not it sends the unwanted message text.

2 Likes