Build an AI Personal Assistant with n8n

Build an AI Personal Assistant with n8n

Imagine having a single automated system that can read and reply to emails, schedule meetings, track your expenses, research topics, draft blog posts, and even plan your travels – all coordinated from one place in n8n.

This guide explains how to build that AI personal assistant using an n8n workflow template. You will see how tools like GPT models, Perplexity, Tavily, Gmail, Google Calendar, Airtable, SerpAPI, WeatherAPI, and Replicate work together in a modular architecture that you can adapt to your own needs.


What you will learn

By the end of this tutorial-style article, you will understand:

  • Why n8n is a strong choice for building an AI personal assistant
  • The overall architecture: an Orchestrator Agent plus specialized sub-agents
  • How each agent (email, calendar, finance, content, research, travel, etc.) works
  • How to set up the n8n workflow step by step, including memory and research flows
  • How a full example (publishing a blog post) runs from start to finish
  • Best practices for security, monitoring, costs, and scaling

You can follow this guide whether you are starting from the existing n8n template or recreating the architecture in your own instance.


Why use n8n for an AI personal assistant?

n8n is an open source workflow automation platform that is especially well suited for building AI assistants made of multiple agents and tools. It gives you:

  • Visual flow design – you can connect nodes for Gmail, Google Calendar, Airtable, LLMs, and more in a drag-and-drop canvas.
  • Extensible integrations – n8n supports many cloud APIs and AI providers such as OpenAI, Anthropic, Perplexity, Tavily, SerpAPI, WeatherAPI, and Replicate.
  • Security and self-hosting – you can run n8n on your own infrastructure, store credentials securely, and control what data leaves your environment.

Instead of building a monolithic chatbot, n8n lets you compose small, focused agents into one orchestrated assistant. This modular approach makes the system easier to debug, extend, and maintain.


Core architecture: Orchestrator plus modular agents

The workflow is organized around a central Orchestrator Agent that coordinates several domain-specific agents. Each agent has a clear responsibility and a defined way to communicate with the orchestrator.

1. Orchestrator Agent (the “brain” of the workflow)

The Orchestrator Agent is the central node that:

  • Receives user input from channels like Telegram or HTTP webhooks
  • Understands the intent behind the request (for example “schedule a meeting” or “track this expense”)
  • Routes the request to the correct specialized agent
  • Collects and formats the final response for the user

You can think of the orchestrator as a conductor directing different sections of an orchestra. It does not do the heavy work itself. Instead, it delegates to agents such as Email, Calendar, Finance, Content, Research, and Travel.

2. Specialized agents (the “skills” of your assistant)

Each agent is implemented as a modular subflow in n8n. Below is an overview of the main agents in this architecture and what they do.

Finance Tracker Agent

  • Logs and queries expenses in Airtable
  • Useful for quick expense tracking and categorization (for example food, travel, personal)
  • Can answer questions like “How much did I spend on travel this month?” by querying Airtable

Weather & News Agent

  • Uses WeatherAPI to fetch local weather data and forecasts
  • Uses SerpAPI to pull news headlines
  • Returns short, summarized updates, for example “Today in Berlin: 18°C and cloudy. Top news: …”

Email Management Agent

  • Uses Gmail nodes in n8n to read, label, reply to, or draft messages
  • Can automate inbox triage, such as labeling newsletters or flagging urgent items
  • Can generate AI-powered draft replies with LLMs based on email content and user instructions

Calendar Agent

  • Works with Google Calendar to create, update, and fetch events
  • Helps with scheduling meetings, checking availability, and sending event summaries
  • Can be combined with the Contacts Agent to invite the right people

Content Creation Agent

  • Performs multi-step content creation for blog posts and long-form writing
  • Uses Perplexity or Tavily for research and source gathering
  • Uses GPT models (for example GPT-4.x or GPT-5-Nano) to draft sections of the content
  • Creates a final document in Google Docs for editing and publishing
  • Calls Replicate to generate a featured image, which can be embedded in the document or HTML

Research Agent

  • Combines Perplexity and Tavily to perform web research
  • Returns concise, source-backed answers or more detailed research summaries
  • Can be used standalone (for user questions) or as a helper for the Content Creation Agent

Social Media Calendar Agent

  • Uses Airtable as a central database of social media content ideas
  • Updates, organizes, and selects ideas for channels like Instagram, LinkedIn, and TikTok
  • Can trigger content generation workflows that turn ideas into ready-to-post drafts

Travel Agent

  • Uses SerpAPI to search for flights and hotels
  • Builds shareable suggestions for trips, including dates, options, and links
  • Can work with the Calendar Agent to propose travel dates that fit your schedule

Contacts Agent

  • Integrates with Google Contacts
  • Looks up email addresses and phone numbers based on names or partial information
  • Supports other agents, for example when scheduling meetings or drafting outreach emails

Key integrations and tools used in the workflow

This n8n personal assistant template connects several APIs and AI tools. Understanding them helps you customize or extend the workflow.

  • OpenAI / GPT-4.x / GPT-5-Nano – for natural language generation, conversation handling, summarization, and drafting content such as emails and blog sections.
  • Perplexity & Tavily – for web research, answering questions with sources, and providing background information to the LLMs.
  • Google APIs (Gmail, Docs, Calendar, Contacts) – for mail management, event scheduling, document creation, and contact lookups.
  • Airtable – as a lightweight database for expenses and social media content ideas.
  • SerpAPI – for news headlines, search results, and travel-related lookups like flights and hotels.
  • WeatherAPI – for weather reports and forecasts.
  • Replicate – for AI image generation, such as featured images for blog posts.
  • Telegram – used as an example chat interface; you can swap this for Slack, email, or a simple web UI by changing the trigger node.

Before you start: prerequisites

To implement this workflow in n8n, you will need:

  • A self-hosted or cloud-hosted n8n instance with persistent storage
  • API keys and credentials for:
    • OpenAI and/or Anthropic (for LLMs)
    • SerpAPI
    • WeatherAPI
    • Replicate
    • Airtable
    • Google OAuth (Gmail, Calendar, Docs, Contacts)
  • Basic familiarity with:
    • n8n nodes and how to connect them
    • Webhook or chat triggers
    • Setting up and using n8n credentials

Step-by-step: building the workflow in n8n

In this section, we will walk through the main steps to assemble the AI personal assistant inside n8n. You can adapt each step to your own environment or use it to understand how the template works under the hood.

Step 1 – Set up the input trigger and orchestrator

  1. Add a trigger node
    Choose how users will talk to your assistant. Common options:
    • Telegram Trigger – for chat-based interaction
    • Webhook Trigger – for web apps, forms, or custom frontends
  2. Create the Orchestrator Agent node or subflow
    This central node should:
    • Receive the raw user message or payload from the trigger
    • Parse the intent (for example “check weather”, “draft email”, “log expense”)
    • Decide which specialized agent to call
    • Optionally use an LLM to classify the request and build a structured internal command
  3. Keep the orchestrator lightweight
    The orchestrator should focus on:
    • Routing requests
    • Combining responses
    • Formatting the final output

    Heavy logic, external calls, and domain-specific rules belong in the individual agents.

Step 2 – Build each agent as a modular subflow

In n8n, it is good practice to implement each agent as its own workflow or sub-workflow. This keeps things clean and reusable.

When creating each agent subflow (for example Calendar, Email, Finance, Content), follow these guidelines:

  • Define a clear input and output
    Decide what data the orchestrator will send in, and what the agent will return. For example:
    • Input: { “action”: “create_event”, “title”: “…”, “start”: “…”, “end”: “…” }
    • Output: { “status”: “success”, “eventId”: “…” }
  • Use n8n credentials for authentication
    Configure:
    • Google OAuth credentials for Gmail, Calendar, Docs, Contacts
    • Airtable API key or personal access token
    • API keys for OpenAI, SerpAPI, WeatherAPI, Replicate, Perplexity, Tavily

    Store them in n8n’s credential store and reference them from nodes instead of hardcoding secrets.

  • Log actions and responses
    Add simple logging with:
    • Function nodes that print key variables
    • n8n’s built-in execution logs

    This makes debugging much easier when something goes wrong in a specific agent.

Step 3 – Add memory and state for conversational flows

To make your assistant feel more like a real personal assistant, you need some form of memory. This allows multi-step interactions where the system remembers context, such as:

  • The last drafted email
  • An in-progress blog post
  • Recent user preferences

In n8n, you can add memory in several ways:

  • Database-based memory
    Use a Postgres node or another database to store:
    • Session IDs
    • Conversation history
    • Partial results (for example sections of a blog post)
  • Buffer or variable-based memory
    For short-term context, you can use:
    • Static data nodes
    • Workflow variables
    • Simple key-value storage

The orchestrator can read and update this memory as it processes each new request, which enables more natural back-and-forth interactions.

Step 4 – Connect research tools and content generation

When the assistant needs to research a topic or create content, it uses a two-step pattern:

  1. Research step
    Call Perplexity or Tavily from a Research or Content agent to:
    • Search the web for the requested topic
    • Collect relevant links, summaries, and citations
    • Prepare structured notes that can be passed to an LLM
  2. Generation step
    Feed the research results into a GPT model to:
    • Draft sections of a blog post
    • Write an email based on the research
    • Answer a question with references

For blog posts, the workflow typically:

  • Generates a title and outline (H2/H3 headings)
  • Writes each section based on the research
  • Calls Replicate to generate a featured image
  • Creates a Google Doc with the final HTML or formatted content

Example walkthrough: publishing a blog post with the assistant

To see how the pieces fit together, let us walk through a concrete example that this workflow template supports: “Write and publish a blog post.”

  1. User triggers the blog workflow
    The user sends a message such as “Write a blog post about remote work productivity” via Telegram or submits a web form. The trigger node passes this request to the Orchestrator Agent.
  2. Orchestrator calls a Titles & Structure tool
    The orchestrator forwards the request to the Content Creation Agent, which:
    • Calls a Titles & Structure tool backed by Perplexity or similar research
    • Proposes a title and a H2/H3 outline for the article

    The user can review and approve or adjust this structure.

  3. Sections are drafted with research and GPT
    Once the outline is approved:
    • A “Write Section” tool takes each H2 (and possibly H3) heading
    • It combines prior research results with a GPT model to draft that section
    • This process repeats for every section until the full article is written
  4. Generate a featured image
    The workflow calls Replicate with a prompt describing the blog topic. Replicate returns a generated image URL. The workflow then:
    • Inserts the image above the first H2 in the HTML or document
    • Optionally

Build a Telegram Voice AI Agent with n8n

Build a Telegram Voice AI Agent with n8n

This guide walks you through an n8n workflow template that turns Telegram voice messages into intelligent spoken replies. You will learn how the workflow captures voice notes, transcribes them with OpenAI, processes them with an AI agent that has memory, converts the reply to speech with ElevenLabs, and sends the audio response back to the user on Telegram.

What you will learn

By the end of this tutorial, you will be able to:

  • Set up a Telegram bot and connect it to n8n
  • Configure an n8n workflow that listens for Telegram messages
  • Transcribe Telegram voice messages to text using OpenAI
  • Use an AI agent with memory to generate context-aware replies
  • Convert AI replies to natural-sounding audio with ElevenLabs
  • Send the generated audio back to Telegram as a voice reply

Why build a Telegram voice AI agent?

Voice-first interfaces are increasingly popular for:

  • Hands-free interactions
  • Accessibility and assistive experiences
  • More natural, conversational user interfaces

This n8n template is ideal if you want to create a Telegram voice assistant that can:

  • Transcribe voice messages into text
  • Generate replies using a language model with short-term memory
  • Convert replies back into high-quality speech
  • Return the audio response directly in the Telegram chat

Concept overview: how the workflow works

Main building blocks

The workflow is built from several n8n nodes that work together in sequence:

  • Telegram Trigger – Listens for incoming Telegram messages
  • Switch – Detects if the message is voice or text and routes accordingly
  • Telegram (get file) – Downloads the voice file from Telegram
  • OpenAI (Transcribe) – Converts the audio file into text
  • Set / Edit fields – Normalizes text so it is ready for the AI agent
  • Merge – Combines different text inputs into a single message
  • AI Agent – Uses an OpenAI chat model with memory and rules to generate a reply
  • HTTP Request (ElevenLabs) – Sends the reply text to ElevenLabs for text-to-speech
  • Telegram (sendAudio) – Sends the generated audio back to the user

High-level flow

  1. The Telegram Trigger node receives a new message.
  2. The Switch node checks if the message contains a voice note.
  3. If it is a voice note, the file is downloaded and transcribed to text.
  4. If it is text, it can be passed directly to the AI agent.
  5. The AI agent uses a language model plus memory to generate a response.
  6. The response text is sent to ElevenLabs, which returns an audio file.
  7. The audio file is sent back to the user via Telegram as an audio message.

Step-by-step setup in n8n

Step 1: Prepare your accounts and keys

  1. Create a Telegram bot
    Use @BotFather in Telegram to create a new bot and get your bot token.
  2. Set up n8n
    Install n8n and make sure your instance can receive webhooks. This usually means:
    • Using a public URL, or
    • Using a tunnel tool like ngrok during development
  3. Get an OpenAI API key
    You will use this key for:
    • Audio transcription (Whisper-based)
    • Chat completion with the language model
  4. Get an ElevenLabs API key
    This will be used in the HTTP Request node for text-to-speech (TTS).

Step 2: Configure credentials in n8n

  1. Telegram credentials
    In n8n, create a Telegram credential and paste your bot token from BotFather.
  2. OpenAI credentials
    Add a new OpenAI credential in n8n and insert your OpenAI API key. This will be referenced by:
    • The transcription node
    • The AI agent node (chat model)
  3. ElevenLabs credentials
    In the HTTP Request node that calls ElevenLabs, set the required headers, typically:
    • xi-api-key: <your_elevenlabs_api_key>
    • Content type and other headers, depending on the ElevenLabs API version you use

Step 3: Import and connect the workflow template

  1. Download or copy the provided workflow JSON for the Telegram Voice Chat AI Agent.
  2. In n8n, go to Workflows and import the JSON template.
  3. Open the workflow and update credential references:
    • Point Telegram nodes to your Telegram credential
    • Point OpenAI nodes to your OpenAI credential
    • Configure the HTTP Request node to use your ElevenLabs API key

Step 4: Configure Telegram Trigger and routing

Telegram Trigger node

The Telegram Trigger node listens for incoming updates from Telegram. You can configure it to listen to:

  • Private chats
  • Group chats (if your use case requires it)

Check your bot’s privacy settings in BotFather. For group chats, you may need to allow the bot to receive all messages, not just those that mention it.

Switch node

The Switch node decides whether the incoming message is a voice message or text. It typically checks if message.voice exists in the incoming data.

  • If message.voice exists, the message is routed to the voice processing branch.
  • If it does not exist, the message can be treated as plain text and sent directly to the AI agent or handled with different logic.

Step 5: Handle voice messages – download and transcribe

Telegram (get file) node

For voice messages, the Telegram (get file) node:

  • Uses the file ID from the message
  • Downloads the voice note, usually as an OGG/Opus file

OpenAI (Transcribe) node

The OpenAI Transcribe node then sends this audio file to OpenAI’s transcription endpoint (Whisper-based). It returns:

  • Text content that represents what the user said

This transcription becomes the text input that will be passed to the AI agent.

Step 6: Normalize text and merge inputs

Set / Edit fields node

The Set or Edit fields node is used to clean up or standardize the text payload. Typical uses include:

  • Renaming fields so the AI agent always receives text in a consistent property
  • Removing unnecessary metadata
  • Adding any extra context you want the agent to see

Merge node

The Merge node combines different types of input into a single structure. In this template it is used to:

  • Merge text that came from transcription (voice messages)
  • Merge text that came directly from the Telegram message (text messages)

The result is a unified message object that the AI agent can process regardless of the original format.

Step 7: Configure the AI Agent, language model, and memory

AI Agent node

The AI Agent node is at the core of this workflow. It receives the final text prompt and is configured with:

  • Language model: An OpenAI chat model, for example gpt-4o-mini in the template.
  • Memory: A windowed buffer memory that keeps the last N messages for short-term context.
  • System message (rules): Instructions that control how the agent should respond.

In the template, the system message includes rules such as:

  • Return plain text only
  • Avoid special characters that might break formatting
  • Do not include explicit line breaks in the JSON field

You can adjust these rules to fit your use case, for example:

  • Making responses shorter or more detailed
  • Giving the agent a specific persona
  • Structuring output for downstream tools

Step 8: Convert the agent reply to audio with ElevenLabs

HTTP Request (ElevenLabs) node

Once the AI agent generates a text reply, that text is sent to ElevenLabs using an HTTP Request node. This node typically includes:

  • The reply text in the request body
  • A model_id such as eleven_multilingual_v2 to choose the TTS model
  • The required headers with your ElevenLabs API key

ElevenLabs returns an audio binary, which represents the spoken version of the AI agent’s reply. This binary data will then be passed to the Telegram sendAudio node.

Step 9: Send the audio reply back to Telegram

Telegram (sendAudio) node

The final step uses the Telegram (sendAudio) node to send the generated audio file back to the original chat. Make sure that:

  • The node is configured to send binary data from the previous HTTP Request node
  • The correct chat ID from the original Telegram message is used

Once configured, the user will receive an audio message that sounds like a natural spoken reply to their original voice note or text.

Step 10: Test the complete flow

  1. Activate the workflow in n8n.
  2. Send a voice message to your Telegram bot.
  3. Watch the execution in n8n as it goes through:
    • Telegram Trigger
    • Switch
    • File download
    • Transcription
    • AI Agent
    • ElevenLabs TTS
    • Telegram sendAudio
  4. Confirm that you receive an audio reply in Telegram.

Security, reliability, and best practices

Protect your API keys

  • Do not hardcode or share API keys in public templates or screenshots.
  • Always store keys in n8n credentials, not in plain text fields.

Rate limits and performance

  • OpenAI and ElevenLabs both enforce rate limits.
  • For production, consider adding retry logic or throttling if you expect high traffic.

Privacy considerations

  • Inform users that their voice data is processed by external services.
  • Use encryption in transit and, where possible, at rest.
  • Be careful about how long you store transcriptions or audio files.

Input sanitization and safety

  • If you use transcriptions for further automation, sanitize or validate inputs.
  • Guard against prompt injection and malicious content when passing user text to the AI agent.

Error handling

  • Add error branches or catch nodes in n8n to handle failures gracefully.
  • Provide user-friendly fallback messages, for example: “I’m having trouble generating an audio reply right now.”

Ways to customize your voice AI agent

  • Voice style: Change the TTS voice, pitch, or speed in ElevenLabs to match your brand or persona.
  • Agent behavior: Modify the system prompt to:
    • Give the agent a personality
    • Make responses more concise or more detailed
    • Turn it into a coach, tutor, or assistant for a specific domain
  • Memory configuration: Adjust the window size of the buffer memory or connect the agent to a database for longer-term memory across sessions.
  • Additional tools: Integrate extra tools into the agent, such as:
    • Calendar APIs
    • Knowledge bases or documentation
    • Web search for up-to-date information
  • Audio formats: Extend the workflow to support more audio formats or add a normalization step if users upload non-OGG recordings.

Troubleshooting guide

  • Poor transcription quality:
    • Encourage clearer audio or use better microphones.
    • Check if you can enable or adjust model-specific options in the transcription node.
  • No audio returned to Telegram:
    • Verify that the HTTP Request node is returning a valid audio binary.
    • Make sure the Telegram sendAudio node is configured to read binary data from the correct property.
  • Unexpected behavior in the workflow:
    • Inspect node input and output in the n8n execution logs.
    • Check the Switch conditions and Merge configuration to confirm that data flows as expected.

Example use cases

  • Personal voice assistant on Telegram that answers questions and performs quick tasks.
  • Voice-based customer support prototype that handles common queries and forwards complex issues to humans.
  • Language-learning bot that responds in natural speech and can help with pronunciation or practice.
  • Accessibility assistant for visually impaired users who prefer voice over text.

Recap

This n8n template combines three powerful components:

  • Telegram for messaging and voice input
  • OpenAI for speech-to-text and intelligent chat responses
  • ElevenLabs for high-quality text-to-speech output

Together, they create a fully automated voice AI agent on Telegram that can listen, understand, think, and speak back to the user.

To get started, import the template into your n8n instance, connect your Telegram, OpenAI, and ElevenLabs credentials, and send a test voice message to your bot.

Quick FAQ

Do I need to write code to use this template?

No. The workflow is built using n8n’s visual editor. You mainly need to configure nodes, credentials, and prompts.

Can I use a different OpenAI model?

Yes. The template uses <

Automate Lead Gen & Enrichment with n8n

Automate Lead Generation & Enrichment with n8n: A Friendly, End-to-End Guide

Imagine kicking off a whole lead generation pipeline from a quick Telegram message, then coming back later to a neatly scored, enriched, and campaign-ready list of prospects. That is exactly what this n8n workflow template does for you.

If you run B2B outreach, outbound sales, or SDR operations, this template ties together Telegram, Apify (Apollo scraper), Perplexity and other LLMs, Google Sheets, and Smartlead – all orchestrated inside n8n – so you can move from “who should we contact?” to “we are ready to hit send” with minimal manual work.

What this n8n lead gen template actually does

This “Lead Gen and Enrichment” template is an end-to-end automation that:

  • Scrapes leads from Apollo (via Apify) based on simple inputs like industry and location.
  • Filters and scores those leads so you can focus on the ones that really matter.
  • Enriches each contact with quick research and a personalized icebreaker using LLMs.
  • Stores everything neatly in Google Sheets for tracking and collaboration.
  • Pushes the final list into Smartlead (or a similar tool) so they are ready for a cold outreach sequence.
  • Notifies you on Telegram when the job is done, including how many leads were found.

In other words, it turns a casual Telegram message into a fully prepared cold outreach list.

Why bother automating lead generation and enrichment?

Doing all of this by hand gets old fast. Manual prospecting is:

  • Slow and repetitive.
  • Easy to mess up with copy-paste errors.
  • Hard to scale beyond a handful of SDRs and spreadsheets.

With an automated n8n workflow, you can instead:

  • Collect large volumes of prospect data quickly, including emails, job titles, and company info.
  • Enrich profiles with firmographic data and personalized insights so your outreach does not feel generic.
  • Score and prioritize leads so your SDRs spend time on higher-value prospects.
  • Push qualified leads consistently into your outreach tool or CRM without manual imports.

If your team is stuck in spreadsheet hell, this template is designed to pull you out of it.

Core building blocks inside the template

Here is a quick tour of the main components the workflow stitches together:

  • Telegram Trigger – Starts the workflow when you send a message containing industry and location.
  • Information Extractor (LLM node) – Parses that message and pulls out structured values like company_type and location.
  • Apify Apollo Scraper – Calls an Apify act that scrapes Apollo (or a similar dataset) for people matching your filters.
  • Wait & Apify Check Status – Polls Apify until the scraping run is done, then fetches the dataset.
  • Filtering and Lead Scoring (Code node) – Removes entries without emails and assigns a lead score based on seniority, company size, LinkedIn and website presence.
  • Google Sheets – Appends the qualified, scored leads to a spreadsheet.
  • Perplexity + LLM Chain – Generates short prospect insights and a 200-character icebreaker for personalization.
  • Smartlead HTTP Request – Sends the enriched leads and icebreakers into a Smartlead campaign via API.
  • Telegram Notification – Sends a summary back to your Telegram chat with the final counts and key details.

Now let’s walk through how it all flows together in practice.

How the n8n workflow runs, step by step

1. Start everything with a Telegram message

You begin inside Telegram. You send a message like:

“Find SaaS companies in Berlin with marketing leaders”

The Telegram Trigger node receives this message and passes the text straight into the next step, the Information Extractor. No forms, no UI, just a quick chat message.

2. Extract structured search parameters with an LLM

The Information Extractor node uses an LLM to turn your free-form text into clean, structured fields. It pulls out three key attributes:

  • company_type – for example, “SaaS”, “agency”, “ecommerce”.
  • location – URL-encoded so it works nicely with Apify / Apollo filters.
  • Location_Proper – a human-readable version of the location for summaries and logs.

These values are then used to build the request payload for Apify.

3. Launch the Apify Apollo scraper

Next, the Apify Apollo Scraper node kicks off an Apify act. It sends a JSON body to Apify that includes filters such as:

  • personTitles – for example, “Head of Marketing”, “VP Sales”.
  • location – based on the LLM-extracted and URL-encoded location.
  • Organization keywords related to your company_type.

Your Apify API key and act ID are configured in the node credentials, so the workflow can securely launch the scraping task.

4. Wait for the scrape to finish, then pull the dataset

Scraping takes time, so the template uses a small loop to handle this gracefully:

  • A Wait node pauses the workflow for a bit.
  • An Apify Check Status node checks whether the run has finished successfully.

This repeats until the Apify run status is “succeeded”. Once it is done, the workflow calls Apify Get Dataset to retrieve all the scraped records.

5. Filter, score, and write leads to Google Sheets

Now the raw data comes in and the template starts cleaning it up:

  • Entries without emails are filtered out so you are not wasting time on unusable contacts.
  • A Code node calculates a Lead Score for each contact. The score can factor in:
    • Title seniority.
    • Company employee count.
    • Presence of a LinkedIn profile.
    • Presence of a company website.
  • Scores are capped at 100 to keep them consistent and easy to compare.

Once the scoring is done, qualified rows are appended to your Google Sheets spreadsheet. This sheet becomes your central record for all enriched leads and is also used for downstream steps.

6. Enrich leads with personalized insights and icebreakers

After the basic data is stored, the template loops through those rows and upgrades them with personalization:

  • Each lead is sent to Perplexity or another LLM to gather quick research and context.
  • An LLM Chain node then distills that research into a short, roughly 200-character icebreaker.

This icebreaker is designed to be used directly in your cold outreach, for example as the first line of an email. You get scalable personalization without writing every opener by hand.

7. Push everything into Smartlead for outreach

Once leads are enriched and scored, the workflow is ready to seed your campaign. A Smartlead HTTP Request node:

  • POSTs the leads into a Smartlead campaign via API.
  • Includes the generated icebreaker as a custom field so your templates can reference it.

From there, Smartlead (or your chosen outbound tool) can enroll those contacts into a cold email sequence with personalization already baked in.

8. Get a friendly summary back in Telegram

To close the loop, a Telegram Notification node sends a message back to the original chat. It typically includes:

  • How many leads were scraped and qualified.
  • The industry or company type.
  • The target location.

You get a quick status update without needing to log into n8n or Apify to check on things.

What you need before using the template

Before you hit “execute workflow”, make sure you have this checklist covered:

  • n8n instance – Cloud or self-hosted, with enough runtime allowed for long-running workflows.
  • Telegram Bot token and chat ID – So the workflow can receive triggers and send notifications.
  • Apify account – With a valid act ID for the Apollo scraper and your API key set in the node credentials.
  • LLM credentials – OpenAI or another LLM provider for information extraction, plus Perplexity or your chosen insight API key for enrichment.
  • Google Sheets OAuth credentials – To append and update your lead spreadsheet securely.
  • Smartlead (or similar) API key – For importing leads into your outbound campaign tool.

Best practices to get the most from this automation

Keep an eye on costs and rate limits

APIs like Apify, Perplexity, and LLM providers can get pricey if you go all-in on huge batches from day one. A safer approach is to:

  • Start with smaller batches, for example 100-300 records.
  • Gradually increase volume once you are happy with the quality.
  • Use exponential backoff and respect API rate limits to avoid throttling or errors.

Focus on quality, not just volume

It is tempting to pull as many leads as possible, but your team will thank you for relevance instead. Some ideas:

  • Add stricter filters early, like requiring work emails or specific seniority levels.
  • Use lead scoring thresholds to auto-tag or route top-tier leads.
  • Experiment with filters until your reply rates and meeting rates look healthy.

Make personalization work for you

The LLM-generated insights and icebreakers are powerful, but they are not magic. To get the best results:

  • Manually review a sample of outputs before scaling to large lists.
  • A/B test different tones and styles of icebreakers.
  • Track reply rates and iterate on the prompts feeding your LLM nodes.

Stay on top of deduplication and data hygiene

Nothing kills a campaign faster than sending multiple emails to the same person. To avoid that:

  • Deduplicate by email before adding rows to Google Sheets or pushing into Smartlead.
  • Consider using hashes or a shared blocklist across campaigns.
  • Regularly clean outdated or bounced contacts from your sheet and tools.

Common issues and how to fix them

  • No dataset returned from Apify
    Check the Apify run logs, verify the actId, and make sure your search parameters are valid and correctly URL-encoded.
  • Too many empty emails
    Adjust your Apify configuration to prioritize work or personal emails, and refine the personTitles filter to target roles more likely to have contact data.
  • 401 / unauthorized errors
    Re-check API keys and token scopes for Apify, Google, Perplexity, Smartlead, and any LLM provider you are using. Expired or incorrect credentials are usually the culprit.
  • Workflow timeouts in n8n
    Use the Wait + Check Status pattern (already built into the template), increase your n8n workflow timeout if needed, or break the process into smaller chained workflows.

Security and compliance considerations

Since this workflow handles personal contact data, it is important to stay compliant:

  • Follow relevant regulations like GDPR and CCPA in your region.
  • Store API keys and tokens securely using n8n credentials, not in plain text.
  • Avoid logging sensitive data fields in n8n where possible.
  • Provide an opt-out mechanism and honor unsubscribe or suppression lists in your outreach tool.

Ideas for extending and customizing the template

The template is meant to be a strong starting point, not a rigid system. You can easily adapt it to your stack:

  • Swap the data source – Replace the Apify Apollo Scraper with LinkedIn Sales Navigator, ZoomInfo, Clearbit, or another provider by modifying the HTTP request nodes.
  • Change the outbound tool – Instead of Smartlead, connect HubSpot, Outreach, Lemlist, or your CRM by updating the API endpoint and request body.
  • Add deeper enrichment – Pull in technographics, funding rounds, or recent news via extra API calls to further refine your lead scoring.
  • Use different triggers – Start the workflow from a web form, Zapier, Notion, or other tools instead of Telegram if that fits your process better.

Sample lead scoring logic and how to improve it

Inside the JavaScript Code node, the template uses a straightforward scoring approach. It is a great baseline, but you can enhance it by including factors like:

  • Industry fit and how closely it matches your ICP.
  • Recent funding or company growth signals.
  • Engagement signals such as LinkedIn activity or content sharing.
  • Manual override flags from SDRs for hot or disqualified leads.

Over time, you can tune the weights in that scoring logic to better reflect what a “high-intent” lead looks like for your team.

Putting it all together

This n8n template gives you a complete, practical pipeline for B2B lead generation, enrichment, scoring, and campaign seeding. It cuts down manual work, keeps your data organized, and lets you scale personalization without burning out your team.

Want to try it in your own environment?

  • Import the template into your n8n instance.
  • Plug in your API keys and credentials.
  • Run a small test batch to validate lead quality, scoring, and personalization.

If you would like help tailoring the workflow to your stack, adding deduplication logic, or syncing to your CRM, you can always book a quick implementation session and get hands-on guidance.

Spin up this template in n8n today and unlock scalable, personalized B2B outreach with far less manual effort.

Need a walkthrough or a ready-to-import template export? Reach out and we will help you get set up and tuned for best results.

Automate Invoice Processing with n8n & Airtable

Automate Invoice Processing with n8n & Airtable

Every invoice that lands in your inbox is a tiny distraction. Downloading, checking, typing amounts into a spreadsheet or accounting tool, chasing missing data – it all adds up and quietly steals time from the work that actually moves your business forward.

What if every new invoice could glide into your system automatically, neatly structured and ready to reconcile, while you stay focused on strategy, clients, or growth?

This is exactly what the “Invoice Categorizer” n8n template helps you do. By combining n8n, Telegram, OpenAI (via a LangChain agent), and Airtable, you can turn messy, manual invoice handling into a calm, predictable, and scalable workflow.

In this guide, you will walk through that transformation step by step. You will see how each node works, how the data is formatted, and how to adapt the template to your own stack. Most importantly, you will see how this workflow can be a starting point for automating much more of your financial operations.

The pain of manual invoices and the opportunity behind it

Manual invoice processing is not just tedious, it is a growth bottleneck. Every minute you or your team spend on repetitive data entry is a minute not spent on higher value work.

Typical manual workflows:

  • Download invoices from email or portals
  • Open each PDF and scan for totals, dates, and suppliers
  • Re-type amounts into a spreadsheet or accounting tool
  • Try to keep a record that is searchable and auditable
  • Chase team members or vendors for missing information

It is slow, error-prone, and expensive. Yet, it is also one of the best places to start automating because the process is structured, repetitive, and high volume.

By automating invoice processing with n8n you can:

  • Reduce manual data entry and errors so your numbers are more reliable.
  • Speed up vendor reconciliation and approvals, which improves relationships and cash flow.
  • Keep a searchable, auditable record in Airtable that your team can trust.
  • Enable remote invoice submission via Telegram, so vendors or teammates can send invoices from anywhere.

Instead of being stuck in “invoice admin mode,” you move into a mindset where automation quietly handles the routine, and you focus on decisions, strategy, and growth.

From possibility to practice: what this n8n template actually does

The “Invoice Categorizer” template is a complete, ready-to-use pipeline. It starts when someone sends a PDF invoice to your Telegram bot and ends with structured records in Airtable plus a confirmation message back to the user.

At a high level, the workflow:

  • Receives a PDF invoice via Telegram
  • Validates that the uploaded file is a PDF
  • Downloads the file and runs OCR/text extraction
  • Sends the extracted text to an AI Agent (LangChain + OpenAI)
  • The AI agent parses invoice fields and line items
  • Creates a structured Invoice record in Airtable
  • Creates linked Line Item records in Airtable
  • Sends a confirmation message via Telegram to close the loop

This is not just a demo. With the right credentials and a few tweaks, you can have a production-ready invoice automation pipeline in minutes, and then extend it as your needs grow.

Core building blocks of the workflow

Before diving into the journey step by step, it helps to know the main components you are working with. These are the “lego bricks” you can later rearrange or expand.

Key n8n nodes and services

  • Telegram Trigger: Listens for new messages and files sent to your Telegram bot.
  • Switch node: Validates the file MIME type and ensures only PDFs continue through the workflow.
  • Telegram file download: Downloads the invoice PDF using its file_id.
  • Extract from File (pdf): Runs text extraction or OCR on the PDF to obtain raw text.
  • Set / Edit Fields: Combines extracted text with user-provided details and prepares the prompt for the AI agent.
  • AI Agent (LangChain + OpenAI): Parses invoice-level fields and line items, and calls Airtable tools based on a carefully designed system prompt.
  • Airtable “Create Invoice”: Creates a new invoice record and returns the Airtable record ID.
  • Airtable “Create Line Item”: Creates one record per line item and links each item to the parent invoice using the record ID.
  • Telegram sendMessage: Sends success or failure messages back to the user.

Each of these nodes is already wired together in the template. Your job is to understand them, configure your own credentials, and then adapt the structure to your own business logic.

Critical data rules that keep your automation stable

Automation is only as strong as the data that flows through it. The template includes strict formatting rules so that Airtable receives clean, predictable values. Respecting these rules will save you from subtle bugs later.

  • Numeric fields:
    • Total_Tax and Total_Amount must be numbers only.
    • Remove currency symbols.
    • Remove or normalize commas so they do not break number parsing.
  • Invoice_linked field (for line items):
    • When creating line items in Airtable, the Invoice (linked) field must be passed as a JSON array string containing the invoice record ID.
    • Example: ["rec123abc"].
    • This is essential for Airtable relationships to work correctly.
  • Date fields:
    • Use YYYY-MM-DD format for all dates.
    • Example: 2025-09-01.
  • Missing values:
    • If a field is missing from the invoice, set its value to "MISSING".
    • This prevents downstream automations from failing due to null or undefined values.
  • Line items:
    • Ignore items with zero quantity.
    • For each valid line item, extract:
      • Product code
      • Description
      • Unit price
      • Quantity
      • Unit type
      • Sub total

Think of these rules as the guardrails that keep your automation reliable as you scale it and feed it more invoices from different suppliers.

Your automation journey, step by step

Now let us walk through the workflow in the same order your invoices will follow. As you read, imagine how each piece could be adapted, improved, or reused for other document flows in your business.

1. Telegram Trigger – inviting invoices into your system

Your journey starts in Telegram. Configure your bot token in n8n and set the Telegram Trigger node to fire on new messages.

The template:

  • Captures the chat id so you can maintain session context.
  • Prompts the user for the company or client name if needed.
  • Then asks the user to upload the PDF invoice.

This simple interaction turns Telegram into a friendly intake portal for invoices, especially useful for distributed teams or vendors who are always on the go.

2. Switch node – validating that the file is a PDF

Next, the workflow needs to make sure it is processing the right kind of file. The Switch node checks the MIME type at $json.message.document.mime_type and confirms that it equals application/pdf.

If the file is not a PDF, you can:

  • Route it to a fallback path.
  • Send a Telegram message asking the user to upload a valid PDF.

This small check prevents the rest of the workflow from failing and keeps the experience smooth for your users.

3. Downloading the file and extracting text

Once the file is confirmed as a PDF, the template uses the Telegram (get file) node to download it by file_id. The downloaded file is then passed directly into the Extract from File (pdf) node.

In the Extract from File node you can:

  • Run text extraction on digital PDFs.
  • Enable OCR for scanned invoices.
  • Adjust language and OCR settings to improve accuracy for your specific documents.

The output of this step is the raw text of the invoice, which then becomes the raw material for the AI agent to work with.

4. Set / Edit Fields – preparing the AI prompt

The Set / Edit Fields node is where you shape the data into a clear instruction for the AI agent.

This node:

  • Combines the extracted text with any user-provided client name.
  • Builds a single prompt string that gives the agent all the context it needs.
  • Stores the Telegram chat id as a session key so you can send follow-up messages or confirmations.

Spending a bit of time refining this prompt can significantly improve extraction quality, so treat it as a powerful tuning lever rather than a static piece of configuration.

5. AI Agent (LangChain + OpenAI) – turning text into structured data

Now the magic happens. The AI Agent node uses LangChain and OpenAI to interpret the invoice text, extract the right fields, and interact with Airtable through tools defined in the system prompt.

The system message given to the agent encodes several important behaviors:

  • Request missing context: If the client or company name was not provided earlier, the agent is instructed to ask for it.
  • Extract invoice-level fields: It must return values in the exact formats required by Airtable:
    • Numbers only for numeric fields like Total_Tax and Total_Amount.
    • Dates in YYYY-MM-DD format.
    • "MISSING" for fields that are not present on the invoice.
  • Create the Invoice record: The agent calls the Create Invoice Airtable tool and stores the returned record ID.
  • Create linked line items: For each non-zero quantity item, the agent:
    • Creates a line item record.
    • Passes the invoice record ID in a JSON array string for the Invoice_linked field, for example ["recAbC123"].

You can configure the OpenAI model according to your needs:

  • Use gpt-4o or gpt-4 for higher accuracy.
  • Use gpt-3.5 for lower cost or less complex invoices.

The template expects the AI Agent to use the same OpenAI API key that you have configured in the OpenAI node. With a few tweaks, you can strike the right balance between accuracy and cost for your use case.

6. Airtable: Create Invoice and Create Line Item – building your structured record

After the AI agent finishes its work, the workflow uses two Airtable nodes to persist the data:

  • Create Invoice:
    • Configured with your Airtable base ID and the invoice table ID.
    • Maps extracted fields like invoice number, dates, supplier, tax, and totals into the right columns.
    • Returns the record ID (for example recAbC123), which is crucial for linking line items.
  • Create Line Item:
    • Also configured with your base and table IDs.
    • Creates one record per line item.
    • Uses the invoice record ID in the Invoice_linked field as a JSON array string, for example ["recAbC123"].

The template is already set up to use numeric types for tax and total amount in Airtable, so as long as you follow the formatting rules, the records will slot in cleanly.

7. Telegram confirmation – closing the loop with your users

Finally, the workflow uses Telegram sendMessage to confirm success or failure back to the user.

This small step makes your automation feel trustworthy and transparent. Users send an invoice, receive a confirmation, and quickly learn that the system “just works” in the background.

Testing, learning, and improving your workflow

Every automation improves with feedback and iteration. Start small, observe how the workflow behaves, and then refine.

  • Begin with a single sample PDF: Upload it via Telegram and inspect the raw text output from the Extract from File node.
  • Enable temporary debug output: Log the structured JSON returned by the AI agent so you can see exactly what it is extracting.
  • Validate Airtable mappings: Before enabling real record creation, have the agent produce a JSON payload that you can paste into the Airtable API explorer as a dry run.
  • Watch for common issues:
    • OCR misreads, especially on dates and numbers.
    • Currency symbols left in numeric fields.
    • Incorrect date formats that do not match YYYY-MM-DD.

Each test invoice is a chance to tune prompts, fix mappings, and strengthen the workflow. Over time, your pipeline becomes more resilient and accurate, and you gain the confidence to feed it higher volumes of invoices.

Security and compliance as you scale automation

As you automate more of your financial operations, security and compliance become even more important. The template is flexible enough to support best practices without adding friction.

  • Protect credentials:
    • Store your Telegram bot token, OpenAI key, and Airtable tokens in n8n credentials.
    • Never hard-code secrets directly inside nodes.
  • Handle sensitive data carefully:
    • If invoices contain P

Build a Confluence Page AI Chatbot with n8n

Build a Confluence Page AI Chatbot with n8n

This guide walks you through how to build an AI chatbot that can answer questions using your Confluence pages as the source of truth. You will learn how to connect Atlassian Confluence, n8n, and an LLM such as OpenAI, then turn page content into Markdown that an AI model can understand and respond to accurately.

What you will learn

By the end of this tutorial, you will know how to:

  • Connect Confluence Cloud to n8n using API tokens
  • Search for and retrieve Confluence page content via the REST API
  • Convert Confluence storage format (HTML-like) into clean Markdown
  • Feed that Markdown to an AI model (OpenAI, LangChain) as context
  • Return accurate answers to users through a chat interface such as Telegram
  • Apply best practices for security, scaling, and troubleshooting

Why build a Confluence chatbot?

Confluence is often the central place for internal documentation, but it can be slow for teammates to find what they need. An AI chatbot on top of Confluence can:

  • Provide faster access to documentation through natural language questions
  • Deliver context-aware answers based on actual Confluence page content
  • Integrate with chat tools such as Telegram, Slack, or your internal web chat

Instead of searching manually and scanning long pages, users can ask questions like, “How do we deploy to staging?” and receive concise answers directly pulled from your Confluence pages.

How the n8n Confluence chatbot works

At a high level, n8n orchestrates all the steps between the user, Confluence, and the AI model. The typical flow looks like this:

  • A user sends a chat message (trigger node or webhook)
  • n8n determines which Confluence page to use (by ID or search)
  • Confluence REST API returns the page body in storage format
  • n8n converts that HTML-like storage format into Markdown
  • The Markdown plus the user’s question are passed to an LLM node
  • The AI model generates an answer based only on the provided context
  • n8n sends the answer back to the user in their chat app

Prerequisites

Before you start, make sure you have:

  • An Atlassian account with access to Confluence Cloud
  • An Atlassian API token
    Generate at: https://id.atlassian.com/manage-profile/security/api-tokens
  • An n8n instance (cloud or self-hosted)
  • An OpenAI API key or another LLM provider configured in n8n
  • Basic familiarity with HTTP APIs and Confluence REST API concepts

Step-by-step: Building the Confluence AI chatbot in n8n

Step 1 – Create your Atlassian API token and configure authentication

First, you need an API token that n8n will use to authenticate with Confluence.

1.1 Create an Atlassian API token

  1. Go to Atlassian API tokens.
  2. Create a new token and copy it. Treat it like a password.

1.2 Build the Basic Auth header

Confluence Cloud uses Basic authentication with your email and the API token. Combine them as email:api_token, then Base64 encode the string.

# Linux / macOS
echo -n "your_email@domain.com:your_api_token" | base64

# PowerShell (Windows)
$Text = 'your_email@domain.com:your_api_token'
$Bytes = [System.Text.Encoding]::UTF8.GetBytes($Text)
[Convert]::ToBase64String($Bytes)

Use the resulting string in the HTTP Authorization header:

Authorization: Basic <base64-string>

1.3 Store credentials securely in n8n

In n8n, create a credential (for example, HTTP Header Auth) that stores this Authorization header value. This keeps your token out of workflow code and helps prevent accidental leaks.


Step 2 – Search and retrieve Confluence page content

Next, you need a way to fetch the right Confluence page based on the user’s request. There are two main parts:

  1. Find the page ID (using search or a known ID)
  2. Retrieve the page body in storage format

2.1 Search for a page by ID or CQL

If you already know the page ID, you can search by ID directly. Otherwise, you can use Confluence Query Language (CQL) to search by title, space, or other properties.

Example request to search by ID:

GET https://your-domain.atlassian.net/wiki/rest/api/search?limit=1&cql=id=491546
Headers:  Authorization: Basic <encoded_string>  Content-Type: application/json

In n8n, you can implement this with an HTTP Request node using your Confluence credentials. If the response contains multiple results, use a SplitOut or similar node to handle the array and pick the first matching page.

2.2 Fetch the page body in storage format

Once you know the page ID, call the Confluence pages API to get the full page body. You must request the storage format so that the body is returned in a consistent HTML-like structure.

GET https://your-domain.atlassian.net/wiki/api/v2/pages/{id}?body-format=storage
Headers:  Authorization: Basic <encoded_string>  Content-Type: application/json

Key detail: using body-format=storage ensures the content is available under body.storage.value in the JSON response. This field contains the HTML-like representation of the page, including Confluence macros and structure.


Step 3 – Convert Confluence storage HTML to Markdown

LLMs generally work better with clean text or Markdown than with raw HTML. The next step is to convert body.storage.value into Markdown inside n8n.

3.1 Why convert to Markdown?

  • Reduces noise from HTML tags and Confluence-specific markup
  • Makes the context more readable for both you and the model
  • Helps the LLM focus on the actual documentation content

3.2 Perform the conversion in n8n

In your workflow, add a node that converts HTML to Markdown. This can be:

  • An HTML-to-Markdown node (if available)
  • A Code node that uses a conversion library or custom logic

Example of how the input might look conceptually:

// n8n: Markdown node input
{{ $json.body.storage.value }}

// output: Markdown string to pass to the LLM

The result is a Markdown string that you will pass as “context” to your AI model in the next step.


Step 4 – Use an AI model to answer questions from Confluence context

Now that you have the page content in Markdown, you can connect it to an LLM node (for example, OpenAI or a LangChain agent) and instruct the model to answer questions using only that context.

4.1 Designing the prompt

Use a clear prompt that:

  • Tells the model to rely only on the provided context

Example prompt template:

Answer the user's question using only the context below. 
If the answer is not in the context, respond: "I don't know.".

User question: <user question>

Context:
<page markdown>

4.2 Configuring the LLM node in n8n

In n8n you can:

  • Use the OpenAI node directly, passing the prompt and the Markdown as input
  • Use a LangChain agent node if you want tools, chains, or more advanced behavior

If you want a multi-turn conversation, add a memory buffer (for example, window buffer memory) so that previous messages are kept and the chatbot feels more conversational.


Step 5 – Deliver the chatbot response to the user

Once the LLM returns an answer, the final step is to send it back to the user through your preferred channel.

5.1 Example: Telegram chatbot

Using the n8n Telegram node, you can:

  • Trigger the workflow when a new message is received
  • Send the AI-generated answer back to the same chat

5.2 Other delivery channels

You can also integrate with:

  • Slack or Microsoft Teams
  • A custom web chat UI
  • Internal tools connected via webhooks or APIs

The core logic of the workflow stays the same. Only the trigger and response nodes change depending on your chat platform.


Putting it together: Example n8n node sequence

The full workflow in n8n typically includes the following nodes and steps:

  1. Chat Trigger
    Receive a user message (for example, Telegram trigger or webhook).
  2. Map User Request
    Use a Set or Function node to map the user’s question to a specific Confluence page ID or a search query (CQL).
  3. Confluence Search (REST API)
    HTTP Request node calling the search endpoint to find the page.
  4. Split and Extract Page Data
    Use SplitOut or similar to handle arrays, then extract content.id and content._links.webui as needed.
  5. Confluence Page Storage View
    HTTP Request node to /wiki/api/v2/pages/{id}?body-format=storage to get body.storage.value.
  6. HTML to Markdown Conversion
    Convert the storage HTML into clean Markdown.
  7. AI Agent / OpenAI Node
    Send the user question and Markdown context to the model, optionally with window buffer memory for conversation history.
  8. Send Chat Response
    Use Telegram, Slack, or another chat node to send the answer back to the user.

Best practices for n8n Confluence workflows

Use credentials for security

  • Store the Confluence API token in n8n credentials (for example, HTTP Header Auth).
  • Avoid hardcoding tokens directly in nodes or code.

Handle search results safely

  • When Confluence search returns multiple results, use SplitOut to process each item.
  • Pick the best match or the first result as your page_id.

Control context size

  • For very long pages, truncate or chunk the content before sending to the LLM.
  • Sending only the relevant parts reduces token usage and improves answer quality.

Improve answer reliability

  • Always convert HTML to Markdown or plain text to reduce hallucinations.
  • Use a strict prompt that tells the model to rely only on the provided context.

Security and rate limits

Confluence Cloud APIs are subject to rate limits, and your workflow should handle this gracefully.

  • Rate limiting: If you receive HTTP 429 responses, implement retry and backoff logic in n8n.
  • Caching: Cache frequently requested pages so you do not hit the API every time.
  • Secret management: Never commit API tokens to source control. Use n8n’s credentials vault or environment variables to store sensitive keys.

Example cURL request to fetch page storage

If you want to test your Confluence API access outside n8n, you can use cURL:

curl -D- \  -X GET \  -H "Authorization: Basic <your_encoded_string>" \  -H "Content-Type: application/json" \  "https://your-domain.atlassian.net/wiki/api/v2/pages/491546?body-format=storage"

If this request returns a JSON object with body.storage.value, you are ready to connect the same logic inside n8n.


Handling Confluence macros and attachments

Confluence’s storage format can contain macros, attachments, and other advanced elements. Some things to keep in mind:

  • Macros such as draw.io or include macros may not render well when converted directly to Markdown.
  • If your documentation relies heavily on macros, consider preprocessing them server-side or expanding them before conversion.
  • Store attachments separately if needed and make them searchable by metadata. You can then surface links or references in the chatbot’s answers.

Debugging your n8n Confluence chatbot

If the workflow is not behaving as expected, use these checks:

  • Empty page body: If body.storage.value is empty, confirm that:
    • You included body-format=storage in the query.
    • Your API token has permission to view that page.
  • Inspect raw JSON: Use a Set node to expose fields like:
    • content._links.webui (web URL of the page)
    • content.id (page ID)
    • body.storage.value (HTML-like body)
  • Check HTTP responses: Log headers and status codes for failed requests to quickly spot auth issues or 403/404 errors.

Scaling up: chunking and retrieval (RAG)

For a larger documentation base, you may outgrow the simple “single page as context” approach. In that case, consider a retrieval-augmented generation (RAG) pattern:

  • Index your Confluence content (for example, using embeddings and a vector store).
  • When a user asks a question, run a semantic search to find the most relevant chunks.
  • Pass only those chunks as context to the LLM.

This approach keeps token usage under control and often improves answer accuracy across many pages.


Quick recap

To build a Confluence page AI chatbot with n8n you:

  1. Created an Atlassian API token and configured Basic Auth in n8n.
  2. Used the Confluence REST API to search for pages and retrieve page bodies in storage format.
  3. Converted body.storage.value from HTML-like storage to Markdown.
  4. Sent the Markdown plus the user’s question to an AI model with a strict context-based prompt.
  5. Returned the AI’s response to users through Telegram or another chat integration.
  6. Applied security, debugging, and scaling best practices for a robust chatbot.

Build an n8n Travel Agent with LangChain & Pinecone

Build an n8n Travel Agent with LangChain & Pinecone

Imagine having a smart travel agent that never sleeps, remembers every preference, and sends gorgeous itineraries straight to your inbox. That is exactly what the o3 mini Travel Agent template for n8n helps you build.

This workflow combines conversational AI, LangChain-style tools, OpenAI embeddings, Pinecone vector search, and Gmail to turn a simple chat message into a polished, HTML travel plan. In other words, your users tell it where they want to go, and your automation does the rest.

What this n8n Travel Agent actually does

At its core, this template listens for a chat message like:

“Plan a 5-day family trip to Hawaii leaving from New York.”

From there, it:

  • Understands the request using a conversational LLM (via OpenRouter)
  • Searches Pinecone vector stores for matching resorts, flights, and activities
  • Assembles everything into a clear, HTML travel itinerary
  • Sends the final plan to the traveler through Gmail

The whole flow is designed to feel like a human travel agent conversation, but automated and scalable.

Who this template is perfect for

You will get the most value out of this template if you are:

  • A travel startup that wants fast, personalized trip plans without hiring a big support team
  • A travel agency looking to pre-draft itineraries that agents can tweak and approve
  • An automation builder or n8n fan experimenting with AI, vector search, and email workflows

If you want to turn vague trip ideas into structured, ready-to-send itineraries with minimal manual work, this template fits nicely.

How the workflow is structured (high-level view)

Let us walk through the architecture before diving into each node. The workflow is built around a simple but powerful pattern:

  • Trigger: A “When chat message received” webhook kicks things off
  • Language model: OpenRouter Chat Model handles conversation, intent, and final copywriting
  • Memory: Window Buffer Memory keeps short-term context from the ongoing chat
  • Tools: Pinecone-backed vector retrieval for Resorts, Flights, and Activities
  • Embeddings: OpenAI embeddings node turns queries into vectors for semantic search
  • Email delivery: A Gmail node sends the final HTML itinerary to the traveler

All of this is wrapped in a tool-using agent pattern, so the model can “decide” when to call which tool, then stitch everything into one coherent itinerary.

Node-by-node walkthrough of the Travel Agent

1. When chat message received (webhook trigger)

This node is where the conversation starts. It receives the traveler’s message, such as:

“Plan a 5-day family trip to Hawaii leaving from New York.”

The webhook passes the text and any metadata into the rest of the workflow, which then uses that information to plan the trip.

2. OpenRouter Chat Model (the conversational brain)

The OpenRouter Chat Model acts as your main language model. It is responsible for:

  • Understanding constraints like dates, origin, group size, and preferences
  • Extracting structured details from the free-form user request
  • Writing the final text that will appear in the HTML itinerary

You can think of it as the “travel agent personality” that talks to the user and then writes up the final plan.

3. Window Buffer Memory (conversation context)

Travelers rarely get everything right on the first try, right? They will ask for changes, add constraints, or clarify details.

The Window Buffer Memory node stores recent messages so the agent can remember what was said earlier in the same conversation. This helps it:

  • Avoid asking the same questions again and again
  • Respect updated preferences or corrections
  • Keep the conversation feeling natural and continuous

4. Embeddings OpenAI (turning text into vectors)

To match user requests with your travel data, the workflow needs semantic search. That is where the OpenAI embeddings node comes in.

It converts phrases like “family-friendly beachfront resort” into vector embeddings. Those vectors are then used to query Pinecone so the agent can find the best matching resorts, flights, or activities.

5. Pinecone tools for Resorts, Flights, and Activities

The workflow includes three separate Pinecone-backed tools:

  • Resorts tool, pointing to a resorts namespace
  • Flights tool, pointing to a flights namespace
  • Activities tool, pointing to an activities namespace

Each tool runs a vector search over its own namespace, returning the most relevant items based on the user’s preferences.

The agent is set up so that it must call all three tools before it builds the final itinerary. That way, it always has:

  • Somewhere to stay
  • Ways to get there
  • Things to do at the destination

6. Send Itinerary (Gmail node)

Once the agent has pulled all the data and written the itinerary in HTML, the last step is to send it.

The Gmail node handles:

  • Setting the email subject line
  • Using the HTML itinerary as the email body
  • Sending from a verified account via Gmail OAuth2

The result is a clean, formatted itinerary that looks great in the traveler’s inbox.

Step-by-step setup guide

Ready to get this running in your own n8n instance? Here is how to set it up from scratch.

1. Get n8n ready

  1. Install n8n and open the editor UI, or use n8n.cloud if you prefer a hosted version.
  2. Import the o3 mini Travel Agent workflow template into your workspace.

2. Configure your credentials

You will need a few API keys and OAuth credentials. In n8n, set up:

  • OpenRouter API key for the chat model
  • OpenAI API key for generating embeddings
  • Pinecone API key and an index with these namespaces:
    • resorts
    • flights
    • activities
  • Gmail OAuth2 credentials for sending itineraries via email

Make sure all of these are stored in the n8n Credentials section, not hard-coded into nodes.

3. Populate Pinecone with travel data

This is where your travel database comes in. For each of the three namespaces, add metadata documents that represent your offerings.

Each item should include:

  • A short, clear description
  • Relevant tags, for example:
    • family-friendly
    • adventure
    • beachfront
  • Price information, if available
  • Availability windows or date ranges

The better your metadata, the more accurate and useful the itineraries will be.

4. Customize the agent’s system message

Inside the template you will find a system message that guides how the agent behaves. This is your chance to:

  • Match your brand voice and tone
  • Define service rules and constraints
  • Mention operational details like accepted payment types or preferred partners

Adjust this message so the travel agent feels like an extension of your product or agency, not a generic bot.

5. Test, tweak, repeat

  1. Run sample prompts through the workflow.
  2. Inspect the retrieved resorts, flights, and activities for relevance.
  3. Iterate on:
    • The system prompt
    • Tool settings, like number of results
    • The HTML layout of the final itinerary

A few small tweaks here can make a big difference in how “human” and useful the final plan feels.

Example prompt and HTML output

Here is a sample prompt you might send into the workflow:

“Plan a 4-day romantic getaway to Miami for a couple, leaving from Boston, with beach time and a fine-dining night.”

And a simple example of the kind of HTML itinerary the agent might generate and email:

<html>
<body>  <h2>4-Day Miami Romantic Getaway</h2>  <p><strong>Day 1:</strong> Arrival, check-in at Oceanview Resort. Sunset walk on the beach and dinner at Seaside Bistro.</p>  <p><strong>Day 2:</strong> Morning beach time, afternoon spa, evening fine-dining reservation at Luxe Grill.</p>  <p><strong>Day 3:</strong> Boat tour in the morning, art district visit in the afternoon, cocktails at rooftop bar.</p>  <p><strong>Day 4:</strong> Relax, late checkout, recommended airport departure time: 3 hours before flight.</p>
</body>
</html>

In your own setup, you can extend this with images, links, pricing sections, or call-to-action buttons.

Best practices for a smooth travel automation

To keep your n8n travel agent reliable and user-friendly, here are some practical tips.

Keep itineraries focused and realistic

  • Limit retrieval results to the top 3 to 5 items for each category so the itinerary does not become overwhelming
  • Include rest periods and downtime, not just back-to-back activities

Handle data and credentials safely

  • Always sanitize and validate email addresses before sending itineraries
  • Store API keys in n8n credentials, never directly in node parameters
  • Use version control for your workflow JSON so you can roll back after tests

Security & privacy considerations

Travel data is personal by nature, so it is important to treat it with care. A few guidelines:

  • Use secure credential storage in n8n and rotate API keys regularly
  • Mask or redact personally identifiable information in logs and debug outputs
  • Offer an easy way for users to opt out or request deletion of stored preferences
  • Confirm consent before:
    • Sending emails
    • Storing itinerary details long term

Testing checklist before going live

Before you roll this out to users, run through this quick checklist:

  • Make sure the webhook triggers correctly when a test chat message is sent
  • Verify the OpenRouter model extracts structured details like dates and party size
  • Test embeddings to Pinecone searches and confirm the returned items match the prompt
  • Send a test email with the Gmail node and check:
    • HTML renders correctly
    • Links and formatting look good on desktop and mobile

Deployment & scaling tips

Once your travel agent is working nicely in development, you can prepare it for real users.

  • Run n8n in a secure, hosted environment with HTTPS enabled
  • If usage grows, scale n8n horizontally and use a robust database like Postgres for workflow state
  • Upgrade to a Pinecone production plan with enough capacity for your vector queries
  • Monitor OpenAI and OpenRouter usage and set alerts so costs do not surprise you

Why this template makes your life easier

Instead of manually researching options, assembling day-by-day plans, and formatting everything into an email, you get a reusable automation that:

  • Turns a single chat message into a structured trip
  • Uses AI and vector search to pull in relevant travel data
  • Delivers a ready-to-send HTML itinerary automatically

The o3 mini Travel Agent template is a practical and extensible starting point if you want to blend conversational AI, semantic search, and email automation into one user-facing experience.

Next steps

If you are curious how this would work with your own travel data, the best move is to try it:

  • Import the template into your n8n instance
  • Connect your OpenRouter, OpenAI, Pinecone, and Gmail credentials
  • Run a few test prompts and refine the system message and HTML layout

If you want a more tailored walkthrough or help structuring your Pinecone index with resorts, flights, and activities, you can reach out to your team internally or work with a specialist and keep iterating. Once it is tuned, this workflow can quietly handle a lot of your travel planning workload in the background.

Automate YouTube-to-Email Alerts with n8n

Automate YouTube-to-Email Alerts with n8n

If you love keeping up with your favorite YouTube channels but hate constantly refreshing your subscriptions page, this workflow template is going to feel like a relief. With n8n, you can automatically get an email whenever a channel you follow publishes a new long-form video, without touching the YouTube app.

This workflow quietly runs in the background, checks your YouTube subscriptions, reads each channel’s RSS feed to find fresh uploads, enriches those videos with YouTube API data like thumbnails and duration, filters out shorts and irrelevant items, then sends you a clean email for every new long video.

Let’s walk through what it does, when you’d actually want to use it, and how the whole thing is wired together in n8n.

What this n8n template actually does

At a high level, the workflow:

  • Runs on a schedule (for example, every hour).
  • Pulls your YouTube subscriptions via the YouTube Data v3 API.
  • Checks which channels have new or unwatched items.
  • Optionally skips channels you do not want alerts for.
  • Reads each channel’s RSS feed to grab its latest 15 videos.
  • Keeps only videos that were published since the last run.
  • Calls the YouTube API again to get thumbnails and duration.
  • Filters out shorts and very short videos.
  • Sends you an HTML email for each new long-form video.

So instead of endlessly scrolling through YouTube, you just open your inbox and see exactly what is new and worth watching.

Why this approach works so well

You might be wondering: why not just use the YouTube API for everything? The short answer is quota and cost.

The template relies on YouTube’s RSS feeds for each channel:

https://www.youtube.com/feeds/videos.xml?channel_id=CHANNEL_ID

Those feeds are free to use and do not touch your YouTube Data API quota. The workflow uses them to fetch the latest 15 videos per channel, then only calls the YouTube Data API when it truly has to, mainly to get:

  • Video duration (to separate shorts from long-form content).
  • Thumbnails (so your email looks good and clickable).

By doing it this way, you:

  • Save API quota for when you actually need it.
  • Keep the workflow light and cheap to run.
  • Still get rich metadata for your emails.

In other words, RSS does the heavy lifting, and the YouTube API just fills in the gaps.

When to use this YouTube-to-email automation

This template is perfect if you:

  • Follow a lot of channels and miss uploads in the noise.
  • Prefer email over app notifications or YouTube’s random recommendations.
  • Want to avoid spammy shorts and only get longer videos.
  • Care about API quota and do not want to burn through it on every check.
  • Like the idea of building your own “personal YouTube digest” in n8n.

You can even tune it to be as quiet or as chatty as you want by changing the schedule or filtering out specific channels.

How the workflow runs from start to finish

Let’s go through the node chain in a more natural story flow, from the moment the workflow wakes up to the moment the email lands in your inbox.

1. Schedule Trigger – deciding how often to check YouTube

Everything starts with the Schedule Trigger node. This is where you tell n8n how often to look for new videos. The example workflow is set to run every hour, but you can adjust that:

  • Run more often if you never want to miss a video.
  • Run less often if you want fewer emails and fewer API calls.

Just open the Schedule Trigger node and change the interval. Increasing the interval automatically reduces how many times the workflow runs and how often it hits the YouTube API.

2. Fetching your YouTube subscriptions

Next, the workflow uses the YouTube Data v3 API to grab your subscriptions. It calls the subscriptions endpoint and pulls your channel list in pages of 50 items per request, with pagination handled for you.

The request looks like this:

GET https://www.googleapis.com/youtube/v3/subscriptions?mine=true&part=snippet,contentDetails&maxResults=50

Each call uses some API quota, but this is kept under control because:

  • The subscriptions endpoint is called only once per run.
  • Detailed video info is gathered later via RSS first, not via the API directly.

3. Error checking and splitting subscriptions

Once the response comes back, a node checks if the API returned an error object. If something went wrong, the workflow stops and gives you a helpful error message instead of silently failing.

If everything is fine, the workflow splits the list of subscriptions so that each channel is processed as its own item. This makes it easy to filter, query RSS feeds, and call the YouTube API on a per-channel basis.

4. Keeping only channels with new or unwatched videos

To avoid doing unnecessary work, the workflow looks at contentDetails.newItemCount for each subscription and only keeps channels where:

contentDetails.newItemCount > 0

This field roughly indicates that there are new uploads you have not seen yet. It is not perfect, but it dramatically cuts down the number of channels that need to be checked every run.

5. Optional channel filter – skipping noisy channels

There are always a few channels that upload too often or just are not “email-worthy.” You can easily exclude them.

In the workflow, there is a Filter node where you can add channel IDs to a notContains array. Any channel whose ID matches that list will be skipped.

You can grab a channel ID from YouTube by using Share → Copy channel ID, then paste it into that filter. This is handy for:

  • High-volume channels that would flood your inbox.
  • Channels you still want to follow in YouTube but not via email.

6. Using RSS to get the latest 15 videos per channel

For each remaining channel, the workflow builds the YouTube RSS feed URL using the channel ID from the subscription snippet. In the RSS node, the expression looks like this:

=https://www.youtube.com/feeds/videos.xml?channel_id={{ $json.snippet.resourceId.channelId }}

That feed returns the 15 most recent videos for that channel, and the best part is that it does not cost you any YouTube Data API quota.

7. Only keeping videos published since the last run

Now that we have the latest videos, we do not want to email you about the same ones over and over. So the workflow compares each video’s publish date with the time window since the last run.

The Schedule Trigger node exposes a timestamp, and the workflow uses that along with the configured interval to compute when the previous run started. The expression looks like this:

=  $('Schedule Trigger').item.json.timestamp.toDateTime().minus(  $('Schedule Trigger').params.rule.interval[0].hoursInterval,  $('Schedule Trigger').params.rule.interval[0].field  ).toISO()

Then the filter checks:

= {{ $json.pubDate.toDateTime() }} is after the computed ISO timestamp

Only videos published after that timestamp pass through. This is what keeps your inbox free of duplicates, as long as your schedule and filter window line up correctly.

8. Calling the YouTube API for video details

At this point, we have a list of fresh videos from RSS. Now we need richer metadata so we can filter out shorts and build a nice email.

The workflow calls the YouTube Data v3 videos endpoint with:

part=contentDetails,snippet,id

From this, we get:

  • contentDetails.duration – to see how long the video is.
  • snippet.thumbnails – a set of thumbnails in different resolutions.

The RSS ID looks like yt:video:VIDEO_ID, so the workflow strips the prefix using this expression:

= {{ $json.id.replace("yt:video:", "") }}

That cleaned up ID is what is sent to the YouTube API.

9. Filtering out YouTube Shorts and very short videos

Most YouTube Shorts are under 60 seconds. To avoid getting email alerts for those, the workflow converts the ISO 8601 duration from the API into seconds and applies a simple rule.

The core check (in an If node) looks like this:

=
Duration.fromISO($json.contentDetails.duration).as('seconds') > 61

Videos pass if:

  • The duration is missing (common for some live broadcasts), or
  • The duration is greater than 61 seconds.

This means regular long-form videos and some live content get through, while typical shorts are filtered out. If you want to be stricter, you can change the logic so that only videos with an existing duration greater than 60 seconds are allowed.

10. Sending an email for each new long-form video

Finally, the Email node builds and sends a nicely formatted HTML email per new video. The email includes:

  • The video title as a big heading.
  • The highest-resolution thumbnail available.
  • A link directly to the YouTube watch page.

The email subject is set to the channel title so you can quickly see which channel the video is from.

To pick the best thumbnail, the template grabs the last entry in the thumbnails object, which usually corresponds to the highest resolution. Here is the example HTML expression used:

=
<h1 style="text-align: center;">{{ $json.snippet.title }}</h1>
<a href="https://www.youtube.com/watch?v={{ $json.id }}">  <img decoding="async" src="{{ $json.snippet.thumbnails[Object.keys($json.snippet.thumbnails)[Object.keys($json.snippet.thumbnails).length - 1]].url }}" alt="Watch on YouTube" style="width:100%; height:auto; max-width:640px; display:block; margin: 10px auto;">
</a>

To make this work, you just need to configure your email credentials in n8n. The example uses SMTP, but you can also plug in other supported email providers if you have them set up.

Configuration tips so everything runs smoothly

Before you hit “activate,” here are a few practical things to double-check.

Set the right schedule frequency

  • Shorter interval (like every 15 minutes) gives you near real-time alerts but more API calls.
  • Longer interval (like every few hours) keeps things quieter and reduces quota usage.

Adjust this directly in the Schedule Trigger node.

Make sure pagination is handled for subscriptions

The YouTube subscriptions endpoint returns your channels in pages. The template already handles page tokens so that all your subscriptions are retrieved, not just the first 50. You do not have to do anything here, but it is good to know it is built-in.

Set up your credentials in n8n

  • YouTube OAuth2 credential – required for accessing your subscriptions and video details via the YouTube Data v3 API.
  • SMTP or email provider credential – required by the Email node to send messages.

Make sure both are configured and selected in the relevant nodes before running the workflow.

Exclude channels you do not want alerts from

If some channels are too noisy, you can manually exclude them. To do that:

  1. Get the channel ID from YouTube (Share → Copy channel ID).
  2. Add those IDs to the filter array in the channel filter node (the one that uses notContains).

That way, you stay subscribed on YouTube but do not get email alerts for those particular channels.

Troubleshooting and edge cases

Here are a few things that might come up and how the template handles them.

  • Live broadcasts with no duration
    Some live videos posted as regular uploads do not have a duration in the API. The workflow treats missing duration as “let it pass” so you do not miss them. If you prefer, you can tighten the filter logic to require a duration.
  • Hitting YouTube API rate limits
    If you run into quota issues, consider:
    • Increasing the interval on the Schedule Trigger node.
    • Relying on RSS as much as possible, which the workflow already does.
    • Further narrowing which channels or videos you process.
  • Getting duplicate emails
    If you see repeat emails for the same video, check that your “keep only videos published since last run” filter is aligned with your schedule interval. The timestamp logic depends on that interval, so mismatches can create overlapping windows.

Ideas for enhancing this workflow

Once you have the basic template running, you can easily extend it in n8n. Some popular tweaks include:

  • Daily or weekly digest instead of one-email-per-video
    Aggregate all new videos into a single summary email rather than sending separate messages.
  • Richer email content
    Add the video description, publish date, and duration into the email body so you can decide what to watch at a glance.
  • Send alerts to chat tools
    In addition to email, push new video notifications to Slack, Discord, or other chat platforms by adding more nodes.
  • Track emailed video IDs
    Use a small database, a Spreadsheet, or a Set node to remember which video IDs have already been sent. This gives you an extra layer of de-duplication on top of the time-based filter.

How to get started with the template

Ready to turn your inbox into a smart YouTube notification center? Here is the quick setup flow:

  1. Import the workflow JSON into your n8n instance.
  2. Connect your YouTube OAuth2 credential.
  3. Connect your SMTP or other email credential.
  4. Set your preferred schedule frequency in the Schedule Trigger node.
  5. Optionally, add any channel IDs you want to exclude.
  6. Activate the workflow and let it run.

Once it is live, you will start seeing clean, thumbnail-rich emails for new long-form videos from the channels you care about.

If you want, you can:

  • Get the exact n8n workflow JSON to import directly.
  • Walk through YouTube OAuth2 or SMTP setup step by step.
  • Customize the email template or switch to a digest-style summary.

When you are ready, you can jump straight into the template here:

n8n Crypto Alert: Binance to Telegram Workflow

n8n Crypto Alert: Binance to Telegram Workflow

Timely visibility into sharp cryptocurrency price movements is critical for traders, quants, and monitoring teams. This n8n workflow template provides an automated, production-ready pattern that connects Binance 24-hour price change data to Telegram, delivering structured alerts directly into your chosen channel or group.

This article explains the end-to-end design of the workflow, how each node is configured, and how to adapt the logic to your own trading, monitoring, or alerting requirements.

Use case and value proposition

By orchestrating Binance market data and Telegram notifications with n8n, you can implement a robust crypto alerting system without maintaining custom infrastructure or glue code.

Using n8n for crypto market alerts gives you:

  • Fully automated monitoring of Binance markets without manual refreshes
  • Flexible, configurable thresholds for significant price changes
  • Message aggregation and splitting that respect Telegram length limits
  • A modular workflow that can be extended with filters, persistence, logging, or webhooks

The result is a maintainable automation that surfaces only the most relevant moves and routes them to Telegram in a clean, readable format.

High-level architecture of the workflow

The workflow is built as a periodic polling and notification pipeline. At a high level, it:

  1. Triggers on a schedule
  2. Fetches 24-hour ticker data from Binance
  3. Filters for assets with large percentage moves
  4. Aggregates and chunks messages to fit Telegram constraints
  5. Sends formatted alerts to a Telegram chat via a bot

Concretely, the workflow uses the following n8n nodes:

  • Schedule Trigger – Defines the polling cadence
  • Binance 24h Price Change (HTTP Request) – Calls the Binance 24-hour ticker endpoint
  • Filter node (Function) – Detects significant percentage changes and formats message payloads
  • Aggregate – Combines all matching items into a single structure for batching
  • Split By 1K chars – Splits long text into approximately 1,000-character chunks
  • Send Telegram Message – Delivers each chunk to the configured Telegram chat

Configuring the workflow step by step

1. Schedule Trigger – define polling frequency

The workflow starts with a Schedule Trigger node. Configure it to match your operational and rate-limit constraints. Typical intervals include:

  • 1 minute for highly responsive monitoring
  • 5 minutes as a balanced default
  • 15 minutes or more for lower-frequency checks

When choosing the interval, consider:

  • Binance API rate limits – Avoid unnecessary calls that may trigger throttling
  • n8n instance capacity – Ensure your infrastructure can handle the polling and processing load

2. Binance 24h Price Change – retrieve market data

The next node is an HTTP Request to Binance, using the public 24-hour ticker endpoint:

https://api.binance.com/api/v1/ticker/24hr

This endpoint returns 24-hour statistics for all trading pairs, including:

  • symbol
  • priceChangePercent
  • lastPrice
  • and other metrics such as volume and high/low prices

Key points for this node:

  • No authentication is required for this public endpoint
  • If you later need higher rate limits or additional private data, configure Binance API credentials in n8n and adjust the endpoint accordingly
  • Make sure the node is configured to return JSON so it can be processed easily by the following Function node

3. Function node – detect and format significant price moves

The core of the alerting logic resides in a Function node. This node processes the Binance response, filters for assets with meaningful percentage changes, and prepares a structured list of messages for Telegram.

The sample logic used in the workflow is:

// Example logic used in the Function node
const significantChanges = [];
for (const coin of items[0].json) {  const priceChangePercent = parseFloat(coin.priceChangePercent);  if (Math.abs(priceChangePercent) >= 15) {  significantChanges.push({  symbol: coin.symbol,  priceChangePercent,  lastPrice: coin.lastPrice  });  }
}

// Sort by highest percent change
significantChanges.sort((a, b) => b.priceChangePercent - a.priceChangePercent);

// Format messages for Telegram
const sortedOutput = significantChanges.map(change => ({  json: {  message: `\`\`\`${change.symbol} Price changed by ${change.priceChangePercent}% \n Last Price: ${change.lastPrice}\`\`\``  }
}));

return sortedOutput;

Key configuration and customization options:

  • Threshold – The default threshold is 15 percent. Adjust this line:
    if (Math.abs(priceChangePercent) >= 15)
    to any desired value, for example 10 or 20, depending on your alert sensitivity.
  • Symbol filtering – To restrict alerts to specific quote assets or markets, introduce conditions such as:
    if (!coin.symbol.endsWith('USDT')) continue;
    to only include USDT pairs, or implement whitelists/blacklists for specific instruments.
  • Sorting – The list is sorted by highest percentage change, so the most extreme moves appear first in Telegram.
  • Formatting – Messages are wrapped in triple backticks for Telegram code formatting. You can adjust this to use bold, italics, or additional text as needed.

Aggregating and chunking messages for Telegram

4. Aggregate – build a combined message payload

After filtering, each item contains a single message field. To send a consolidated alert rather than many individual Telegram messages, the Aggregate node combines these items into a single data structure, typically an array or concatenated string.

This step improves readability and reduces noise in your Telegram channel, especially when multiple assets cross the threshold in the same polling interval.

5. Split By 1K chars – enforce Telegram message limits

Telegram imposes limits on message length. To avoid failures or truncated messages, the workflow uses a Split By 1K chars node that divides the aggregated text into chunks of roughly 1,000 characters.

The logic resembles the following pseudo-code:

// Pseudo-code used in 'Split By 1K chars'
function splitDataIntoChunks(data) {  const chunks = [];  let currentChunk = "";  data.forEach(item => {  const message = item.message + "\n";  if (currentChunk.length + message.length > 1000) {  chunks.push({ json: { data: currentChunk } });  currentChunk = message;  } else {  currentChunk += message;  }  });  if (currentChunk) chunks.push({ json: { data: currentChunk } });  return chunks;
}

Each output item from this node contains a data field with a safe-length text block, which is then passed to the Telegram node.

If you encounter messages that are still too long because of additional formatting or metadata, reduce the limit in the splitting logic or adjust how much data you include per asset.

Sending alerts to Telegram

6. Send Telegram Message – deliver notifications

The final node is the Send Telegram Message node, which posts each chunked message to your chosen Telegram chat.

Configuration steps:

  1. Create a Telegram Bot using BotFather and obtain the bot token.
  2. Add the bot to your target channel or group and ensure it has permission to post messages.
  3. Retrieve the chat ID:
    • For channels, this typically looks like -1001234567890
    • For private chats or groups, use a helper bot or API call to identify the chat ID
  4. Store the token as an n8n credential, then reference it in the Telegram node configuration.
  5. Set the chatId field to the target channel or group ID and map the data field from the previous node as the message text.

Once configured, each chunk generated by the previous node is sent as an individual Telegram message, giving you a clean, structured alert stream.

Security and operational best practices

For a production-grade crypto alerting workflow, observe the following practices:

  • Credential management – Store your Telegram bot token in n8n credentials, not as plaintext parameters in nodes or environment variables exposed in logs.
  • API rate limits – Respect Binance limits by tuning the Schedule Trigger interval and avoiding unnecessary retries. Consider adding basic caching if you expand the workflow to multiple Binance endpoints.
  • Secure deployment – Run your n8n instance over TLS and host it on secure infrastructure, especially if it is accessible from the public internet.
  • Audit and logging – Optionally log alerts to a database or external logging system for traceability, compliance, and later analysis.

Advanced customization options

Symbol whitelisting and blacklisting

For more focused alerting, refine the Function node so it only processes:

  • A curated whitelist of symbols, such as major pairs or specific strategies
  • Or excludes a blacklist of low-liquidity or irrelevant pairs

This can be implemented with simple arrays and conditional checks inside the Function node, for example:

const whitelist = ['BTCUSDT', 'ETHUSDT', 'BNBUSDT'];
if (!whitelist.includes(coin.symbol)) continue;

Enhanced message content and metrics

To provide richer context in each alert, you can extend the logic to include:

  • 24-hour volume or quote volume
  • Weighted average price
  • High and low prices for the period
  • Additional timeframes by combining data from other Binance endpoints

Update the Function node to extract and format these fields into the message string so that Telegram alerts carry more actionable information.

Alert severity levels and routing

Introduce severity tiers based on the magnitude of price changes. For example:

  • Notice for 5 to 10 percent moves
  • Warning for 10 to 20 percent moves
  • Critical for moves above 20 percent

You can then:

  • Apply different Telegram formatting such as bold labels, emojis, or section headers
  • Route critical alerts to a separate admin or incident channel
  • Maintain different thresholds per symbol or asset class

Persistence and analytics

For longer-term analysis and backtesting of your alert thresholds, extend the workflow to write matching events to a data store such as:

  • PostgreSQL or MySQL
  • Airtable or Google Sheets
  • A data warehouse or analytics pipeline

Storing these events enables you to analyze the frequency and impact of large moves, refine thresholds, and correlate alerts with downstream trading or risk signals.

Troubleshooting common issues

If the workflow does not behave as expected, review the following checks:

  • No Telegram messages received:
    • Verify the Telegram bot token is valid and correctly stored in n8n credentials
    • Confirm the chatId is correct and that the bot has permission to post in the channel or group
  • No matching assets:
    • Lower the percentage threshold in the Function node
    • Inspect the raw Binance API response to ensure data is returned as expected
  • Binance rate limit or error responses:
    • Increase the schedule interval to reduce request frequency
    • Consider implementing basic error handling or backoff logic in the HTTP Request node
  • Messages exceeding Telegram limits:
    • Reduce the chunk size in the splitting logic
    • Trim less critical fields from the message content
    • Be aware that formatting characters also contribute to total length

Testing and staging recommendations

Before deploying this workflow in a live environment, validate it in a controlled setup:

  • Use a private Telegram chat or dedicated test group for initial runs
  • Temporarily set a very low threshold such as 0.1 percent so that you can easily generate test alerts
  • Optionally mock the Binance response using a separate node or saved JSON to verify formatting, sorting, and chunking behavior without hitting the live API

Once you are satisfied with the output, revert the threshold to a realistic level and point the Telegram node to your production channel.

Conclusion and next steps

This n8n workflow template provides a solid foundation for automated Binance crypto alerts delivered directly to Telegram. By combining a scheduled HTTP poll, flexible filtering logic, message aggregation, and robust Telegram integration, you can:

  • Continuously monitor the Binance market for significant price changes
  • Receive concise, structured alerts in near real time
  • Easily adapt the workflow to your own symbols, thresholds, and routing rules

Deploy the template in your n8n instance, configure your Telegram credentials securely, and adjust the Function node to match your risk appetite and monitoring strategy. If needed, you can further extend the workflow with persistence, analytics, and advanced alerting logic.

Helpful resources: Review the Binance API documentation, the n8n documentation, and the Telegram Bot API reference for advanced formatting and integration options.

Auto-Tag Photos With n8n & AI (Nano Banana)

Auto-Tag Photos With n8n & AI (Nano Banana)

Managing large photo collections across cloud storage quickly becomes unmanageable without automation. The Nano Banana workflow template for n8n provides an end-to-end automation that analyzes images stored in Google Drive, generates descriptive filenames using an image-capable AI model, and uses an AI agent to decide how files should be organized or removed.

This reference-style guide documents the workflow in a technical, implementation-focused way. It covers the overall architecture, each node in the pipeline, configuration details, and operational considerations for running the workflow at scale.

1. Workflow Overview

The Nano Banana workflow is an n8n automation that:

  • Scans a target folder in Google Drive for image files.
  • Processes files in batches to respect API rate limits.
  • Calls an image-capable large language model (LLM) via HTTP to:
    • Generate a concise, descriptive filename for each image, or
    • Return a deletion signal for low-quality or unusable images.
  • Renames files in Google Drive according to the model output.
  • Aggregates existing folder metadata and passes it to an AI agent.
  • Uses the agent to decide whether to:
    • Move files into existing folders,
    • Create new folders and move files there, or
    • Delete files that should not be kept.

The design separates concerns between:

  • Vision model (image-capable LLM) for content understanding and filename generation.
  • Reasoning agent for folder selection, folder creation, and delete/move decisions.

2. Architecture & Data Flow

2.1 High-Level Execution Flow

  1. Trigger workflow manually or on a schedule.
  2. Query Google Drive for files in a specified root folder.
  3. Split the file list into batches.
  4. For each file in a batch:
    1. Generate a public or accessible download URL.
    2. Send the URL and instructions to an image-capable LLM.
    3. Receive a suggested filename or a DELETE signal.
    4. Rename the file or mark it for deletion.
  5. Aggregate current folder IDs and names under the photo root.
  6. Invoke an AI agent with:
    • Updated filename,
    • File ID,
    • Existing folder metadata.
  7. Allow the agent to:
    • Move the file to a matching folder,
    • Create a new folder and move the file, or
    • Delete the file entirely.

2.2 Core Components

  • Trigger layer: Manual Trigger or Cron node.
  • Storage integration: Google Drive nodes for listing, updating, moving, creating folders, and deleting files.
  • Batch control: SplitInBatches node to process files in controlled chunks.
  • Vision model integration: HTTP Request node calling an image-capable model (for example, google/gemini-2.5-flash-image-preview:free via OpenRouter).
  • Aggregation: Aggregate node to collect folder metadata.
  • Decisioning agent: AI agent node with tools for folder creation, file move, and file deletion, using a reasoning model (for example, gpt-4.1-mini).

3. Node-by-Node Breakdown

3.1 Trigger: Manual or Scheduled Execution

Node type: Manual Trigger or Cron

The workflow is typically developed and tested with the Manual Trigger node. For production use, replace or supplement it with a Cron node to execute on a fixed schedule.

  • Manual Trigger:
    • Useful for initial setup, debugging, and one-off runs.
    • Runs the entire pipeline on demand.
  • Cron:
    • Configure to run every few minutes, hourly, or daily depending on ingestion rate.
    • Ensures newly added photos are processed without manual intervention.

Scheduled execution keeps the Google Drive photo library continuously organized with near real-time tagging and sorting.

3.2 Google Drive: Search Files and Folders

Node type: Google Drive

Operation: List or Search Files

This node retrieves the list of files to process from a specific Google Drive folder that acts as the photo root.

  • Key configuration:
    • Resource: File
    • Operation: List or Search
    • Folder ID: Set to your photos root folder. Cache or hard-code this ID for consistency.
    • Filters: Restrict results to files only and, optionally, to image MIME types if desired.
  • Output:
    • Each item represents a file, typically including:
      • id (file ID in Drive)
      • name (current filename)
      • mimeType
      • Folder or parent references

Ensure that the Google Drive credentials used by this node have at least read access to the target folder and write access if you plan to rename or move files.

3.3 SplitInBatches: Batch Processing Control

Node type: SplitInBatches

The SplitInBatches node takes the list of files returned by the Google Drive node and processes them in configurable chunks. This is essential for:

  • Preventing workflow timeouts.
  • Respecting rate limits for:
    • OpenRouter or other LLM providers, and
    • Google Drive API quotas.

Configuration suggestions:

  • Batch size: Start with 5 to 10 files per batch.
  • Increase gradually once you have observed typical latency and error rates.

The node iterates over batches, feeding each group of items into the image-analysis portion of the workflow before continuing to the next batch.

3.4 HTTP Request: Image-Capable LLM Call

Node type: HTTP Request

This node integrates with an image-capable LLM via HTTP. In the provided template, it uses OpenRouter with the model google/gemini-2.5-flash-image-preview:free. The model receives:

  • A textual instruction (prompt) specifying filename rules.
  • An image URL pointing to the file in Google Drive.

Example JSON request body:

{  "model": "google/gemini-2.5-flash-image-preview:free",  "messages": [  {  "role": "user",  "content": [  {  "type": "text",  "text": "Analyze this image, and based on what you find, output a suggested file name in this format: blah-blah-blah - the file name should be descriptive enough to find in search, and use up to 6 or 7 words. If the main subject is too blurry, output DELETE"  },  {  "type": "image_url",  "image_url": {  "url": "https://drive.google.com/uc?export=download&id={{ $json.id }}"  }  }  ]  }  ]
}

Key points:

  • Model: You can substitute another image-capable model, but keep the prompt semantics consistent.
  • Image URL:
    • Uses Google Drive’s download URL pattern: https://drive.google.com/uc?export=download&id={{ $json.id }}.
    • Requires that the Drive file be accessible via the configured credentials or link-sharing configuration.
  • Prompt behavior:
    • The model is instructed to:
      • Return a descriptive filename with hyphen-separated words, up to 6 or 7 words.
      • Return exactly DELETE when the main subject is too blurry or the image is unusable.

Error handling considerations:

  • Handle HTTP errors (4xx/5xx) with retries or a fallback path.
  • Deal with permission issues if the generated URL is not accessible to the model provider.
  • Guard against malformed responses by validating that the model output is a single string and not empty.

3.5 Google Drive: Rename File

Node type: Google Drive

Operation: Update or Rename File

This node takes the filename suggested by the image model and updates the corresponding file in Google Drive. The logic typically looks like:

  • If the model response is DELETE (case-insensitive), mark the file for deletion instead of renaming.
  • Otherwise, use the response as the new filename.

Configuration notes:

  • File ID: Map from the previous node’s output (for example, {{$json["id"]}}).
  • New name: Use the model output, which should already be:
    • Lowercase,
    • Hyphen-separated,
    • Short (up to 6 or 7 words).

To avoid accidental deletions, you can implement a conditional branch:

  • If result equals DELETE, route the item to a delete or review path.
  • Else, route it to the rename path.

3.6 Aggregate: Folder IDs and Names

Node type: Aggregate

The Aggregate node collects metadata about existing folders under the photo root in Google Drive. This gives the AI agent a complete view of possible destinations for each file.

Typical aggregated fields:

  • folderId
  • folderName

The output is usually a single item containing an array of folder objects. This single aggregated structure is then passed to the AI agent node together with each file’s updated filename and file ID.

3.7 AI Agent: Folder & Deletion Decisions

Node type: AI Agent (LangChain-style in n8n)

This node orchestrates higher-level decisions using a reasoning model and a set of tools. It receives:

  • The file’s updated descriptive filename.
  • The file ID.
  • The list of existing folder names and IDs.

Typical agent rules:

  • If the filename contains location or category keywords that match an existing folder name:
    • Move the file to that folder.
  • If there is no strong match:
    • Create a new folder with a generic but meaningful category name (for example, beach-trips, receipts-2024).
    • Move the file into that new folder.
  • If the filename is exactly DELETE:
    • Delete the file using the Delete File tool.

Tools exposed to the agent typically include:

  • Create Folder (Google Drive).
  • Move File (Google Drive).
  • Delete File (Google Drive).
  • Language model for reasoning, such as gpt-4.1-mini.

This hybrid approach lets the vision model focus purely on image understanding, while the agent handles longer-context reasoning and file system operations.

4. Configuration Notes & Best Practices

4.1 Prompt Engineering for the Image Model

Precise prompts significantly impact filename quality and consistency. Recommended guidelines:

  • Specify the exact format:
    • Hyphen-separated words.
    • All lowercase.
    • Limit to 6 or 7 words.
  • Be explicit about deletion criteria:
    • Instruct the model to return the single word DELETE if the main subject is too blurry or the image is unusable.
  • Optionally, include instructions for category tokens or confidence scores if the model supports them, though the core template uses a simple single-string output.

Concise example prompt:

Analyze this image and return a single proposed filename using up to 6 dashed words, all lowercase. If image is unusable or main subject is too blurry, return exactly DELETE.

4.2 Batch Sizes & Rate Limits

Since the workflow calls both an LLM API and the Google Drive API, you should tune the SplitInBatches node with rate limits in mind:

  • Start with 5 to 10 files per batch.
  • Measure:
    • Average LLM response time.
    • Google Drive API latency and error responses.
  • Increase batch size only if:
    • You stay within rate limits.
    • Workflow execution time remains acceptable.

4.3 Security & Permissions

  • Google Drive credentials:
    • Use a service account or OAuth client with the minimal scopes required.
    • Restrict access to only the folders involved in the workflow where possible.
  • Auditing:
    • Log transitions such as:
      • Old filename → new filename.
      • Original folder → new folder.
      • Deletion decisions.
    • Keep logs in a separate system (for example, a spreadsheet, database, or logging service) to enable rollbacks or manual review.

4.4 Error Handling & Retries

Real-world environments require robust error handling. Recommended patterns:

  • Network and API errors:
    • Add retry logic for transient failures from OpenRouter or Google Drive.
    • Use exponential backoff where supported by n8n.
  • Dead-letter handling:
    • Route items that fail repeatedly to a dedicated “review” folder or queue.
    • Allow manual inspection and reprocessing after issues are resolved.
  • Classification failures

Build a Deep Research Agent with n8n & Perplexity

Build a Deep Research Agent with n8n & Perplexity

This guide explains how to implement a production-grade Deep Research Agent in n8n using Telegram, OpenAI, and Perplexity Sonar / Sonar Pro. The workflow converts Telegram messages into structured research queries, routes them through an agent-style orchestration layer, enriches responses with live web intelligence, and returns concise, cited answers back to Telegram.

The architecture is suitable for automation professionals who need on-demand research, market and competitive monitoring, or fast fact-checking directly inside a chat interface.

Solution architecture overview

At a high level, the workflow implements a LangChain-style agent pattern on top of n8n. Each node has a clearly defined responsibility:

  • Telegram Trigger – receives user messages and initiates the workflow.
  • Filter – enforces access control and prevents unauthorized or abusive use.
  • AI Agent – orchestrates the OpenAI chat model, short-term memory, and external tools.
  • Perplexity Sonar / Sonar Pro – provides real-time web lookups and multi-source synthesis.
  • Telegram (sendMessage) – delivers the final, formatted answer back to the originating chat.

The design separates reasoning, memory, and web intelligence. OpenAI is used for reasoning and formatting, Perplexity handles external knowledge retrieval, and n8n coordinates the full interaction lifecycle, including access control, error handling, and delivery.

Why this pattern works for deep research

This architecture follows several best practices for building reliable research agents:

  • Separation of concerns: The chat model focuses on reasoning, synthesis, and natural language output, while Perplexity handles live search and citations.
  • Short-term conversational memory: A Window Buffer memory keeps recent turns for each Telegram user, which improves follow-up queries without persisting excessive history.
  • Controlled exposure: The Filter node restricts access to defined users, groups, or specific command patterns, which is important for cost management and abuse prevention.
  • Tool-aware prompting: The agent is explicitly instructed when to invoke Sonar vs Sonar Pro, and how to present sources.

The result is an agent that behaves like a focused research assistant, combining generative reasoning with verifiable, linkable sources.

Core workflow components in n8n

Telegram Trigger configuration

The entry point is a Telegram Trigger node that listens for messages in a bot-enabled chat.

  1. Create a Telegram bot with BotFather and obtain the bot token.
  2. Add the Telegram credentials in n8n using that token.
  3. Configure the Telegram Trigger node with typical settings such as:
    • Webhook-enabled: yes
    • Update type: message
    • Session key mapping: map chat.id to the session key so that each chat has its own memory context.

Mapping chat.id to the session key is crucial. It ensures that the Window Buffer memory later in the flow maintains a separate short-term context per user or chat, which is essential for coherent follow-up questions.

Access control with the Filter node

Before invoking any AI tools, the workflow should validate whether the incoming message is allowed to use the research agent.

Use the Filter node to implement access control logic, for example:

  • Allow only specific Telegram user IDs or group IDs.
  • Restrict usage to messages starting with a command prefix such as /research.
  • Optionally check chat type (private vs group) or simple role-based logic.

A typical configuration is a numeric comparison against a known user ID, but you can extend this condition set as your deployment grows. This step is key to cost control and to prevent public abuse of the agent.

AI Agent node (LangChain-style orchestration)

The AI Agent node is the core of the workflow. It coordinates the language model, memory, and tools. Configure it with:

  • Chat model: an OpenAI chat model such as gpt-4o-mini or an equivalent model suitable for reasoning and formatting.
  • Memory: Window Buffer Memory to store a limited number of recent turns per session, using the Telegram chat.id as the key.
  • Tools: connections to Perplexity Sonar and Perplexity Sonar Pro for external web queries.

The effectiveness of this node depends heavily on the system prompt and tool-selection strategy. A representative system instruction might look like:

System: You are a research-focused assistant. Use Sonar for quick facts and Sonar Pro for deep, multi-source synthesis. Always include clickable citations when using a tool.

Within the agent configuration, define when to call each tool. For example:

  • Use Sonar for straightforward factual questions and single-entity lookups.
  • Use Sonar Pro for comparative questions, multi-source synthesis, or broader research tasks.

Memory should be scoped carefully to keep context relevant and to avoid unnecessary token usage, especially in long-running chats.

Perplexity Sonar and Sonar Pro tool nodes

Perplexity provides the external web intelligence layer. In n8n, you configure Sonar and Sonar Pro as HTTP-based tool endpoints using your Perplexity API keys.

Key configuration points:

  • Authentication: store Perplexity API keys in secure n8n credentials and reference them in the tool nodes.
  • Query payload: pass the user’s query or the agent’s tool call arguments in the JSON body.
  • max_tokens: set an appropriate response length for each tool. Sonar responses can be shorter, while Sonar Pro may require more tokens for synthesis.

Practical usage guidelines:

  • Sonar: optimized for fast, single-source lookups and quick fact retrieval.
  • Sonar Pro: designed for multi-source analysis and structured summaries, better suited for research-style questions.

The AI Agent node will call these tools dynamically as needed, then integrate the results into a final, human-readable answer that includes citations.

Telegram sendMessage node

Once the AI Agent has produced a final response, a Telegram (sendMessage) node sends it back to the originating chat.

Implementation details:

  • Use the original chat.id from the Telegram Trigger as the target chat.
  • Include the formatted answer from the AI Agent, including any clickable citations returned by Perplexity.
  • If outputs are long, consider:
    • Splitting the response into multiple messages, or
    • Attaching files (for example, text or CSV) for very large summaries.

Prompting and tool usage best practices

Careful prompt design significantly improves the reliability and cost profile of the research agent. Recommended practices include:

  • Keep the system prompt concise, but explicit about:
    • When to use Sonar vs Sonar Pro.
    • How to present citations and links.
    • Expectations for brevity and clarity.
  • Require sources after web lookups. For example:
    If you used Sonar or Sonar Pro, list up to 3 clickable source URLs at the end of your answer.
  • Control Sonar Pro usage to manage cost. Instruct the model to reserve Sonar Pro for queries that include terms such as:
    • “compare”
    • “research”
    • “market”
    • “synthesize”
  • Normalize incoming queries before passing them to the agent:
    • Trim irrelevant tokens or command prefixes.
    • Use memory to detect follow-up questions.
    • Avoid repeated web calls for identical or near-identical questions within a short time window.

Error handling, monitoring, and rate limit strategy

Any production research agent must be resilient to transient failures and API rate limits. In n8n, consider the following patterns:

  • Retries with backoff:
    • Configure retry logic for Perplexity and OpenAI calls.
    • Use exponential backoff to avoid amplifying rate-limit issues.
  • Centralized logging:
    • Record errors and failed calls in a persistent store or a logging system.
    • Optionally send alerts to a Slack channel or similar for rapid debugging.
  • Graceful user messaging:
    • On failure, return a clear fallback message, for example:
      Sorry, I’m having trouble fetching sources - try again in a minute.

Monitoring token usage, error rates, and response times over time will help you refine the configuration and prompts.

Security and privacy considerations

Because this workflow processes user queries that may contain sensitive information, apply standard security and privacy practices:

  • Minimize logged data: avoid logging raw user content unless explicitly required for debugging. Redact or anonymize where possible.
  • Environment-specific credentials: use separate OpenAI and Perplexity credentials for staging and production, and store them securely in n8n.
  • Access control: leverage the Filter node to restrict who can access the agent, and rotate API keys regularly.

These measures reduce the risk of data exposure and help maintain compliance with internal security policies.

Scaling and cost optimization

As usage grows across teams or user groups, API costs and performance become more important. To scale efficiently:

  • Introduce caching:
    • Use a cache layer such as Redis for frequently repeated queries.
    • Return cached responses instead of calling Perplexity again for the same question within a defined TTL.
  • Throttle Sonar Pro:
    • Apply heuristics to restrict Sonar Pro to long, comparative, or research-heavy queries.
    • Fallback to Sonar or the base model for simple lookups.
  • Tiered model usage:
    • Use smaller or cheaper chat models for routine queries.
    • Escalate to larger models only for complex synthesis or critical use cases.

These patterns help maintain predictable costs while preserving response quality for high-value questions.

Example research prompts

Here are sample queries that demonstrate when to use each Perplexity tool:

Quick lookup with Sonar
What is the current population of Kyoto and the main sources?

Deep synthesis with Sonar Pro
Compare the latest quarterly earnings and guidance for Company A vs Company B and list 3 supporting sources.

By guiding users on how to phrase their questions, you can further optimize tool selection and cost.

Testing, validation, and iteration

Before rolling out to a broader audience, validate the workflow thoroughly:

  1. Test in a private Telegram chat and probe edge cases, such as ambiguous questions, multi-step follow-ups, and long queries.
  2. Simulate rate-limit scenarios for OpenAI and Perplexity to verify that retry and fallback logic behaves as expected.
  3. Measure resource usage:
    • Track average tokens and API calls per query.
    • Use these metrics to estimate monthly costs and refine tool usage rules.

Iterate on prompts, filters, and caching strategies based on real usage patterns.

Extending the Deep Research Agent

The Telegram-based implementation is only one deployment option. The same pattern can be extended to other communication channels and automation scenarios, such as:

  • Adding Slack triggers for research inside team workspaces.
  • Sending results via email for longer-form reports.
  • Scheduling monitoring jobs that periodically run research queries and push updates.
  • Producing structured outputs such as CSV or PDF summaries for downstream analytics or reporting.

Because the core logic is encapsulated in n8n, you can reuse the same agent configuration across multiple channels with minimal changes.

Next steps

This n8n Deep Research Agent pattern combines automation, live web intelligence, and generative reasoning into a single, reusable workflow. It is particularly effective for teams that need fast, cited answers inside a chat interface without manually switching between tools.

To get started:

  • Import or build the workflow in your n8n instance.
  • Connect your OpenAI and Perplexity credentials.
  • Configure the Telegram Trigger and Filter nodes for your test environment.
  • Run a series of queries in a private Telegram chat and refine prompts, filters, and tool usage.

If you prefer a faster setup path, you can use a starter template and adapt it to your environment and access policies.

Action point: Deploy the template, test it in a private chat, and share feedback or questions to receive guidance on tailoring the workflow to your specific use case.