Deploy an advanced n8n workflow for Telegram. Create a witty AI bot using OpenRouter, offering jokes, roasts, scheduled posts, and managing user statistics in a Postgres database. Use these comprehensive n8n templates.
Download this n8n workflow template and start using it instantly.
Community Managers needing an engaging, autonomous bot for their Telegram group.
Developers looking for advanced n8n templates integrating Langchain AI Agents and custom database logic.
Automation Specialists wanting to deploy a fun, production-ready AI solution using n8n.
Users seeking a complete n8n workflow example for chat automation, analytics, and scheduling.
Building an engaging chat bot requires more than simple keyword responses—it needs persistence, context, and intelligence. This advanced n8n workflow solves this by merging real-time communication (Telegram) with the flexible, low-latency AI models available through OpenRouter, backed by a robust Postgres database (ideal for Supabase).
This workflow manages user authentication, conversation history, activity logging, and scheduling, making it a professional, ready-to-deploy solution. Every interaction is recorded, providing data for /stats and /top leaderboards. The core intelligence relies on specialized AI nodes, ensuring the bot's tone—witty, slightly ironic, and concise—is consistent across all commands and mentions. This specific n8n workflow demonstrates how to handle complex routing, database interactions, and specialized AI formatting requirements efficiently within the n8n environment.
This automation operates primarily on two parallel paths, starting with distinct n8n trigger nodes.
Webhook Telegram n8n trigger captures all incoming messages, commands, or mentions.Log message + statistics Postgres n8n node instantly stores the message and updates the user's message count and last activity timestamp in the user_stats table.Switch n8n node inspects the message text to determine if it is an AI command (/joke, /roast), an info command (/stats, /top, /help), or a direct mention (@GiggleGPTBot).Chat history Postgres n8n node fetches the last 15 messages to provide relevant context to the AI model.Mention Analysis Code n8n node parses the command type, user metadata, current time context, and conversation history.Get user statistics, Get top users). The Generating an information response Code n8n node formats this data into a human-readable reply. A Log command Postgres n8n node increments the command count.AI response to command or AI response to mention. Both Langchain Agent n8n nodes use OpenRouter to generate the witty, concise reply based on strict system prompts.Save Bot Response Postgres n8n node and then sent back to the user using a Telegram Send n8n node.Schedule n8n trigger runs every hour (using a cron expression).Get scheduled posts Postgres n8n node queries the database for posts scheduled for the current hour.AI post generation Langchain Agent n8n node uses OpenRouter to create the appropriate content (e.g., a morning joke or daily motivation).Save Bot Response2 and immediately delivered to the target Telegram chat via the Submit scheduled post Telegram n8n node.To utilize this complex n8n workflow template, follow these steps:
Init Database n8n node and execute it manually once. This creates all necessary tables (usermessages, userstats, botresponses, etc.).Adding a schedule n8n node once to insert initial cron entries for morning jokes and daily motivations. Remember to adjust the chatid parameter within the SQL query to match your specific Telegram group ID.Webhook Telegram n8n trigger to active and ensure the webhook connection is established with Telegram. Activate the Schedule n8n trigger for automated posts. Your comprehensive n8n workflow is now ready. Webhook Telegram (n8n trigger): The main entry point. It receives all messages and commands sent to the bot in the Telegram chat.
Schedule (n8n trigger): A cron-based n8n trigger that executes hourly (0 ) to check for time-sensitive scheduled posts.
Postgres (Init Database): Executes complex SQL to create all required database tables for message logging, command tracking, user statistics, and scheduled posts. Essential for the function of this n8n workflow.
Postgres (Log message + statistics): Inserts every incoming user message and updates the messagescount in the userstats table using an ON CONFLICT clause for atomic updates.
Langchain Agent (AI response to command / mention / post generation): These are the core AI processing n8n node instances. They use the OpenRouter credential to access high-quality models (specified as openai/gpt-oss-120b in one instance) and adhere to strict system prompts for witty, concise output (1-2 sentences) tailored to specific commands (/joke, /roast, etc.).
Code (Mention Analysis): A custom n8n node that performs complex pre-processing, fetching chat history from Postgres, parsing commands, setting content type, and preparing the payload for the AI model.
Postgres (Chat history): Retrieves the last 15 user and bot messages from the database, aggregating them to provide conversational context for the AI agents.
Switch: Routes the incoming message to the correct processing path (AI response vs. Information response) based on the specific command found in the Telegram message. This efficient n8n node controls the flow.
Leverage this powerful n8n workflow to build a WhatsApp voice assistant. It utilizes Twilio, VAPI, Google Calendar, Gmail, Supabase, and OpenAI for managing appointments and accessing a custom knowledge base via a conversational interface.

Build an advanced, multi-tool AI assistant using this n8n workflow. Integrate WhatsApp, OpenAI, Gmail, Google Calendar, and Supabase for comprehensive customer support automation using specialized n8n node agents.

Deploy a powerful n8n workflow for WhatsApp using GPT-4o Vision, Whisper transcription, and Redis buffering. This advanced n8n automation handles text, audio, and image analysis for contextual AI interactions.

Automate Mattermost team management using this efficient n8n workflow. Create new channels, add users, and post introductory messages instantly. Use this powerful n8n template for standardized project setup.









































