Use this comprehensive n8n workflow to build a stateful WhatsApp bot. Automatically collect structured questionnaire responses (Anketa) and persist all session data and answers in PostgreSQL.
Download this n8n workflow template and start using it instantly.
Markdown-formatted list of user personas:
Technical marketers or researchers needing a scalable solution for collecting feedback via WhatsApp.
Businesses using PostgreSQL for backend data storage.
Developers looking for advanced examples of state management within an n8n workflow.
Anyone seeking ready-made n8n templates for building conversational interfaces.
Building stateful conversational bots requires robust logic to track user progress. This specific n8n workflow, often referred to as an 'Anketa' module, provides a complete solution for initiating a multi-step questionnaire via WhatsApp, tracking the user's progress through database lookups, and saving each individual answer. The power of this n8n template lies in its tight integration between the conversational interface (WhatsApp) and the data storage layer (PostgreSQL), ensuring reliable data capture even if the user pauses the conversation. Every incoming message triggers this n8n workflow, which then intelligently decides if the user is starting the survey, responding to a question, or issuing a command. This implementation uses several PostgreSQL operations to maintain the 'Bot Status' effectively.
The entire flow is initiated by the WhatsApp Trigger n8n node whenever a new message is received.
WhatsApp Trigger receives the inbound message, and the Initialization Set n8n node prepares the input data.Get Bot Status PostgreSQL n8n node to determine the user's current stage in the questionnaire flow.Define Flow Switch n8n node routes the execution based on the retrieved status or the command in the message (e.g., START, ANKETA, or a specific answer).Starts Test, uses the Get First Question PostgreSQL n8n node to fetch the first item, sends it via the First Question WhatsApp n8n node, and uses Update Bot Status on ANKETA to set the conversation context.Get prev Answer to check context. The Is Question found? If n8n node verifies the session.Add Answer PostgreSQL n8n node. Then, Get Available Questions fetches the next question.Is Questions available? If n8n node checks the list. If true, the next question is sent via the Question WhatsApp n8n node. If false, the survey is complete, triggering the Finish Anketa WhatsApp n8n node, and the status is reset using Update Bot Status on START.This robust architecture, utilizing key flow control n8n nodes, ensures seamless data collection.
To set up this powerful n8n workflow, follow these steps:
WhatsApp Trigger node and all subsequent WhatsApp sender nodes.Get Bot Status, Upsert Bot Status on START, and Add Answer to ensure the n8n workflow functions correctly.This n8n workflow relies heavily on database interaction and flow control:
WhatsApp Trigger (n8n trigger): The entry point. Listens for incoming messages via a registered webhook endpoint.
Postgres Nodes (Multiple): Used for all state management. Key instances include:
Get Bot Status: Queries the database to retrieve the current state of the user's interaction.
Upsert Bot Status on START: Creates or updates the user's session status upon initiating the interaction.
Add Answer / Add prev Answer: Inserts the user's response into the database. Key Configuration: Uses SQL INSERT or UPDATE commands dynamically based on workflow data.
Get First Question / Get Available Questions: Fetches subsequent questionnaire items from the database.
Switch Node (Define Flow, Commands): Essential flow control n8n node. Determines which branch of the automation to execute based on message content or user state.
If Node (Is Question found?, Is Questions available?): Conditional branching n8n node used to determine if the conversation should continue to the next question or terminate.
Starts, First Question, Question, Finish Anketa): Responsible for sending structured messages, questions, and completion notifications back to the user.Deploy a powerful, self-hosted star rating feedback system using this comprehensive n8n workflow. Collect submissions instantly and store them in an n8n Data Table for analysis.

A robust n8n workflow designed to scrape targeted LinkedIn profiles using SerpAPI Google Search and store the resulting data instantly in Google Sheets. Use these n8n templates for efficient lead generation.

A powerful n8n workflow utilizing SerpAPI and OpenAI to scrape targeted LinkedIn profiles, enrich data (like company names and follower counts), and automatically store leads in NocoDB and an Excel file.

Use this powerful n8n workflow to automatically gather YouTube channel statistics, calculate recent video engagement, and find contact emails using SerpAPI, centralizing all data in Google Sheets.

Use this powerful n8n workflow to capture leads via an embedded form, validate emails using Hunter, and instantly log data to Google Sheets, Gmail, and Discord for rapid follow-up.


Analyst-Developer







































