Optimize Prompts with n8n, LangChain AI & Telegram

This workflow improves vague user prompts by leveraging LangChain AI for clarity and detail enhancement, then sends the refined prompts back via Telegram, streamlining prompt optimization for better automation outcomes.
executeWorkflowTrigger
agent
telegram
+3
Workflow Identifier: 2184
NODES in Use: Execute Workflow Trigger, AI Agent, Telegram, OpenAI Chat Model, Code, Simple Memory

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

Visit through Desktop for Best experience

What this workflow does

This workflow gets a prompt input and makes it clearer and detailed using AI.
It fixes unclear prompts so AI gives better results.
After improving the prompt, it breaks long text into smaller parts to send via Telegram.
Finally, it sends the improved prompt back to the user in Telegram.
The workflow also remembers past inputs a little to keep context.
This saves time and gives higher quality AI answers.


Who should use this workflow

Anyone who uses AI but faces problems with unclear prompts and wants better answers quickly.
It is great for content creators, writers, and automation users who want less editing.


Tools and services used

  • n8n Automation Platform: Runs automation workflows.
  • OpenAI API (GPT-4o mini): Improves prompts using AI.
  • LangChain AI Agent: Connects AI and n8n for prompt refinement.
  • Telegram Bot API: Sends and receives messages.
  • Simple Memory node: Keeps short conversation memory for AI context.

Inputs, processing steps, and output

Inputs

The workflow accepts prompt text
Either from another workflow or a Telegram message.

Processing Steps

  • Receive the raw prompt with Execute Workflow Trigger node.
  • Send the prompt to AI Agent node, which uses a special system message to improve clarity and detail.
  • OpenAI Chat Model node with GPT-4o mini runs the AI for prompt rewriting.
  • Simple Memory node connects to AI Agent to keep short context.
  • Split long AI output text in the Code node to fit Telegram limits.
  • Send the optimised prompt back with Telegram node.
  • Handle errors smoothly if Telegram has problems.

Output

User gets a clearer prompt text in Telegram
Split into parts if it is very long.


Beginner step-by-step: How to use the workflow in n8n

Step 1: Import the workflow

  1. Download the workflow file using the Download button on this page.
  2. Go to the n8n editor, click on “Import from File”.
  3. Choose the downloaded workflow to add it.

Step 2: Configure credentials and details

  1. Add your OpenAI API Key in n8n credentials.
  2. Add your Telegram bot API Key in n8n credentials.
  3. Check if chat ID, email, channel, or other ID inputs need updating.
  4. If the Code node or AI Agent node has any custom prompts or code, just copy and paste them as they are.

Step 3: Test and activate

  1. Run the workflow once in n8n to verify outputs.
  2. If Telegram message sends successfully, activate the workflow.
  3. Now the workflow can be used inside other workflows or triggered as needed.

For users doing self-host n8n, make sure API and webhook access are set up properly.


Customizations and tips

  • You can choose a different GPT model for the OpenAI Chat Model node.
  • Modify the system message inside AI Agent node to change how prompts are improved.
  • Increase the buffer size in the Simple Memory node to keep longer chat history.
  • Add more output nodes like Slack or Email after the Code node to send prompts to other platforms.
  • Replace the Execute Workflow Trigger node with Telegram Trigger to start the flow from Telegram messages directly.

Edge cases and failure handling

  • If AI Agent gives vague output, check if the system message is correct.
  • If Telegram messages don’t send, look at the Code node that splits messages to keep length under limits.
  • If OpenAI Chat Model node throws errors, verify API Key settings.

Summary

✓ Clearer and detailed prompts from raw user input
✓ Chat memory boosts AI understanding
✓ Long messages split for Telegram delivery
✓ Saves time revising AI prompts
✓ Easy to use in many n8n automations


Frequently Asked Questions

Yes, users can select other GPT variants in the OpenAI Chat Model node depending on their API access and preferences.
A Code node splits long AI responses into smaller message chunks to fit Telegram’s character limits.
Users should verify that the system message for the AI Agent node matches the recommended text exactly.
Yes, the workflow can run on self-hosted n8n setups; users should ensure API and webhook configurations are correct.

Promoted by BULDRR AI

Related Workflows

Automate Viral UGC Video Creation Using n8n + Degaus (Beginner-Friendly Guide)

Learn how to automate viral UGC video creation using n8n, AI prompts, and Degaus. This beginner-friendly guide shows how to import, configure, and run the workflow without technical complexity.
Form Trigger
Google Sheets
Gmail
+37
Free

AI SEO Blog Writer Automation Workflows in n8n

A complete beginner guide to building an AI SEO blog writer automation using n8n.
AI Agent
Google Sheets
httpRequest
+5
Free

Automate CrowdStrike Alerts with VirusTotal, Jira & Slack

This workflow automates processing of CrowdStrike detections by enriching threat data via VirusTotal, creating Jira tickets for incident tracking, and notifying teams on Slack for quick response. Save hours daily by transforming complex threat data into actionable alerts effortlessly.
scheduleTrigger
httpRequest
jira
+5
Free

Automate Telegram Invoices to Notion with AI Summaries & Reports

Save hours on financial tracking by automating invoice extraction from Telegram photos to Notion using Google Gemini AI. This workflow extracts data, records transactions, and generates detailed spending reports with charts sent on schedule via Telegram.
lmChatGoogleGemini
telegramTrigger
notion
+9
Free

Automate Email Replies with n8n and AI-Powered Summarization

Save hours managing your inbox with this n8n workflow that uses IMAP email triggers, AI summarization, and vector search to draft concise replies requiring minimal review. Automate business email processing efficiently with AI guidance and Gmail integration.
emailReadImap
vectorStoreQdrant
emailSend
+12
Free

Automate Email Campaigns Using n8n with Gmail & Google Sheets

This n8n workflow automates personalized email outreach campaigns by integrating Gmail and Google Sheets, saving hours of manual follow-up work and reducing errors in email sequences. It ensures timely follow-ups based on previous email interactions, optimizing communication efficiency.
googleSheets
gmail
code
+5
Free