← Back to directory

Analyze stocks from Telegram using GPT-4, TwelveData, NewsAPI and Chart-IMG

unverified

gpttelegramn8n-template

Install Guide

Draft — community verifying

Generated by claude-sonnet-auto · 5/26/2026

Prerequisites

Before you begin, make sure you have the following ready:

  • n8n (self-hosted or cloud) — version 0.220.0 or later recommended
  • A Telegram account and the ability to create bots via @BotFather
  • An OpenAI account with access to GPT-4
  • A TwelveData account for stock market data
  • A NewsAPI account for financial news
  • A Chart-IMG account for generating stock charts
  • Node.js v18 or later (required if running n8n self-hosted)
  • Basic familiarity with n8n's workflow editor and credential management

Get Your API Keys

1. OpenAI (GPT-4)

  1. Go to https://platform.openai.com/api-keys
  2. Click "Create new secret key"
  3. Give it a name (e.g., stock-analyzer) and copy the key immediately — it won't be shown again
  4. Ensure your account has GPT-4 API access (check at https://platform.openai.com/account/limits)

2. Telegram Bot Token

  1. Open Telegram and search for @BotFather
  2. Send /newbot and follow the prompts (choose a name and username)
  3. BotFather will return a token in the format 123456789:ABCDefGhIJKlmNoPQRsTUVwxyZ
  4. Copy and save that token securely

3. TwelveData API Key

  1. Go to https://twelvedata.com/account/api-keys (create a free account first at https://twelvedata.com)
  2. After logging in, your API key is shown on the API Keys page
  3. Copy the key — the free tier supports up to 800 API credits/day

4. NewsAPI Key

  1. Register at https://newsapi.org/register
  2. After registration, your API key is displayed immediately on the dashboard
  3. Copy the key — the free developer plan allows 100 requests/day

5. Chart-IMG API Key

  1. Sign up at https://chart-img.com
  2. Navigate to your dashboard and locate the API Key section
  3. Copy your key — the free tier includes a limited number of chart renders per month

Installation

Option A: n8n Cloud

  1. Log in to your n8n Cloud account at https://app.n8n.cloud
  2. No additional installation is needed — proceed to Configuration

Option B: Self-Hosted n8n via npm

# Install n8n globally
npm install -g n8n

# Verify the installation
n8n --version

Option C: Self-Hosted n8n via Docker

# Pull the latest n8n image
docker pull n8nio/n8n

# Run n8n with a persistent volume
docker run -it --rm \
  --name n8n \
  -p 5678:5678 \
  -v ~/.n8n:/home/node/.n8n \
  n8nio/n8n

Import the Workflow

  1. Open the n8n editor (default: http://localhost:5678)
  2. Click "Workflows" in the left sidebar → "Add Workflow"
  3. Click the ⋮ menu (top right) → "Import from file" or "Import from URL"
  4. If you have the workflow JSON file, select it. If you received the workflow as a JSON string, paste it using "Import from clipboard"

Configuration

Set up credentials in n8n for each service. Go to Settings → Credentials → Add Credential for each one below.

| Variable / Credential | Description | Where to get it | |-----------------------|-------------|-----------------| | OPENAI_API_KEY | Secret key for GPT-4 API calls | OpenAI API Keys page | | TELEGRAM_BOT_TOKEN | Token that authenticates your Telegram bot | @BotFather on Telegram | | TWELVEDATA_API_KEY | Key for fetching real-time and historical stock data | TwelveData dashboard | | NEWSAPI_KEY | Key for retrieving financial news articles | NewsAPI dashboard | | CHART_IMG_API_KEY | Key for rendering stock chart images | Chart-IMG dashboard |

Adding Credentials in n8n

For each credential type:

  1. Navigate to Settings → Credentials
  2. Click "Add Credential"
  3. Search for the relevant service (e.g., OpenAI, Telegram, HTTP Request)
  4. Paste the API key or token into the appropriate field
  5. Click "Save"

Tip: For services without a native n8n integration (TwelveData, NewsAPI, Chart-IMG), use the "Header Auth" credential type and set the header name to Authorization with the value apikey YOUR_KEY — confirm the exact header format in each service's documentation.


Running the Bot

Development / Manual Mode

  1. Open the workflow in the n8n editor
  2. Click "Execute Workflow" to trigger a one-time manual run
  3. Send a test message to your Telegram bot while the workflow is active

Production Mode (Activate the Workflow)

  1. In the n8n workflow editor, toggle the "Active" switch in the top-right corner to ON
  2. n8n will now listen for incoming Telegram messages automatically via webhook or polling
  3. To keep n8n running persistently on a self-hosted setup, use a process manager:
# Using PM2 to keep n8n alive
npm install -g pm2
pm2 start n8n --name "stock-bot"
pm2 save
pm2 startup

Docker Production Run

docker run -d \
  --name n8n-stock-bot \
  --restart unless-stopped \
  -p 5678:5678 \
  -v ~/.n8n:/home/node/.n8n \
  n8nio/n8n

Testing

Smoke Test

  1. Open Telegram and find your bot by the username you set in BotFather
  2. Send a message with a stock ticker symbol, for example:
AAPL
  1. Within a few seconds, the bot should reply with:
    • Current stock price data (from TwelveData)
    • A recent news summary (from NewsAPI)
    • A chart image (from Chart-IMG)
    • A GPT-4 generated analysis

Verifying Each Node in n8n

  1. Open the workflow in the n8n editor
  2. Click on individual nodes (e.g., the TwelveData HTTP Request node) and click "Execute Node"
  3. Check the Output panel on the right to confirm data is returned without errors
  4. A green checkmark on each node indicates success

Check Webhook Registration (if using webhooks)

# Replace TOKEN with your Telegram bot token
curl https://api.telegram.org/bot<YOUR_TOKEN>/getWebhookInfo

A successful response will show your n8n webhook URL set as url in the JSON output.


Troubleshooting

| Problem | Likely cause | Fix | |---------|--------------|-----| | Bot does not respond to Telegram messages | Workflow is not activated, or webhook is not registered | Toggle the workflow to Active in the n8n editor; check webhook info with getWebhookInfo as shown above | | 401 Unauthorized error on OpenAI node | Invalid or expired API key, or GPT-4 access not enabled | Regenerate the key at platform.openai.com/api-keys and confirm GPT-4 is available on your plan | | 403 Forbidden from TwelveData or NewsAPI | Free-tier rate limit exceeded or wrong API key | Check your usage on the respective dashboard; upgrade plan if needed, or wait for the daily limit to reset | | Chart image not rendering or returning an error | Chart-IMG API key missing or incorrect header format | Verify the Authorization header format in Chart-IMG docs and re-enter the credential in n8n | | n8n workflow import fails or nodes appear broken | Workflow JSON was created on a different n8n version | Update n8n to the latest version with npm update -g n8n and re-import the workflow | | GPT-4 responses are slow or timing out | High API latency or n8n default timeout too short | In the node settings, increase the Timeout value; consider switching to gpt-3.5-turbo for faster responses during testing |

If issues persist after trying the fixes above, check the n8n execution logs under Executions in the left sidebar for detailed error messages and stack traces.

Sign in to leave feedback on this guide.

Language
n8n-workflow
Author
jiteshdugar
Stars
151
Source
n8n
Added
5/25/2026
Found something off? Email meow@cheesyboy.dev and we'll update the entry.