Opening Problem Statement
Meet Philipp, an active day trader and financial analyst who spends hours every day manually searching for stock charts and performing technical analysis to decide on his trades. The process is tedious, error-prone, and time-consuming — sometimes taking upwards of two hours a day just to gather and assess all the relevant data. Philipp even struggles when friends message him with quick stock questions, as he can’t respond with detailed, immediate analysis on the fly. This setup and manual research delay decision-making, reduce trading effectiveness, and increase the risk of missed opportunities in volatile markets.
This exact struggle is what the n8n workflow you’re about to explore solves. By automating stock analysis, chart generation, and AI-powered commentary all via a Telegram bot, Philipp and other traders can get professional-level analyses instantly — no more manual chart hunting or complex technical calculations.
What This Automation Does
This n8n workflow creates an AI-powered Telegram-based stock analysis assistant with the following capabilities:
- Handles multi-format input: Accepts both text and voice messages over Telegram for stock ticker queries.
- Audio transcription: Uses OpenAI’s API to transcribe voice messages reliably into text queries.
- Chart generation: Calls an external chart image API to produce advanced technical charts (RSI, MACD, volume overlays) based on the requested stock ticker and chart style.
- Technical analysis: Utilizes an OpenAI model to thoroughly analyze the generated stock charts for candlestick patterns, RSI, Stochastic RSI, and market sentiment.
- Interactive AI agent: Responds conversationally with detailed, easy-to-understand stock insights right through Telegram.
- Scheduled batch analysis: Automatically loops through saved ticker lists from Airtable on a schedule to deliver periodic reports on selected stocks.
- Data storage: Saves important ticker symbols to Airtable for ongoing automated analysis workflows.
Overall, this workflow can save traders hours daily by automating cumbersome research and providing professional analysis instantly, with no coding or manual chart creation needed.
Prerequisites ⚙️
- n8n account (self-hosting possible, see buldrr.com/hostinger)
- Telegram Bot API credentials 📧 (Telegram Trigger and Telegram nodes)
- OpenAI API key 🔑 (for both GPT-4 and audio transcription)
- Airtable account with base and table set up 📊 (to store ticker symbols)
- API key for chart image generation service (generic HTTP header authentication) 🔐
Step-by-Step Guide
1. Set Up Telegram Trigger to Receive Messages
Go to your n8n Editor, click + Add Node → Telegram Trigger. Configure it to listen for new Telegram messages by selecting message updates and link your Telegram Bot API credentials. This node will capture every incoming text or voice message from users sent to your Telegram bot.
Once messages arrive, you’ll be able to process and branch based on whether it’s voice or text input.
Common mistake: Forgetting to connect your Telegram Bot’s webhook URL to n8n. Always ensure Telegram bot settings point correctly to your n8n webhook endpoint.
2. Use Switch Node to Differentiate Between Voice and Text
Add a Switch node with two outputs, configured on the condition if the incoming message has a voice.file_id or text content. This separation allows processing voice messages through transcription and text messages directly for analysis.
3. Download Voice Messages
If voice detected, attach a Telegram node configured for download file operation using the voice’s file_id. This downloads the audio file from Telegram for further transcription.
4. Transcribe Audio to Text Using OpenAI
Connect the Download File node output to a OpenAI node set to audio transcription. This converts speech into text for stock ticker extraction.
Code snippet (preset in node): operation: transcribe
resource: audio
5. Set Stock Query Text
Whether from transcription or direct text input, use a Set node to unify message content into a field named text. This prepares the data for AI processing.
6. Process Query Through AI Agent
This core AI Agent node runs a Langchain agent configured with a custom system message instructing it how to intelligently handle stock ticker queries, including calling out to the Get Chart tool for chart generation.
This node uses OpenAI GPT-4-powered chat model for conversational engagement, providing professional, friendly interaction while parsing stock tickers and chart style.
7. Generate Stock Chart Using HTTP Request to Chart API
The Get Chart URL HTTP Request node sends a POST request to the external chart API, passing the ticker symbol (prefixed with NASDAQ) and chosen chart style (default candle chart) along with technical indicators like RSI and volume overlays.
Example JSON body sent:
{
"style": "candle",
"theme": "light",
"interval": "1W",
"symbol": "NASDAQ:TSLA",
"override": {
"showStudyLastValue": false
},
"studies": [
{"name": "Volume","forceOverlay": true},
{"name": "Relative Strength Index"},
{"name": "Stochastic RSI"}
]
}Set correct HTTP headers for the API key and content type in the node.
8. Download the Generated Chart Image
Next, the Download Chart node fetches the actual chart image from the URL returned by the previous HTTP node. This image will be used for technical analysis.
9. Analyze Chart Using OpenAI Image Analysis
The Technical Analysis OpenAI node sends the chart image to an OpenAI GPT-4 powered specialized model to analyze candlestick patterns, RSI, Stochastic RSI, and market sentiment.
The node prompt is set to provide a detailed, actionable analysis in clear language without direct financial advice, tailored to various technical indicators.
10. Send Chart Image and Analysis Back via Telegram
After image analysis, two Telegram nodes are used:
- Send Chart: Sends the chart image as a photo message to the user’s Telegram chat id.
- Send Analysis: Sends the detailed textual analysis to the same Telegram chat instantly.
Both nodes use the Telegram API credentials and the correct chat ID (phased as a fixed value or dynamically passed).
11. Save Ticker to Airtable for Scheduled Analysis
When the user requests saving a ticker for repeated notifications, the Save Ticker Airtable node records the ticker symbol into your Airtable base, preparing it for periodic scheduled runs.
12. Set Up Scheduled Trigger for Batch Stock Analysis
The Schedule Trigger node runs on an interval (e.g., daily or weekly) to pull ticker lists from Airtable via the Get tokens node.
This list is processed in batches by the Loop Over Items node, then individual tickers are sent to the Run Agent HTTP Request node which calls the workflow webhook with an analysis query for each ticker.
13. Configure Webhook To Process Scheduled Requests
The Webhook node receives requests from the scheduling HTTP call and triggers the same AI Agent workflow path for analysis and Telegram message delivery, enabling full automation of batch analysis reports.
Customizations ✏️
- Adjust Chart Style Defaults: In the Get Chart node or Get Chart URL node, change the default chart_style parameter to other types like “bar” or “line” for different visualizations.
- Expand Supported Exchanges: Modify the symbol prefix in HTTP request JSON from “NASDAQ:” to support other stock markets such as “NYSE:” or international tickers.
- Custom Telegram Responses: In the AI Agent node, modify the system message prompt to change the conversational style or add your own disclaimers or greetings.
- Add More Technical Indicators: Extend the studies array in the chart API request to include indicators like Bollinger Bands or MACD for deeper analysis.
- Dynamic Chat ID: Instead of a fixed chat ID, configure Telegram nodes to accept chat ID dynamically from incoming messages.
Troubleshooting 🔧
Problem: “API request failed” or empty chart returned
Cause: API key for chart service is invalid or missing; the request JSON is malformed.
Solution: Verify credentials in the HTTP Request node headers. Double-check the JSON body matches the API documentation. Test API separately via Postman if needed.
Problem: “No message received” after sending voice note
Cause: Telegram bot webhook not set correctly or Telegram Trigger node not capturing voice updates.
Solution: Ensure Telegram Trigger node includes ‘message’ in updates. Confirm webhook URL allocation to Telegram bot settings.
Problem: AI Agent returns generic or irrelevant responses
Cause: System prompt in the AI Agent node not properly tailored or token limits exceeded.
Solution: Adjust the AI Agent’s system prompt for clarity. Monitor token usage and consider shortening request payloads.
Pre-Production Checklist ✅
- Confirm Telegram Bot credentials and webhook linkage are active.
- Test voice and text message input flows separately.
- Verify chart API key, endpoint URL, and JSON body correctness.
- Ensure OpenAI API keys are correctly set and limits are sufficient.
- Test Airtable read/write permissions with your base and table.
- Try the scheduled trigger with a small ticker list to verify batch processing.
Deployment Guide
Once all nodes are configured, activate your Telegram Bot and n8n workflow. Monitor the execution logs in n8n for errors or failed HTTP requests to the chart API or OpenAI endpoints.
For scaling, consider hosting n8n on a reliable cloud provider or your own server for uptime stability. Periodically update API keys and review usage limits.
FAQs
- Can I use other chart APIs instead of the one in the workflow?
- Yes, you can replace the Get Chart URL HTTP Request node with any compatible chart provider. Just ensure the endpoint requires similar parameters and returns a direct image URL.
- Does this workflow consume a lot of OpenAI API credits?
- It depends on usage volume and model choices (GPT-4 typically uses more tokens). Voice transcription and image analysis add to costs. Monitor usage carefully.
- Is my data safe when using this workflow?
- All API calls happen securely via HTTPS. Avoid sharing sensitive personal data. Telegram messages are encrypted. You control your Airtable data and API keys.
- Can I add more technical indicators?
- Yes, add them to the chart API request body under “studies” array for deeper insights.
Conclusion
By following this guide, you’ve built a powerful stock analysis assistant that leverages n8n’s automation capabilities, OpenAI’s AI expertise, and Telegram’s accessibility. You transformed hours of manual stock charting and analysis into instant, conversational insights delivered right to your fingertips.
This solution not only boosts your efficiency by saving hours daily but also opens doors for advanced customization — from scheduled portfolio reports to expanding supported exchanges.
Next, consider expanding this workflow for real-time alerts on market movements, integrating with trading platforms to automate order placement, or incorporating more advanced AI models for sentiment analysis.
Happy trading and automating!