Issue on telegram trigger

Hi my dear friends
I really search about my problem in internet but unfortunately I can’t find anything so if anyone help me please.

In my case:
I add a telegram bot updater to my flow by telegram trigger.
In telegram, I want to ask some questions from my users and then save their answers in my google sheet (database).

My problem is that how can I realize what answer is to specific question.

In fact now I use “forced reply” option in my questions (when I send message to my user).

{
  "name": "000",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "text": "How old you?",
        "replyMarkup": "forceReply",
        "forceReply": {
          "force_reply": true
        },
        "additionalFields": {}
      },
      "name": "Telegram",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1,
      "position": [
        400,
        300
      ]
    },
    {
      "parameters": {
        "updates": [
          "*"
        ]
      },
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1,
      "position": [
        278,
        574
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$node[\"Telegram Trigger\"].data[\"message\"][\"reply_to_message\"][\"text\"]}}",
              "value2": "How old you?"
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        428,
        574
      ]
    },
    {
      "parameters": {
        "text": "Thanks",
        "additionalFields": {}
      },
      "name": "Telegram1",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1,
      "position": [
        620,
        550
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "Telegram1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {},
  "id": "15"
}

You could do it like that:

{
  "nodes": [
    {
      "parameters": {
        "chatId": "={{$node[\"Telegram Trigger\"].data[\"message\"][\"chat\"][\"id\"]}}",
        "text": "How old are you?",
        "replyMarkup": "forceReply",
        "forceReply": {
          "force_reply": true
        },
        "additionalFields": {}
      },
      "name": "Telegram",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1,
      "position": [
        800,
        600
      ],
      "credentials": {
        "telegramApi": ""
      }
    },
    {
      "parameters": {
        "updates": [
          "*"
        ]
      },
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1,
      "position": [
        400,
        500
      ],
      "credentials": {
        "telegramApi": ""
      }
    },
    {
      "parameters": {
        "chatId": "={{$node[\"Telegram Trigger\"].data[\"message\"][\"chat\"][\"id\"]}}",
        "text": "=Thanks. You are  {{$node[\"If Reply\"].data[\"message\"][\"text\"]}}",
        "additionalFields": {}
      },
      "name": "Telegram1",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1,
      "position": [
        800,
        400
      ],
      "credentials": {
        "telegramApi": ""
      }
    },
    {
      "parameters": {
        "conditions": {
          "string": [],
          "boolean": [
            {
              "value1": "={{!!$node[\"Telegram Trigger\"].data[\"message\"][\"reply_to_message\"]}}",
              "value2": true
            }
          ]
        }
      },
      "name": "If Reply",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        600,
        500
      ]
    }
  ],
  "connections": {
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "If Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Reply": {
      "main": [
        [
          {
            "node": "Telegram1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Make sure that when you test, you press “Execute Workflow” every time you received an answer as the workflow has to get executed twice. Once to receive the first message and ask for the age and once to receive the age and send the response (that you could then save in Google Sheets).

1 Like

Dear @jan
Thank you for your response. :pray:
I think I couldn’t get what I meant truly. :sleepy:

In some bots (in Telegram) I see that:
They ask Continuously several questions that needs their user responses through typing.
Their method is not through “forced reply” option.
For example they just ask question “How old are you?” without “forced reply” method and then their user send for example just “24” then,
Bot just ask “What is your name?” without “forced reply” and user just send “Maria”
then bot save “24” in “user_age” column and save “Maria” in “user_firstName” column in user_data table and etc.

I want to know how they recognize what response is for what question without using “forced reply” method?! (I know that this question is not related straightly to n8n and is for my knowledge).

Best regards;

I guess to do that you would simply have to save in Google Sheets the chat-id and what question got asked last.

So if the chat-id is “123” and you ask for the age you would save in the row for the chat-id “123” under “lastQuestionAsked” simply “user_age”. Once you then get the next webhook call with the answer you can look up in the Google Sheet what the last question was. it will then return “user_age” and you can then save the returned value under “user_age”. After that, you could then simply ask the next question and depending on what it is supposed to be (example “user_firstName”) you would then save that value under “lastQuestionAsked” and so on.

I come across similar situation where I need to ask a couple of follow-up questions, for example:

user: /sum
bot: ok, please enter the first number:
user: 10
bot: please enter the second number:
user: 20
bot: the sum is 30

How can I complete this kind of conversion that I need to track the state?

As far as I know, each workflow acts like a pipeline that starts with the input from a trigger node and then passes on the data to process in the successive nodes. If I need to get a second input from the follow-up question, should I start another workflow?

And if I need to start another workflow, is there any internal memory that I can save my previous state instead of using Google Sheet?

Many thanks!