Catch a replied message to bot message in telegram + updating GoogleSheets row

Hi everyone. I’m a beginner on the n8n platform, but I guess there are features that allow me to implement my user scenario.

Below I describe the workflow I want to implement and questions with troubles. Thank you, for your help!

In short: I want create a content manager, based on telegram bot and Google sheets.

Step by step:

  1. User sends content via telegram bot (text, image, file, audio)
  2. Bot saves content and data about user to new row in Google sheets
  3. Bot shows keyboard with choices (Add comment and select folder)
  4. User presses “add comment” button
  5. Bot sends a “Enter comment” message
  6. User enters a comment
  7. Bot adds a comment to column “Comment” to existed row in Google sheets, where it has recorded the user’s content and data
  8. The user presses the “select folder” button
  9. Bot shows the other keyboard with the folders list (from a predefined variable)
  10. User presses a button with the required folder name
  11. Bot adds folder name to to column “Folder” to existed row in the Google sheets line, where he has already written the content, user data and comment.

Questions:

  1. Points 4-6 - I don’t understand how I can distinguish through a telegram trigger that the user replied to the bot’s “Enter Comment” question rather than sending in new content. Is this even realistic to do? Also, I don’t understand how the keyboard callback function in the telegram trigger works, I thought it was needed for this, but it doesn’t work when testing…
  2. I tried point 7, but it doesn’t work to add a value to an existing google sheets row
1 Like

Hey @Nikita_Bessonov!

Welcome to the community :sparkling_heart:

I’ve not tried something similar. Maybe @mcnaveen can help you

1 Like

Hey @harshil1712 Thanks for the Mention.

Hello @Nikita_Bessonov :wave: Thanks for your question and Brief Explanation.


:warning: This is too complicated to create and might not work as expected. I’m just sharing my thoughts and little example


I tried to create Workflow based on your inputs. But, To be honest. It’s quiet complicated to build.

Here is the sample screenshot for your comment part in the points you have mentioned.

Here is the code for above workflow { "nodes": [ { "parameters": { "authentication": "oAuth2", "operation": "append", "sheetId": "1l6OqgPz_cV4gEDvERFf8FbTmtjlq07MuQrLb-YIilkk", "range": "A:B", "options": { "valueInputMode": "USER_ENTERED" } }, "name": "Google Sheets", "type": "n8n-nodes-base.googleSheets", "typeVersion": 1, "position": [ 1140, 360 ], "credentials": { "googleSheetsOAuth2Api": "mcntempmail" } }, { "parameters": { "updates": [ "*" ], "additionalFields": {} }, "name": "Telegram Trigger", "type": "n8n-nodes-base.telegramTrigger", "typeVersion": 1, "position": [ 420, 300 ], "webhookId": "e47cef21-16a6-45c5-8590-fffb8a656cf5", "credentials": { "telegramApi": "n8n test bot" } }, { "parameters": { "values": { "string": [ { "name": "user_id", "value": "={{$node[\"Telegram Trigger\"].json[\"message\"][\"from\"][\"id\"]}}" }, { "name": "username", "value": "={{$json[\"message\"][\"chat\"][\"username\"]}}" } ] }, "options": {} }, "name": "Assign Variables", "type": "n8n-nodes-base.set", "typeVersion": 1, "position": [ 970, 360 ] }, { "parameters": { "conditions": { "string": [ { "value1": "={{$node[\"Telegram Trigger\"].json[\"message\"][\"text\"]}}", "value2": "/start" } ] } }, "name": "IF", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [ 610, 300 ] }, { "parameters": { "chatId": "={{$node[\"Telegram Trigger\"].json[\"message\"][\"from\"][\"id\"]}}", "text": "Please send a right command to start contribution", "additionalFields": {} }, "name": "Telegram", "type": "n8n-nodes-base.telegram", "typeVersion": 1, "position": [ 830, 190 ], "credentials": { "telegramApi": "n8n test bot" } }, { "parameters": { "conditions": { "string": [ { "value1": "={{$node[\"Telegram Trigger\"].json[\"message\"][\"text\"]}}", "value2": "/new" } ] } }, "name": "IF1", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [ 780, 380 ] }, { "parameters": { "chatId": "={{$node[\"Telegram Trigger\"].json[\"message\"][\"from\"][\"id\"]}}", "text": "Select the Option to Perform action", "replyMarkup": "replyKeyboard", "replyKeyboard": { "rows": [ { "row": { "buttons": [ { "text": "Add Comment", "additionalFields": {} } ] } } ] }, "replyKeyboardOptions": {}, "additionalFields": {} }, "name": "Telegram1", "type": "n8n-nodes-base.telegram", "typeVersion": 1, "position": [ 1340, 360 ], "credentials": { "telegramApi": "n8n test bot" } } ], "connections": { "Google Sheets": { "main": [ [ { "node": "Telegram1", "type": "main", "index": 0 } ] ] }, "Telegram Trigger": { "main": [ [ { "node": "IF", "type": "main", "index": 0 } ] ] }, "Assign Variables": { "main": [ [ { "node": "Google Sheets", "type": "main", "index": 0 } ] ] }, "IF": { "main": [ [ { "node": "Telegram", "type": "main", "index": 0 } ], [ { "node": "IF1", "type": "main", "index": 0 } ] ] }, "IF1": { "main": [ [ { "node": "Assign Variables", "type": "main", "index": 0 } ], [ { "node": "Telegram", "type": "main", "index": 0 } ] ] } } }

Let me explain the problem:

Telegram Trigger works only one time, It is designed or made in such way to receive an event once and execute it.

n8n is a workflow model. Means, once the data is received via Trigger or WebHook it process the data or perform stuffs based on the received data until the workflow is fully complete.

We can’t make the workflow to wait for the next data to receive. (You can’t have trigger node between two nodes. Because triggers are meant only for starting the workflow, But there is a workaround for this)

You can either have multiple workflows like above screenshot and check the trigger message you receive from Telegram with the help of IF Node.

For Example:

  • In workflow 1 - I have a telegram trigger, after that there is one IF Node which checks whether the message contains “/start”. If Yes, It’ll reply “Please send the right command to start”.

  • In Workflow 2 - I have same setup but IF Node should check whether received message has “New Comment” as text. If Yes, Then It’ll start the Workflow, and perform next actions.

This way, You can divide the workflows for easier understanding.


Summary:

  • You need multiple workflow, Because trigger works only one time Or You have to do it with Multiple IF Conditions the send it to the TRUE or FALSE Branch
  • You need multiple telegram nodes, Problem here is. There is API limit for telegram. You can read more about this here.
  • I got error for too many request when building this sample workflow.

If you explain your use case, I can suggest alternative solution :slight_smile:

1 Like

@Nikita_Bessonov I built this Telegram interactive quiz bot a while back.
It covers most of the functionality that you are trying to achieve.
I used Airtable instead of Google Sheets.

Hope it helps. Let me know if you have any queries.

Workflow:

Link to the Workflow code

Also, this is the Telegram bot: Quiz Bot

The Airtable base template: Quiz Database Demo

5 Likes

That is nice workflow @shrey-42 :heart:

2 Likes

Yes great @shrey-42 ! Thanks for sharign!

2 Likes

Hi @harshil1712 @mcnaveen @shrey-42
Thank you so much for your help, I guess I will try to recombine the workflow shared by @shrey-42 and I hope that will useful.

And thanks to n8n team, you made a really wonderful community. I’m excited!

5 Likes

@shrey-42 Thanks for your share, could you share your Airtable Template, too?

Sure. I’ve updated my original post with the link.

2 Likes

Hey @Nikita_Bessonov,

How is it going? Were you able to achieve it?