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.
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.
| Node | Category | Type | Operation |
|---|---|---|---|
| Telegram Trigger | Trigger | Telegram Trigger | See node parameters |
| Send Next Question | Messaging | Telegram | See node parameters |
| Send Response | Messaging | Telegram | See node parameters |
| Has No Record? | Routing | If | See node parameters |
| Is Survey Continue? | Routing | If | See node parameters |
| Get State2 | Data store | Redis | get |
| Get Columns1 | Data store | Google Sheets | See node parameters |
| Set Variables1 | Transform | Edit Fields | See node parameters |
| Message Type1 | Routing | Switch | See node parameters |
| Get Command1 | Transform | Edit Fields | See node parameters |
| Bot Actions1 | Routing | Switch | See node parameters |
| Memory3 | Data store | Memory Redis Chat | See node parameters |
| Get Survey State1 | Transform | Edit Fields | See node parameters |
| Reset Agent Memory1 | Data store | Memory Manager | See node parameters |
| Memory4 | Data store | Memory Redis Chat | See node parameters |
| Start Session1 | Data store | Redis | set |
| Get State3 | Data store | Redis | get |
| Increment Index1 | Data store | Redis | set |
| Interview Agent1 | AI & models | Agent | See node parameters |
| Get Record1 | Data store | Google Sheets | See node parameters |
| Append Responses1 | Transform | Edit Fields | See node parameters |
| Update Answer2 | Web / API | HTTP Request | PUT |
| Get Last Bot Message1 | Data store | Redis | get |
| Update Answer3 | Web / API | HTTP Request | PUT |
| Model2 | AI & models | OpenAI Chat Model | See node parameters |
| Model3 | AI & models | OpenAI Chat Model | See node parameters |
| Should Follow Up?1 | AI & models | Text Classifier | See node parameters |
| Execution Data2 | Integration | Execution Data | See node parameters |
| Create Record2 | Data store | Google Sheets | appendOrUpdate |
| Send Start | Messaging | Telegram | See node parameters |
| Send Start1 | Messaging | Telegram | See node parameters |
| Completed Survey | Messaging | Telegram | See node parameters |
| Create Record1 | Data store | Google Sheets | appendOrUpdate |
Setup
- Download the JSON and import it into an isolated n8n instance. Leave the workflow inactive.
- Connect your own credentials through n8n’s credential store. Replace
REPLACE_WITH_*values with your resource identifiers. - Inspect API destinations, Code nodes, database queries, file paths, and outbound actions.
- 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
googleSheetsOAuth2ApiopenAiApiredistelegramApi
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
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?
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.