← All N8N workflows
AI & researchAgentExecution DataGoogle SheetsHTTP RequestIf

receive telegram events and send next question and telegram

Configured with Agent, Execution Data, Google Sheets, HTTP Request, and additional nodes. Review the connections and setup before adapting this template.

Workflow preview
TriggerTelegram TriggerTelegram TriggerMessagingSend Next QuestionTelegramMessagingSend ResponseTelegramRoutingHas No Record?IfRoutingIs Survey Continue?IfData storeGet State2RedisData storeGet Columns1Google SheetsTransformSet Variables1Edit FieldsRoutingMessage Type1SwitchTransformGet Command1Edit FieldsRoutingBot Actions1SwitchData storeMemory3Memory Redis ChatTransformGet Survey State1Edit FieldsData storeReset Agent Memory1Memory ManagerData storeMemory4Memory Redis ChatData storeStart Session1RedisData storeGet State3RedisData storeIncrement Index1RedisAI & modelsInterview Agent1AgentData storeGet Record1Google SheetsTransformAppend Responses1Edit FieldsWeb / APIUpdate Answer2HTTP RequestData storeGet Last Bot Message1RedisWeb / APIUpdate Answer3HTTP RequestAI & modelsModel2OpenAI Chat ModelAI & modelsModel3OpenAI Chat ModelAI & modelsShould Follow Up?1Text ClassifierIntegrationExecution Data2Execution DataData storeCreate Record2Google SheetsMessagingSend StartTelegramMessagingSend Start1TelegramMessagingCompleted SurveyTelegramData storeCreate Record1Google Sheets

Node categories in this workflow

  • Trigger
  • Messaging
  • Routing
  • Data store
  • Transform
  • AI & models
  • Web / API
  • Integration

Icons describe general node roles, inferred from node types. Inspect the parameters for the configured action.

Drag to pan; use + and − to zoom. Reconstructed from the exported node positions; nothing runs here. Dashed lines represent non-main connections. Full node names and notes appear below.

How it works

The exported workflow contains the following configured nodes. Their connections are shown above; inspect the JSON for the complete logic, expressions, and external actions.

Workflow node names, types, and operations
NodeCategoryTypeOperation
Telegram TriggerTriggerTelegram TriggerSee node parameters
Send Next QuestionMessagingTelegramSee node parameters
Send ResponseMessagingTelegramSee node parameters
Has No Record?RoutingIfSee node parameters
Is Survey Continue?RoutingIfSee node parameters
Get State2Data storeRedisget
Get Columns1Data storeGoogle SheetsSee node parameters
Set Variables1TransformEdit FieldsSee node parameters
Message Type1RoutingSwitchSee node parameters
Get Command1TransformEdit FieldsSee node parameters
Bot Actions1RoutingSwitchSee node parameters
Memory3Data storeMemory Redis ChatSee node parameters
Get Survey State1TransformEdit FieldsSee node parameters
Reset Agent Memory1Data storeMemory ManagerSee node parameters
Memory4Data storeMemory Redis ChatSee node parameters
Start Session1Data storeRedisset
Get State3Data storeRedisget
Increment Index1Data storeRedisset
Interview Agent1AI & modelsAgentSee node parameters
Get Record1Data storeGoogle SheetsSee node parameters
Append Responses1TransformEdit FieldsSee node parameters
Update Answer2Web / APIHTTP RequestPUT
Get Last Bot Message1Data storeRedisget
Update Answer3Web / APIHTTP RequestPUT
Model2AI & modelsOpenAI Chat ModelSee node parameters
Model3AI & modelsOpenAI Chat ModelSee node parameters
Should Follow Up?1AI & modelsText ClassifierSee node parameters
Execution Data2IntegrationExecution DataSee node parameters
Create Record2Data storeGoogle SheetsappendOrUpdate
Send StartMessagingTelegramSee node parameters
Send Start1MessagingTelegramSee node parameters
Completed SurveyMessagingTelegramSee node parameters
Create Record1Data storeGoogle SheetsappendOrUpdate

Setup

  1. Download the JSON and import it into an isolated n8n instance. Leave the workflow inactive.
  2. Connect your own credentials through n8n’s credential store. Replace REPLACE_WITH_* values with your resource identifiers.
  3. Inspect API destinations, Code nodes, database queries, file paths, and outbound actions.
  4. Run with synthetic data and harmless destinations. Enable triggers only after checking the actual outputs.

Requirements

An n8n instance with the listed node types and compatible versions. Service-connected workflows may require accounts, credentials, or paid APIs.

Credential types declared in the source

  • googleSheetsOAuth2Api
  • openAiApi
  • redis
  • telegramApi

Workflow notes

1. Initiate Survey by Inviting User to Chat

1. Initiate Survey by Inviting User to Chat

Learn more about the chat trigger

To present the survey to the user, we'll use n8n's builtin hosted chat. Survey questions are predefined and pulled from Google Sheet. Finally, for state and session management such as tracking which question we're asking, we'll use Redis as it's a fast write and ready database suitable for our chat.

2. Handle Bot Commands

2. Handle Bot Commands

Learn more about the switch node

Our chatbot can be a mix of traditional chat mechanics and AI agent. Using bot commands, gives the user some control over the flow of the conversation such as skipping to the next question or starting over the survey.

3. Support to Follow-Up Questions

3. Support to Follow-Up Questions

Learn more about the Text Classifier node

Depending on whether the current question is open-ended or closed-ended, we may not require the Agent to spend too much time on the answer. Here we're using the text classifier node to make that judgement call - when closed-ended, we can skip to the next question and when open-ended, we can attempt to dig deeper into the answer.

4. Deeper Insights with a Conversational AI Agent

4. Deeper Insights with a Conversational AI Agent

Learn more about the AI Agent

The way we utilise the AI in this workflow is by allowing the agent to converse back-and-forth with the user on any given question of the survey. This means answers can be more than just single sentence and can expand to minute-long conversations, producting much deeper insights for the survey.

5. Managing Conversational Flow with External State

5. Managing Conversational Flow with External State

Learn more about the Redis node

We use Redis as a quick and easy way to store and track the question index (or "state") as the user progresses through the survey. To calculate which question should be next or if the survey is complete, we query the spreadsheet row for the user's session and calculate our next state from there.

6. Resetting Chat Memory for Every Question

6. Resetting Chat Memory for Every Question

Learn more about the Chat Memory Manager

I discovered that to ensure my agent focused on a specific question when interacting with the user, I needed to clear all previous message context to prevent it from using past references. This is a really unconventional approach to controlling Agent behaviour but from my observation, greatly reduces hallucinations during the conversation.

Try It Out

Try It Out

This n8n template demonstrates how you can build a structured chat journey augmented with AI for your business.

In this scenario, a chatbot conducts a product satisfaction survey with a user using a predefined set of questions. For each question, the agent can dive deeper into the user's answers by asking follow-up questions.

This chatbot template isn't fully "agentic" which makes it a bit more complicated and scripted but ensures a more deterministic user journey; suitable when you need more guide-rails on the experience.

See example survey here: https://docs.google.com/spreadsheets/d/REPLACE_WITH_DOCUMENT_ID/2PACX-1vQWcREg75CzbZd8loVI12s-DzSTj3NE_02cOCpAh7umj0urazzYCfzPpYvvh7jqICWZteDTALzBO46i/pubhtml?gid=0&single=true

How it works

  • A chat session is started with the user who needs to enter the bot command "/next" to start the survey.
  • Once started, the template pulls in questions from a google sheet to ask the user. Questions are asked in sequence from left to right.
  • When the user answers the question, a text classifier node is used to determine if a follow-up question could be asked.
  • If not, the survey proceeds to the next question. Otherwise, an AI Agent will generate a follow-up question based on the user's response.
  • All answers and AI conversations are recorded in the Google Sheet.
  • When all questions are answered, the template will stop the survey and give the user a chance to restart.

How to use

  • You'll need to setup a Telegram bot (see docs)
  • Create a google sheet with an ID column. Populate the rest of the columns with your survey questions (see sample)
  • Ensure you have a Redis instance to capture state. Either self-host or sign-up to Upstash for a free account.
  • Update the "Set Variable" node with your google sheet ID and survey title.
  • Share the bot with users to allow others to participate in your survey.

Can I use this for WhatsApp?

Yes you can! Swapping out all telegram nodes for WhatsApp nodes should produce the same result.

Need Help?

Join the Discord or ask in the Forum!

receive telegram events and send next question and telegram

receive telegram events and send next question and telegram

Purpose and structure

This folder contains the receive telegram events and send next question and telegram workflow. Its executable nodes use agent, executionData, googleSheets, httpRequest, if, lmChatOpenAi, memoryManager, memoryRedisChat, redis, set, switch, telegram, telegramTrigger, textClassifier. The table and connection map below are derived from the JSON, not an inferred guarantee of behavior.

Setup

Import inactive. Configure your own credentials and replace REPLACE_WITH_* values. Review external destinations and Code nodes before running.

Entry points

Telegram Trigger

Verification

Sanitized source candidate; not runtime-tested. This overview is generated from node metadata. Read the folder README for the connection map, credential types, and license.

Attribution

https://github.com/Zie619/n8n-workflows/blob/94007c1445d9258a7da116646b79473e7c7c3282/workflows/Telegram/0782_Telegram_Redis_Create_Webhook.json MIT; preserve source notices.

More in AI & research