← All N8N workflows
AI & researchAgentCodeExecute WorkflowExecute Workflow TriggerIf

sendandwait telegram and set redis and get redis

Configured with Agent, Execute Workflow, Execute Workflow Trigger, Information Extractor, and additional nodes. Review the connections and setup before adapting this template.

Workflow preview
MessagingHuman Handoff usingSend and WaitTelegramData storeSet Interaction to BotRedisData storeSet Interaction toHumanRedisData storeGet Interaction StateRedisAI & modelsModelOpenAI Chat ModelData storeMemoryMemory Redis ChatTriggerHandoff SubworkflowExecute Workflow TriggerTriggerTelegram TriggerTelegram TriggerMessagingSend ResponseTelegramRoutingSwitch InteractionSwitchAI & modelsInformation ExtractorInformation ExtractorAI & modelsOpenAI Chat ModelOpenAI Chat ModelCodeWith DefaultsCodeRoutingHas All Criteria?IfAI & modelsOnboarding AgentAgentData storeGet Onboarding ChatHistoryRedisAI & modelsAfter Sales AgentAgentData storeMemory1Memory Redis ChatAI & modelsModel1OpenAI Chat ModelSubworkflowHandoff ToolTool WorkflowSubworkflowHandoff Subworkflow1Execute WorkflowMessagingSend Response2TelegramData storeMemory2Memory Redis ChatData storeUpdate Agent MemoryMemory ManagerMessagingSend Response3TelegramMessagingGet Canned ResponseTelegramMessagingNotify userTelegramData storeMemory3Memory Redis ChatData storeUpdate Agent Memory1Memory ManagerMessagingContinue ConversationTelegram

Node categories in this workflow

  • Messaging
  • Data store
  • AI & models
  • Trigger
  • Routing
  • Code
  • Subworkflow

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
Human Handoff using Send and WaitMessagingTelegramsendAndWait
Set Interaction to BotData storeRedisset
Set Interaction to HumanData storeRedisset
Get Interaction StateData storeRedisget
ModelAI & modelsOpenAI Chat ModelSee node parameters
MemoryData storeMemory Redis ChatSee node parameters
Handoff SubworkflowTriggerExecute Workflow TriggerSee node parameters
Telegram TriggerTriggerTelegram TriggerSee node parameters
Send ResponseMessagingTelegramSee node parameters
Switch InteractionRoutingSwitchSee node parameters
Information ExtractorAI & modelsInformation ExtractorSee node parameters
OpenAI Chat ModelAI & modelsOpenAI Chat ModelSee node parameters
With DefaultsCodeCodeSee node parameters
Has All Criteria?RoutingIfSee node parameters
Onboarding AgentAI & modelsAgentSee node parameters
Get Onboarding Chat HistoryData storeRedisget
After Sales AgentAI & modelsAgentSee node parameters
Memory1Data storeMemory Redis ChatSee node parameters
Model1AI & modelsOpenAI Chat ModelSee node parameters
Handoff ToolSubworkflowTool WorkflowSee node parameters
Handoff Subworkflow1SubworkflowExecute WorkflowSee node parameters
Send Response2MessagingTelegramSee node parameters
Memory2Data storeMemory Redis ChatSee node parameters
Update Agent MemoryData storeMemory ManagerSee node parameters
Send Response3MessagingTelegramSee node parameters
Get Canned ResponseMessagingTelegramSee node parameters
Notify userMessagingTelegramSee node parameters
Memory3Data storeMemory Redis ChatSee node parameters
Update Agent Memory1Data storeMemory ManagerSee node parameters
Continue ConversationMessagingTelegramSee node parameters

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

  • openAiApi
  • redis
  • telegramApi

Workflow notes

1. Check Interaction State For Incoming Message

1. Check Interaction State For Incoming Message

Learn more about the telegram trigger

This is an example of a state-based agent - the technique commonly known as a finite-state machine. This is a great way to really control the flow and direction of the conversation where there are requirements to collect data or perform steps in sequence. To manage the session state, we can use Redis and the session key will be the user's number.

2. Onboarding Agent to Validate Customers

2. Onboarding Agent to Validate Customers

Read more about Agents

This agent unlike the common multi-tasking examples out there, is only tasked to handle the user's onboarding. In this way, we trade convenience for clutter but ensure the agent is less likely to stray from the desired path.

3. Extract Customer Details from Conversation

3. Extract Customer Details from Conversation

Learn more about the Information Extractor

To collect the user's details in a structured format, we can analyse the current conversation and extract the data with the Information Extractor node. This allows the conversation to remain free-form and avoids asking a question for each field. We use a code node to check if all details are captured.

4. Human Handoff when Criteria Met

4. Human Handoff when Criteria Met

Learn more about subworkflows

Here, we initiate the hand-off which calls our hand-off subworkflow. Subworkflows can be a great way to run actions concurrently and without blocking the reply to the user. At this point, the session state would be set to "human" which means the human agent should take over.

5. Defer to Human

5. Defer to Human

When session state is "human", no further user messages can reach the agent. This is to ensure there isn't a parallel conversation happening which may confuse the human and agent.

6. Interaction Switched Back to Bot

6. Interaction Switched Back to Bot

Read more about the Customer Workflow Tool

When the session state is "bot", it signals the human agent has "transferred" the user back to the bot and so can continue processing their messages. A Custom Workflow Tool is used to retrigger the hand-off process whenever the user requests for it.

7. Interaction Subworkflow

7. Interaction Subworkflow

Learn more about n8n's human-in-the-loop feature

The hand-off implementation here involves a "human-in-the-loop" feature of n8n - a feature which "pauses" an execution whilst running until a reply or action is sent back by the human. Sounds complicated but good to note that n8n handles this interaction seemlessly! Here, we're using it to allow the human agent to reliquish control of the conversation back to the AI agent. Additionally, the human agent's feedback is captured and added to the agent's memory to better assist the user afterwards.

Try it out

Try it out

This n8n template demonstrates an approach to perform bot-to-human handoff using Human-in-the-loop functionality as a switch.

In this experiment, we play with the idea of states we want our agent to be in which controls it's interacton with the user.

  • First state - the agent is onboarding the user by collecting their details for a sales inquiry. After which, they are handed-off / transferred to a human to continue the call.
  • Second state - the agent is essentially "deactivated" as further messages to the bot will not reach it. Instead, a canned response is given to the user. The human agent must "reactivate" the bot by completing the human-in-the-loop form and give a summary of their conversation with the user.
  • Third state - the agent is "reactivated" with context of the human-to-user conversation and is set to provide after sales assistance. An tool is made available to the agent to again delegate back to the human agent when requested.

How it works

  • This template uses telegram to handle the interaction between the user and the agent.
  • Each user message is checked for a session state to ensure it is guided to the right stage of the conversation. For this, we can use Redis as a simple key-value store.
  • When no state is set, the user is directed through an onboarding step to attain their details. Once complete, the agent will "transfer" the user to a human agent - technically, all this involves is an update to the session state and a message to another chat forwarding the user's details.
  • During this "human" state, the agent cannot reply to the user and must wait until the human "transfers" the conversation back. The human can do this by replying to "human-in-the-loop" message with a summary of their conversation with the user. This session state now changes to "bot" and the context is implanted in the agent's memory so that the agent can respond to future questions.
  • At this stage of the conversation, the agent is now expected to handle and help the user with after-sales questions. The user can at anytime request transfer back to the human agent, repeating the previous steps as necessary.

How to use

  • Plan your user journey! Here is a very basic example of a sales inquiry with at most 3 states. More thought should be developed when many more states are involved.
  • You may want to better log and manage session states so no user is left in limbo. Try connecting the user and sessions to your CRM.
  • Note, the Onboarding agent and After-Sales agent have separate chat memories. When adding more agents, it is recommend to continue having separate chat memories to help focus between states.

Need Help?

Join the Discord or ask in the Forum!

Happy Hacking!

Add Human Chat ID

Add Human Chat ID

This is needed to notify the human agent.

sendandwait telegram and set redis and get redis

sendandwait telegram and set redis and get redis

Purpose and structure

This folder contains the sendandwait telegram and set redis and get redis workflow. Its executable nodes use agent, code, executeWorkflow, executeWorkflowTrigger, if, informationExtractor, lmChatOpenAi, memoryManager, memoryRedisChat, redis, switch, telegram, telegramTrigger, toolWorkflow. 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

Handoff Subworkflow, 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/0815_Telegram_Code_Update_Triggered.json MIT; preserve source notices.

More in AI & research