You can create a stock analysis AI agent that replies to a Telegram message with a chart and an easy-to-read market summary. In this guide, you will connect n8n, Telegram, Twelve Data, Chart IMG, and OpenAI through visual workflow nodes. The bot will help you review price patterns, but it will not predict returns or make trading decisions for you.

Quick Answer

Build a Telegram stock analysis bot with n8n. Connect a Telegram Trigger, validate a ticker, request price data from Twelve Data, capture a chart with Chart IMG, and ask OpenAI to explain the returned data. Then send the chart and summary to the original Telegram chat. You can configure this in n8n without writing a separate app.

Key Takeaways

  • n8n acts as the automation engine that connects Telegram, market data, charting, and AI analysis.
  • Telegram is the user interface, so you can request analysis from your phone.
  • Twelve Data supplies market data for the written analysis. Chart IMG separately captures a chart from its supported charting source; it does not directly render the Twelve Data response.
  • OpenAI can explain supplied prices and indicators, but it must not invent data or trading signals.
  • This bot is useful for research and learning, but it should not replace professional financial advice.

At a Glance

Time RequiredVaries by hosting, credentials, and troubleshooting. Allow extra time for webhook and API tests.
DifficultyBeginner to intermediate. You will configure credentials, expressions, HTTP requests, and bot responses.
Tools Neededn8n with a public HTTPS webhook, Telegram, OpenAI API access, Twelve Data, and Chart IMG.
CostHosting, OpenAI API usage, and provider limits vary. ChatGPT subscriptions do not automatically pay for API usage.

Diagram for a Telegram stock analysis AI agent built with n8n

How the Stock Analysis AI Agent Works

The bot needs two separate outputs: reliable price data for the written analysis and a chart image for a visual reference. A typical n8n workflow follows these steps:

  1. Telegram Trigger: Receive a text message and capture the sender’s chat ID.
  2. Validate the request: Extract a supported stock symbol and reject empty or unclear messages.
  3. Twelve Data HTTP Request: Retrieve a chosen period of price data and check the response for errors.
  4. Chart IMG HTTP Request: Request a chart screenshot for the same symbol and a matching interval where available.
  5. OpenAI: Summarize only the retrieved market values, with the symbol, timeframe, and data timestamp.
  6. Telegram Send Photo and Send Message: Return the visual and the text to the chat that started the request.

Use one consistent symbol and exchange across the services. A chart screenshot and the Twelve Data price response can use different underlying feeds, so slight differences do not automatically mean either service is broken.

Note: An imported workflow is only a starting point. You still need to inspect its API endpoints, credentials, node connections, and output fields before enabling it.

Setting Up the n8n Automation Platform

n8n is an automation platform that connects different apps and services in one visual workflow. For this stock analysis bot, n8n works as the central engine. It receives a Telegram message, requests market data and a separate chart image, sends validated values to OpenAI, and replies in Telegram.

You need a working n8n instance before you can build the workflow. You can host it locally, use a compatible hosted service, or choose n8n Cloud. Telegram webhooks need a publicly reachable HTTPS URL. The right option depends on your budget, uptime needs, and comfort level with server management.

Hosting Options for n8n

You have three primary ways to host your n8n instance:

  • Local Hosting: You run n8n on your own computer. This is a low-cost option, but your machine must stay active for the bot to work.
  • WebSpaceKit (WSK) Hosting: This provides a cloud environment that can keep your bot running without leaving your personal computer online all day.
  • n8n Cloud: This is the official hosted option from n8n. It can be easier to maintain, though the cost may be higher than some self-hosted setups.

The screenshots below use WebSpaceKit. It advertises managed n8n hosting, but confirm the current plan features and setup screens before buying. The workflow logic also applies to other supported n8n hosting options.

Note: A local n8n instance needs a reachable HTTPS webhook for Telegram. A computer that sleeps or disconnects can stop receiving updates. Use a secure tunnel or correctly configured HTTPS reverse proxy if you self-host.

WebSpaceKit hosting plan selection screen for n8n

Purchasing and Installing n8n

Follow these steps to prepare your environment:

  1. Review the provider’s current n8n hosting features, webhook support, and usage limits before selecting a plan.
  2. Complete the provider’s account and hosting setup using its current instructions.
  3. Open the hosting dashboard and follow the setup option shown for your n8n instance. Button labels can differ.
  4. Confirm that your n8n editor opens over HTTPS and that you can save a test workflow.

Once the dashboard loads, you are ready to import the workflow. At this point, keep your hosting dashboard open because you may need it while testing and activating the automation.

WebSpaceKit n8n hosting account activation screen

Importing the Workflow Template

A compatible JSON workflow can save setup time, but importing it does not configure credentials or guarantee that its API requests still work. Review the JSON source before importing because workflows can contain unsafe endpoints or unexpected actions.

  1. If your hosting provider currently offers a trusted “Technical Analysis Agent” JSON template, download it. Otherwise, create the six workflow stages listed above with n8n nodes.
  2. In the n8n editor, open the workflow menu and select “Import from File” if you have a JSON template.
  3. Import the JSON, then name and save the workflow “Stock Analysis Bot.” If building manually, add a Telegram Trigger and connect the other nodes in the same sequence.
  4. Check every imported or new node for missing credentials, invalid endpoints, and unexpected expressions before testing.

n8n editor dashboard before importing a workflow

An imported workflow may show warnings for missing credentials or required values. A node can also be misconfigured without a warning, so test its output rather than relying on the icon alone.

n8n workflow with nodes awaiting setup or credentials

Configuring Essential Workflow Nodes

The workflow connects four external services. Each needs the correct credentials and a response format that the next node can read.

  • Telegram: Receives your stock symbol request and sends the final response back to you.
  • OpenAI: Explains structured market data and any explicitly provided indicators; a chart image is not automatically analyzed.
  • Twelve Data: Supplies market prices, timestamps, and other supported data fields.
  • Chart IMG: Captures a chart screenshot from a supported charting service, independently of the Twelve Data API response.

Connecting Telegram

Telegram acts as the front end of your stock analysis bot. Instead of opening multiple tools, you send a message to your bot and let n8n handle the workflow in the background.

  1. Open the verified @BotFather account in Telegram and send /newbot.
  2. Follow its prompts to choose a bot name and unique username.
  3. Copy the bot token and store it securely.
  4. In n8n, create Telegram credentials with that token and select them in the Telegram Trigger node. Choose the Message update event.
  5. Start a chat with your bot and send /start, then a test ticker while the trigger listens for test events.

Warning: Treat your Telegram bot token like a password. Do not publish it in screenshots, public templates, shared documents, or website code.

Telegram BotFather setup screen for a new bot

Inspect the trigger output for message.chat.id and message.text. Keep the original chat ID available for the send nodes. A fixed chat ID works only for a restricted personal bot; a shared bot needs to use the incoming chat ID dynamically.

Telegram Trigger test output showing message and chat ID

Connecting OpenAI

OpenAI can summarize the actual price series or indicators that n8n passes to it. It cannot verify live market prices on its own in this workflow, and its output should not be treated as financial advice.

  1. Create an API key in the OpenAI API platform, using the appropriate project and permissions.
  2. In the n8n OpenAI node, create or select credentials for the API project.
  3. Save the key in n8n credentials, not in the prompt or workflow text. Check that API billing or credits are available.
  4. Test the node using a supported model and a short sample prompt, then inspect the output before connecting real market data.

Give the model the ticker, exchange, data timestamp, interval, and an organized set of prices or calculated indicators. Ask it to describe trend direction and risk without giving buy or sell instructions. Do not ask for support, resistance, or volume analysis unless your inputs actually support it.

Pro Tip: Tell the model to say “insufficient data” when a metric is missing, to distinguish facts from interpretation, and never to invent prices, indicator values, or future returns.

OpenAI API credentials configuration in n8n

Example Prompt for a Data-Grounded Summary

Adapt the following instruction in your OpenAI node. Map each field to the verified output of your market data node rather than manually typing a price.

Summarize the provided stock data for education only. Identify the ticker, exchange, candle interval, most recent data timestamp, and any clear historical pattern supported by the supplied values. State when volume or indicators are missing. Do not invent prices, technical levels, live updates, forecasts, or buy/sell recommendations. Keep the reply under 150 words.

Remember that the OpenAI API has separate billing from ChatGPT subscriptions. Check your project’s usage and spend limits before enabling repeated requests.

Enabling Stock Data and Charting

Use Twelve Data for the price series that supports your AI summary. Use Chart IMG for a separate stock chart screenshot. Because these services do not share a single underlying dataset automatically, check that their symbols, exchanges, dates, and intervals line up.

Connecting Twelve Data

Twelve Data provides time-series records with fields such as open, high, low, close, volume, and timestamps where available. Its /time_series endpoint can give the AI model factual context for a chosen ticker and interval.

  1. Create a Twelve Data account and review its current market coverage and API allowances.
  2. Copy the API key from your Twelve Data dashboard and keep it private.
  3. Configure an n8n HTTP Request node for the /time_series endpoint, using the method and parameters in the official API documentation.
  4. Configure authentication securely. For a daily example, send symbol=AAPL, interval=1day, and an appropriate outputsize. The actual key belongs in credentials or a protected parameter.
  5. Test with AAPL or TSLA. Confirm the response contains the expected symbol, exchange, interval, timestamp, and price records, rather than an API error.

For Twelve Data, 1day means one daily candle; it does not mean an image of one trading day. Access to real-time data, exchanges, and indicators varies by plan. Market data can be delayed, and API rate or credit limits can block requests.

Twelve Data API key setup for a stock time-series request

Validate Ticker Input Before Calling APIs

For a beginner bot, accept a single ticker such as AAPL or TSLA and use an n8n Edit Fields or Switch node to clean and validate the message. Plain-language requests such as “Analyze Tesla” need a separate symbol-lookup step; they will not automatically become TSLA.

Reject missing or unsupported symbols with a friendly reply. In a shared bot, limit message length, avoid passing raw user text into API URLs, and restrict which chats can call paid services.

Connecting Chart IMG

Chart IMG captures images of supported TradingView charts. It does not directly plot the JSON returned by Twelve Data. Request the same stock and an equivalent interval if you want the screenshot to match the figures in your summary.

  1. Sign in to Chart IMG and find the API key and documentation for the chart type covered by your plan.
  2. Add an HTTP Request node for the supported Chart IMG endpoint and method.
  3. Use the documented authentication method, such as the x-api-key request header on supported POST endpoints.
  4. Set the exact exchange-qualified symbol if required, a supported chart interval, and optional appearance settings.
  5. Run the request and inspect whether the response is image binary data or a usable image URL. Configure the HTTP node’s response format accordingly.

For a daily candle chart, a Chart IMG endpoint may use 1D while Twelve Data uses 1day. Confirm supported values for your chosen endpoint. The candle interval is different from the amount of history visible in the screenshot.

Chart IMG API key configuration for chart screenshot generation

Send the Chart and Summary Back to Telegram

Use a Telegram Send Photo node when Chart IMG returns an accessible image URL or binary image. If your HTTP node outputs a binary file, enable Binary File in the Telegram node and select the matching binary field. If it returns a URL, pass that URL as the photo source.

Add a separate Send Message node for the AI summary. A long explanation should not be squeezed into a photo caption. Both send nodes must use the same chat ID captured by the trigger.

Managing Multi-User Access

If more than one person can use the bot, do not hardcode a single destination. Otherwise, one person could receive another person’s analysis, or replies could go to the wrong chat.

In each Telegram send node, reference the original trigger output. If the trigger is named Telegram Trigger, an example chat ID expression is {{ $('Telegram Trigger').first().json.message.chat.id }}. The shorter {{ $json.message.chat.id }} works only when the current node still receives the original Telegram message structure. Adjust the node name and verify the expression in your own workflow.

Note: For a private bot, restrict access to your own chat or user ID. For a shared bot, use dynamic routing and add user limits to control privacy and API spending.

Telegram reply chat ID configuration in n8n

Testing and Refining Your Bot

After each node works in testing, save and publish the workflow using the controls in your n8n version. Send a supported ticker such as AAPL to your Telegram bot and inspect the production execution.

A successful execution should receive the Telegram message, validate the symbol, fetch valid Twelve Data records, obtain a Chart IMG screenshot, generate a grounded OpenAI summary, and return both outputs to the correct chat.

Example stock chart and AI summary returned to a Telegram chat

What to Check Before You Activate the Workflow

Test one node at a time before relying on the bot. Compare its output against a separate trusted data source, especially for market timing, exchange selection, and volume figures.

  • Telegram trigger: Confirm that your message reaches n8n.
  • Ticker parsing: Confirm that it accepts AAPL but rejects unsupported free-form requests unless you built symbol lookup.
  • Twelve Data request: Confirm that the symbol, interval, exchange, and timestamps are correct and that no rate-limit error occurred.
  • Chart IMG request: Confirm the screenshot matches the requested symbol and candle interval, and compare feed differences.
  • OpenAI response: Check that every reported number is present in the input and no unsupported trading signal appears.
  • Telegram send nodes: Confirm that the photo and written summary reach the original chat.

Troubleshooting Common Issues

If your bot fails to respond, check your n8n execution log first. The log can show which node failed, what data entered the node, and what error came back from the service.

  • No Telegram response: Check that the workflow is published, the trigger uses a reachable HTTPS webhook, and the bot has received a user message.
  • Invalid stock symbol: Confirm that the input parser produced a ticker and that your provider covers its exchange.
  • No chart image: Check the Chart IMG endpoint, symbol format, API allowance, and the HTTP node’s binary or URL output settings.
  • OpenAI error: Check the model, project credentials, remaining credits, rate limits, and billing permissions.
  • Wrong recipient: Reference message.chat.id from the original Telegram Trigger, not from a later HTTP response.
  • Slow response: Review hosting, API latency, rate limits, and chart generation. Let users know a request is processing when the workflow is slow.
  • Works in test mode only: Telegram allows only one webhook per bot. Switching between test and production can replace the webhook; republish the workflow or use a separate test bot.
  • Different chart price: Confirm the exchange, adjustment settings, candle interval, market session, and the two providers’ data feeds.
  • Unexpected charges: Add user restrictions and request limits; review n8n executions and provider usage dashboards.

If you encounter errors, test each node individually to isolate the problem. Fix the first failing node before moving deeper into the workflow.

Daily stock chart image used to review price trends

Benefits of Automation

Once tested, the bot brings a chart and a short data summary into one Telegram conversation. This cuts down the number of manual steps needed to check a stock’s recent price history.

Using the same prompt, interval, and data checks can make routine comparisons more consistent. Still, new candles and different market feeds can change the output from one request to the next.

A stock analysis bot is most useful when it speeds up research, not when it replaces judgment. Use it to organize data, spot patterns, and prepare better questions before making financial decisions.

Conclusion

A configured and tested n8n workflow can turn a Telegram ticker message into a chart screenshot and a grounded stock-data summary. The key is to treat Twelve Data as the analysis source and Chart IMG as a separate visual source.

Start with one supported symbol and a daily interval. Once the workflow is stable, add ticker lookup, clearer error messages, user access controls, and usage monitoring. Verify any material financial data independently before acting on it.

Disclaimer: This guide is for educational purposes only and does not constitute financial advice. Market data availability, accuracy, and latency depend on your data providers, plans, and exchanges. Always verify information with trusted platforms and consult a qualified professional before making financial decisions.

Frequently Asked Questions

Do I need to know coding to build this stock analysis bot?

You can assemble the workflow with visual nodes and configuration fields. You still need to understand basic API responses, credentials, and n8n expressions.

Can I use this bot for any stock symbol worldwide?

No. Coverage depends on the data and chart providers, your subscriptions, and exchange support. The two services must both recognize the requested symbol for the combined response to work.

How can I host n8n for free?

You can self-host n8n on your computer, but it must stay running and expose a secure public HTTPS webhook for Telegram. Other services may still charge for API usage.

What if I want to support multiple Telegram users?

Use a chat ID expression that references the original Telegram Trigger, such as {{ $('Telegram Trigger').first().json.message.chat.id }}, after checking your node name and data structure. Add access limits before opening the bot to the public.

Can I customize the AI analysis responses?

Yes. Edit the OpenAI prompt to change how the bot explains the values you provide. Only include technical indicators or volume figures that your data request supplies.

Is this bot suitable for real-time trading decisions?

No. Use this tool for education, organization, and idea generation only. Always verify market data with trusted financial platforms before placing trades.

Why is my Telegram bot not replying?

Check whether the workflow is published, the HTTPS webhook is reachable, the token is valid, and the send nodes use the correct chat ID. Also check for a test-versus-production webhook conflict.

Can I change the chart timeframe?

Yes. Adjust the candle interval for both providers. For example, Twelve Data uses 1day for daily data, while Chart IMG endpoints may use 1D. Check each endpoint’s supported values.

Sources

  1. n8n Documentation — workflow building, imports, and Telegram integrations.
  2. Telegram Bot Platform — supports Telegram bot creation and bot messaging concepts.
  3. OpenAI Platform Documentation — supports using OpenAI through API credentials and workflow integrations.
  4. TwelveData API Documentation — supports stock market data API usage and symbol/time-series concepts.
  5. Chart IMG — explains the TradingView screenshot service and plan limits.
  6. n8n Import and Export Guide — documents JSON workflow imports.
  7. OpenAI API Billing Guide — confirms that API billing is separate from ChatGPT billing.