Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

26 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ IHSG Analytics Bot

Enterprise-Grade AI-Powered Indonesian Stock Market Analytics Platform
Real-time market intelligence, advanced price alerts with anti-spam batch notifications, bandarmologi analysis, and institutional trading insights delivered via Telegram.

TypeScript Node.js Telegraf Supabase Production Ready License


πŸ“‹ Executive Overview

IHSG Analytics Bot is a production-ready, enterprise-grade Telegram bot that delivers comprehensive Indonesian stock market analytics powered by artificial intelligence. Built with TypeScript 6.x and Node.js 24.x, the platform integrates real-time market data from GoAPI, leverages AI Aggregator (primary) and Google Gemini (fallback) for intelligent natural language processing, and provides persistent cloud storage through Supabase PostgreSQL.

🎯 Key Differentiators

  • πŸ”” Advanced Alert Engine - Anti-spam batch notification system with HTML formatting and exponential backoff retry mechanism
  • πŸ€– Dual AI Architecture - Primary AI Aggregator with automatic Google Gemini fallback for 99.9% uptime
  • πŸ“Š Institutional Analytics - Bandarmologi tracking, foreign flow analysis, and liquidity sentiment indicators
  • ⚑ Production-Hardened - Exponential backoff with Β±20% jitter, graceful error handling, and configurable worker intervals
  • 🎨 Premium UX - Beautiful HTML notifications with monospace data alignment and strategic emoji indicators

πŸ—οΈ System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      IHSG Analytics Bot                             β”‚
β”‚                                                                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”‚
β”‚  β”‚   Telegram   │────▢│   Telegraf   │────▢│    Hermes    β”‚      β”‚
β”‚  β”‚     User     │◀────│ Bot Handler  │◀────│  AI Agent    β”‚      β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚
β”‚                                                     β”‚               β”‚
β”‚                                            Tool Calling             β”‚
β”‚                                                     β”‚               β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚                  Tool Registry (19 Tools)                     β”‚ β”‚
β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚
β”‚  β”‚ β€’ Market Data (10)  β€’ Watchlist (3)  β€’ Portfolio (3)        β”‚ β”‚
β”‚  β”‚ β€’ Price Alerts (3)  β€’ Technical Analysis & Bandarmologi     β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                                                                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”‚
β”‚  β”‚    GoAPI     β”‚     β”‚   Supabase   β”‚     β”‚    Alert     β”‚      β”‚
β”‚  β”‚  IDX Data    β”‚     β”‚  PostgreSQL  β”‚     β”‚   Worker     β”‚      β”‚
β”‚  β”‚ + Retry Logicβ”‚     β”‚   (Cloud)    β”‚     β”‚  (Background)β”‚      β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚
β”‚                                                                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚             AI Providers (Dual Architecture)                 β”‚ β”‚
β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚
β”‚  β”‚  Primary: AI Aggregator (gpt-4o) + Fallback: Gemini 2.0    β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ› οΈ Technology Stack

Layer Technology Version Purpose
Runtime Node.js 24.x Server-side JavaScript execution
Language TypeScript 6.0 Type-safe development with latest features
Bot Framework Telegraf 4.x Telegram Bot API wrapper with middleware
AI Orchestration Vercel AI SDK 6.x LLM tool calling & streaming responses
Database Supabase 2.x Cloud PostgreSQL with Row Level Security
HTTP Server Express 5.x Webhook mode routing & health checks
HTTP Client Axios 1.x External API requests with retry logic
Validation Zod 4.x Runtime schema validation & type inference
Chart Rendering QuickChart.io API Serverless chart generation (no dependencies)

πŸ”Œ External Integrations

  • GoAPI - Real-time Indonesian stock market data provider (IDX)
  • AI Aggregator - Primary LLM provider (OpenAI-compatible endpoint)
  • Google Gemini - Fallback LLM provider (automatic failover)
  • Supabase - Managed PostgreSQL database with real-time subscriptions
  • QuickChart.io - Chart rendering service (30-day historical data)

🎯 Core Features Deep-Dive

1. πŸ”” Advanced Price Alerts Engine

Production-Grade Alert System with Zero-Spam Guarantee

Anti-Spam Batch Notification System

Multiple alerts triggered for the same user are automatically consolidated into a single beautiful HTML message:

Before Optimization:

User has 3 alerts triggered
❌ Sends 3 separate messages (notification spam)

After Optimization:

User has 3 alerts triggered
βœ… Sends 1 consolidated message (batch notification)

Benefits:

  • πŸ“‰ 60-80% reduction in Telegram messages
  • 🎨 Premium HTML formatting with monospace alignment
  • πŸ“Š Summary statistics (total count, average price)
  • πŸš€ Better user experience (no spam)

Example Batch Notification:

πŸ”” BATCH ALERT TRIGGERED

Anda memiliki 3 alert yang terpicu!

━━━━━━━━━━━━━━━━━━━━━━━━━

1. 🟒 BBCA
   πŸ’° Rp 5.600 🟒 +0.90%
   🎯 Target di atas Rp 5.500

2. 🟒 BBRI πŸ“Š
   πŸ’° Rp 5.250 🟒 +5.00%
   πŸ“Š +5% dari Rp 5.000

3. πŸ”΄ TLKM πŸ›‘οΈ
   πŸ’° Rp 3.990 πŸ”΄ -4.80%
   πŸ›‘οΈ Drop 5% dari high Rp 4.200

━━━━━━━━━━━━━━━━━━━━━━━━━

πŸ“ˆ RINGKASAN
Total Alert  : 3
Rata-rata    : Rp 4.947
Status       : Semua dinonaktifkan

βœ… Semua alert telah dinonaktifkan

Exponential Backoff Retry Mechanism

Resilient API calls to GoAPI with intelligent retry logic:

  • 3 retry attempts with exponential backoff (1s β†’ 2s β†’ 4s)
  • Β±20% jitter to prevent thundering herd problem
  • Comprehensive logging with attempt tracking
  • Graceful degradation (worker continues despite failures)

Retry Flow:

Attempt 1: Immediate execution
  ↓ (fails)
Attempt 2: Wait ~1s with jitter (800ms - 1200ms)
  ↓ (fails)
Attempt 3: Wait ~2s with jitter (1600ms - 2400ms)
  ↓ (fails)
Attempt 4: Wait ~4s with jitter (3200ms - 4800ms)
  ↓ (still fails)
Skip symbol, continue with next

Handled Scenarios:

  • βœ… Network timeouts
  • βœ… API rate limits (HTTP 429)
  • βœ… Transient failures
  • βœ… Invalid responses
  • βœ… Missing data

Configurable Worker Interval

Customize alert checking frequency via environment variable:

# Alert check interval in milliseconds
# Default: 120000ms (2 minutes)
# Recommended range: 60000-300000ms (1-5 minutes)
ALERT_CHECK_INTERVAL_MS=120000

Tradeoffs:

Interval Responsiveness API Usage Server Load
1 min (60000ms) ⚑ High πŸ“ˆ High πŸ”₯ High
2 min (120000ms) βš–οΈ Balanced πŸ“Š Moderate πŸ’š Low
5 min (300000ms) 🐒 Slower πŸ“‰ Low πŸ’™ Minimal

Alert Types Supported

1. STATIC Alert - Fixed price targets

🎯 PRICE ALERT
━━━━━━━━━━━━━━━━━━━━━━━━━
πŸ“ˆ BBCA
πŸ’° Rp 5.600 🟒 +0.90%

🟒 Kondisi: Harga naik di atas
🎯 Target: Rp 5.500

πŸ“Š DATA PASAR
Open     : Rp 5.550
High     : Rp 5.650
Low      : Rp 5.500
Perubahan: +50 (0.90%)
Volume   : 124.12M

2. PERCENTAGE Alert - Relative movement triggers

πŸ“Š PERCENTAGE ALERT
━━━━━━━━━━━━━━━━━━━━━━━━━
πŸ“ˆ BBRI
πŸ’° Rp 5.250 🟒 +5.00%

🟒 Kondisi: Naik 5%
πŸ“ Harga Base: Rp 5.000
🎯 Target: Rp 5.400
πŸ“Š Perubahan: 5.00%

3. TRAILING STOP Alert - Dynamic protection

πŸ›‘οΈ TRAILING STOP
━━━━━━━━━━━━━━━━━━━━━━━━━
πŸ“ˆ TLKM
πŸ’° Rp 3.990 πŸ”΄ -4.80%

πŸ”΄ Kondisi: Turun 5% dari high
πŸ”οΈ Day High: Rp 4.200
🎯 Threshold: Rp 3.990
πŸ“‰ Drop: 5.00%

2. πŸ“Š Watchlist & Portfolio Management

Cloud-Synchronized Personal Stock Tracking

Watchlist Features

  • βœ… Add/remove stocks with natural language
  • βœ… View real-time prices for all tracked stocks
  • βœ… Persistent storage in Supabase
  • βœ… Per-user isolation with chat_id indexing

Example Commands:

"Tambahkan BBCA ke watchlist"
"Tampilkan watchlist saya"
"Hapus TLKM dari watchlist"

Portfolio Tracking

  • βœ… Record average purchase price per stock
  • βœ… Track total lots owned
  • βœ… Calculate profit/loss automatically
  • βœ… View portfolio summary with current valuations

Example Commands:

"Tambah BBRI ke portfolio, harga rata-rata 5000, total 10 lot"
"Tampilkan portfolio saya"
"Hapus ASII dari portfolio"

3. πŸ“ˆ Market Data & Analytics

Comprehensive Indonesian Stock Exchange (IDX) Data

Available Market Queries

Real-Time Prices:

"Berapa harga BBCA sekarang?"
"Cek harga TLKM"

Market Summary:

"Bagaimana kondisi pasar hari ini?"
"Gimana IHSG hari ini?"

Top Movers:

"Saham apa yang naik tertinggi?"
"Top losers hari ini?"

Stock Comparison:

"Bandingkan BBRI dan BBNI"
"Compare ASII vs UNTR"

Historical Data:

"Data historis TLKM 30 hari terakhir"
"Grafik harga BBCA"

Fundamentals:

"Fundamental ASII"
"Analisa fundamental BBRI"

Technical Indicators

Supported Indicators:

  • RSI (14-period) - Overbought/oversold momentum
  • MACD (12/26/9) - Trend-following momentum
  • Moving Averages - SMA 20, EMA 20, SMA 50
  • Support/Resistance - Dynamic levels from 30-day data

Example:

"RSI TLKM berapa sekarang?"
"MACD BBRI gimana?"
"Analisa teknikal BBCA"

4. πŸ’Ό Bandarmologi & Institutional Flow Analysis

Track Smart Money and Institutional Trading Patterns

Broker Summary

  • Top 3 broker accumulation/distribution classification
  • Daily trading volume by broker house
  • Net buy/sell positioning

Example:

"Bandarmologi BBCA"
"Broker summary TLKM"

Foreign Flow Analysis

  • Net foreign investor positioning
  • 1-day, 5-day, and 20-day flow tracking
  • Foreign ownership percentage trends

Example:

"Foreign flow TLKM"
"Asing masuk BBRI?"

Liquidity Flow Sentiment

  • Combined institutional sentiment analysis
  • Sentiment scale: VERY_BULLISH β†’ VERY_BEARISH
  • Smart money tracking algorithms

Example:

"Liquidity flow UNTR"
"Bandar akumulasi ASII?"

5. πŸ“Š Chart Visualization

Professional 30-Day Historical Charts

  • Serverless rendering via QuickChart.io API
  • No native dependencies required
  • Automatic caching (60 seconds)
  • Support for all IDX stocks

Example:

"Tampilkan chart BBCA"
"Grafik harga TLKM"

βš™οΈ Environment Variables

Create a .env file in the project root:

# ============================================
# TELEGRAM CONFIGURATION
# ============================================
# Your Telegram bot token from @BotFather
TELEGRAM_BOT_TOKEN=your-telegram-bot-token

# ============================================
# MARKET DATA API
# ============================================
# GoAPI key for Indonesian stock market data
GOAPI_KEY=your-goapi-key

# ============================================
# AI PROVIDERS
# ============================================
# AI Aggregator (Primary)
AGGREGATOR_API_KEY=your-aggregator-api-key
AGGREGATOR_BASE_URL=https://lite.koboillm.com/v1
AGGREGATOR_MODEL=openai/gpt-4o

# Google Gemini (Fallback - activated on primary rate limit)
GOOGLE_GENERATIVE_AI_API_KEY=your-google-ai-api-key

# ============================================
# DATABASE (SUPABASE)
# ============================================
# Supabase project URL (Dashboard β†’ Settings β†’ API)
SUPABASE_URL=https://your-project.supabase.co

# Supabase service role key (Dashboard β†’ Settings β†’ API)
# ⚠️ WARNING: Keep this secret! Never expose to client-side code.
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key

# ============================================
# SERVER CONFIGURATION
# ============================================
# Application mode: development (polling) | production (webhook)
NODE_ENV=development

# Server port (used in production webhook mode)
PORT=3000

# ============================================
# ALERT WORKER CONFIGURATION
# ============================================
# Alert check interval in milliseconds (how often to check active price alerts)
# Default: 120000ms (2 minutes)
# Recommended range: 60000-300000ms (1-5 minutes)
# 
# Lower values:
#   βœ… More responsive alerts (faster notifications)
#   ❌ Higher GoAPI usage (more frequent price checks)
#   ❌ Increased server load
# 
# Higher values:
#   βœ… Reduced API calls (lower costs)
#   βœ… Lower server resource usage
#   ❌ Slower alert responses (delayed notifications)
#
# Production recommendation: 120000ms (2 minutes) - balanced approach
ALERT_CHECK_INTERVAL_MS=120000

Environment Variable Reference

Variable Required Default Description
TELEGRAM_BOT_TOKEN βœ… - Bot authentication token from @BotFather
GOAPI_KEY βœ… - API key for GoAPI stock market data
AGGREGATOR_API_KEY βœ… - AI Aggregator API key (primary LLM provider)
AGGREGATOR_BASE_URL ❌ https://lite.koboillm.com/v1 AI Aggregator endpoint URL
AGGREGATOR_MODEL ❌ openai/gpt-4o Model identifier for AI Aggregator
GOOGLE_GENERATIVE_AI_API_KEY βœ… - Google Gemini API key (fallback provider)
SUPABASE_URL βœ… - Your Supabase project URL
SUPABASE_SERVICE_ROLE_KEY βœ… - Supabase service role key (backend only)
NODE_ENV ❌ development Application environment mode
PORT ❌ 3000 HTTP server port (production webhook only)
ALERT_CHECK_INTERVAL_MS ❌ 120000 Alert worker check interval in milliseconds

πŸš€ Local Setup

Prerequisites

Installation Steps

1. Clone the Repository

git clone https://github.com/prstyaDev/ihsg-analytics-bot.git
cd ihsg-analytics-bot

2. Install Dependencies

npm install

3. Configure Environment

cp .env.example .env

Edit .env with your actual credentials.

4. Database Setup

The bot uses Supabase PostgreSQL with automatic schema migrations. Tables are created automatically when you connect the repository to your Supabase project via GitHub Integration.

Required Tables:

  • watchlist - Personal stock tracking lists
  • alerts - Price alert configurations
  • portfolio - User portfolio holdings

5. Run Development Server

npm run dev

The bot will start in polling mode (no webhook required for local development).

6. Production Build

npm run build
npm start

🚒 Production Deployment

Deployment Modes

1. Polling Mode (Development)

  • No public domain required
  • Uses Telegram long polling
  • Ideal for local testing

2. Webhook Mode (Production)

  • Requires public domain with SSL
  • More efficient for high traffic
  • Recommended for production

Production Configuration

Environment:

NODE_ENV=production
PORT=3000
ALERT_CHECK_INTERVAL_MS=120000

Webhook Setup:

curl -X POST "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook" \
  -d "url=https://yourdomain.com/telegram-webhook"

Recommended Platforms

☁️ Railway

  • Zero-config deployment
  • Automatic HTTPS
  • Free tier available
  • One-click deploy

☁️ Heroku

  • Hobby tier with worker dynos
  • Add-ons for PostgreSQL
  • Easy scaling

☁️ Fly.io

  • Global edge deployment
  • Automatic SSL certificates
  • Docker-based deployment

☁️ VPS (DigitalOcean, Linode, AWS EC2)

  • Full control
  • Nginx reverse proxy
  • PM2 process manager
  • Manual SSL with Certbot

Production Checklist

  • βœ… Set NODE_ENV=production
  • βœ… Configure webhook URL
  • βœ… Set up reverse proxy (Nginx)
  • βœ… Enable HTTPS/SSL
  • βœ… Configure firewall rules
  • βœ… Set up monitoring (PM2, Datadog)
  • βœ… Configure log rotation
  • βœ… Set up database backups
  • βœ… Test alert worker startup
  • βœ… Verify batch notifications

πŸ“ Project Structure

ihsg-bot/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ index.ts                 # Application entry point
β”‚   β”œβ”€β”€ agent/
β”‚   β”‚   └── hermes.ts            # AI agent orchestration
β”‚   β”œβ”€β”€ bot/
β”‚   β”‚   └── index.ts             # Telegram bot handlers
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   └── env.ts               # Environment validation (Zod)
β”‚   β”œβ”€β”€ db/
β”‚   β”‚   └── index.ts             # Supabase client & queries
β”‚   β”œβ”€β”€ tools/
β”‚   β”‚   └── registry.ts          # Tool definitions (19 tools)
β”‚   β”œβ”€β”€ utils/
β”‚   β”‚   β”œβ”€β”€ chart.ts             # Chart generation utility
β”‚   β”‚   β”œβ”€β”€ retry.ts             # Exponential backoff retry
β”‚   β”‚   β”œβ”€β”€ technical.ts         # Technical indicators (RSI, MACD, MA)
β”‚   β”‚   β”œβ”€β”€ bandar.ts            # Bandarmologi & foreign flow
β”‚   β”‚   └── tradingHours.ts      # IDX trading hours logic
β”‚   └── workers/
β”‚       └── alertWorker.ts       # Background alert worker
β”œβ”€β”€ .env                         # Environment variables (gitignored)
β”œβ”€β”€ .env.example                 # Environment template
β”œβ”€β”€ .gitignore
β”œβ”€β”€ package.json
β”œβ”€β”€ tsconfig.json
└── README.md

πŸ›‘οΈ Error Handling

The bot implements comprehensive error handling at multiple layers:

Timeout Protection

// 120-second timeout for AI queries
if (queryErr.message === 'TIMEOUT_ERROR') {
  await ctx.reply("⏱ Maaf, pengambilan data market sedang padat, coba lagi sebentar lagi.");
}

AI Provider Failover

// Automatic fallback to Google Gemini
if (errStr.includes('RESOURCE_EXHAUSTED') || errStr.includes('rate_limit')) {
  console.log('[System] Menggunakan Fallback Google Gemini...');
  // Gemini handles the request
}

GoAPI Retry Logic

// Exponential backoff with 3 retries
await retryWithBackoff(
  async () => await api.get('/stock/idx/prices'),
  { maxRetries: 3, baseDelay: 1000, operationName: 'GoAPI price fetch' }
);

Database Connection Recovery

// Graceful degradation if database fails
if (!result.success) {
  console.warn('[System] Database connection failed - watchlist features may be unavailable');
  // Bot continues with limited functionality
}

πŸ§ͺ Testing

Manual Testing Scenarios

Alert Worker:

# Test with 2-minute interval
ALERT_CHECK_INTERVAL_MS=120000 npm run dev

# Test with aggressive 30-second interval
ALERT_CHECK_INTERVAL_MS=30000 npm run dev

Batch Notifications:

  1. Create 3 alerts for same user with different symbols
  2. Trigger all alerts in same cycle
  3. Verify single consolidated message received

Exponential Backoff:

  1. Use invalid GoAPI key
  2. Observe retry attempts in logs
  3. Verify worker continues with next symbol

🀝 Contributing

Contributions are welcome! Please follow these guidelines:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Code Standards:

  • TypeScript strict mode
  • ESLint compliance
  • Comprehensive error handling
  • JSDoc documentation for public APIs

πŸ“„ License

This project is licensed under the MIT License. See LICENSE file for details.


πŸ“ž Support


πŸ† Acknowledgments

  • GoAPI - Indonesian stock market data provider
  • Telegraf - Excellent Telegram Bot API framework
  • Supabase - Managed PostgreSQL with real-time features
  • Vercel AI SDK - Powerful LLM orchestration toolkit
  • QuickChart.io - Serverless chart rendering

Built with ❀️ by prstyaDev

About

β€‹πŸ“ˆ Smart IHSG Analytics Bot featuring real-time stock monitoring, natural language price alerts worker, and cloud-rendered charts. Powered by TypeScript, Supabase (PostgreSQL), and GoAPI.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages