A powerful Telegram bot that generates beautiful, visual cards for real-time stock quotes and weather information. Built with Firebase Cloud Functions, GrammY, and server-side image generation.
Query a single stock with $AAPL to get a detailed card:
Features displayed:
- Current price with daily change percentage
- Year-to-Date (YTD) performance
- YTD vs SPY comparison (S&P 500 benchmark)
Query multiple stocks at once with $AAPL $MSFT $GOOG:
Features displayed:
- Up to 10 stocks in a single card
- Alphabetically sorted by ticker
- Compact view with price, change %, YTD, and YTD vs SPY
Get real-time weather with Weather City:
Daytime vs Nighttime The card automatically adapts its theme and units based on location and time of day.
| Daytime (Tokyo - Metric) | Nighttime (New York - Imperial) |
|---|---|
![]() |
![]() |
Features:
- Smart Theme: Light mode for day, Dark mode for night
- Auto-Units: Imperial (F, mph) for US, Metric (C, km/h) for others
- Hourly Forecast: Next 6 hours trends
- Detailed Metrics: Feels like, Wind, Humidity, Visibility
- Real-time prices via Yahoo Finance API
- Single stock queries:
$AAPL,$TSLA,$GOOG - Multi-stock queries:
$AAPL $MSFT $AMZN $NVDA(up to 10 stocks) - Alphabetical sorting for multi-stock cards
- YTD Performance: Calculated using the close price of the first trading day of the year
- SPY Comparison: Shows how the stock performs vs the S&P 500 benchmark
- Color-coded values: Green for gains, red for losses
- City-based queries:
Weather London,Weather New York - City-based queries:
Weather London,Weather New York - Smart Units: Automatically uses Fahrenheit/Miles for US and Celsius/Kilometers for the rest of the world.
- Dynamic Themes: Changes between Light (Day) and Dark (Night) modes based on local time.
- Detailed Forecast: Hourly trend chart and key metrics.
- Web Dashboard: comprehensive management of groups, history, and status.
- Group Management: View details, history, and ban/unban groups.
- Strict Security: Bot only responds to registered, active, and unblocked groups.
- Notifications: Automated alerts sent to groups upon ban/unblock.
- Activity Stats: Track message and image generation counts per group.
- Server-side PNG generation using Satori + Resvg
- Dark theme with professional styling
- Custom Roboto font rendering
- Dynamic sizing for multi-stock cards
AI-Telegram/
βββ firebase.json # Firebase configuration (Functions + Hosting)
βββ firestore.indexes.json # Database indexes
βββ .github/
β βββ workflows/ # CI/CD Workflows
βββ dashboard/ # Next.js Admin Dashboard
β βββ src/
β β βββ app/ # App Router
β β βββ components/ # Reusable UI components (Tables, Dialogs, etc.)
β β βββ lib/ # API Client & Firebase Auth
βββ functions/
β βββ src/
β β βββ index.ts # Firebase Functions entry point
β β βββ bot.ts # GrammY bot handlers
β β βββ admin.ts # Admin API backend
β β βββ generator/
β β β βββ card.tsx # React components for card generation
β β βββ services/
β β βββ db.ts # Firestore Database Service
β β βββ stock.ts # Yahoo Finance integration
β β βββ weather.ts # Weather API integration
β βββ set-admin.js # Admin claim utility script
β βββ assets/
β β βββ fonts/ # Roboto font files
β βββ package.json
β βββ tsconfig.json
βββ docs/
βββ screenshots/ # Documentation images
| Component | Technology |
|---|---|
| Runtime | Node.js 20 |
| Cloud Functions | Firebase Functions (2nd Gen) |
| Bot Framework | GrammY |
| Stock Data | Yahoo Finance API (yahoo-finance2) |
| Image Generation | Satori (SVG) + Resvg (PNG) |
| Language | TypeScript |
- Node.js 20+
- Firebase CLI (
npm install -g firebase-tools) - A Telegram Bot Token (from @BotFather)
-
Clone the repository
git clone https://github.com/yourusername/AI-Telegram.git cd AI-Telegram -
Install dependencies
cd functions npm install -
Configure environment variables
Create
functions/.env:TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here
-
Build the project
npm run build
cd functions
npm run serveThis will:
- Build the TypeScript code
- Start the Firebase Functions emulator on
http://127.0.0.1:5001 - Watch for file changes
You'll need to expose your local server to the internet. Use ngrok or a similar tunneling service:
# In a separate terminal
ngrok http 5001Then set your Telegram webhook:
curl -X POST "https://api.telegram.org/bot<YOUR_TOKEN>/setWebhook" \
-H "Content-Type: application/json" \
-d '{"url": "https://your-ngrok-url.ngrok.io/demo-test/us-central1/telegramWebhook"}'Once the webhook is set, test in Telegram:
| Command | Description |
|---|---|
/start |
Show welcome message and help |
$AAPL |
Get Apple stock card |
$AAPL $MSFT $GOOG |
Get multi-stock card |
Weather London |
Get weather card for London |
/start |
Activate bot interactions in current group (Admins only) |
/stop |
Deactivate bot interactions in current group (Admins only) |
-
Login to Firebase
firebase login
-
Select your project
firebase use your-project-id
-
Set environment secrets
firebase functions:secrets:set TELEGRAM_BOT_TOKEN
-
Deploy Functions & Dashboard
Option A: GitHub Actions (Recommended)
- Push to the
antigravitybranch. - The workflow
firebase-deploy.ymlwill automatically build and deploy both Functions and Dashboard. - Ensure you set these Repository Secrets in GitHub:
TELEGRAM_BOT_TOKENGOOGLE_MAPS_API_KEYFIREBASE_SERVICE_ACCOUNT_KEY(JSON content)NEXT_PUBLIC_FIREBASE_API_KEYNEXT_PUBLIC_FIREBASE_AUTH_DOMAINNEXT_PUBLIC_FIREBASE_PROJECT_ID
Option B: Manual Deployment
# Deploy everything firebase deploy # Deploy only functions firebase deploy --only functions # Deploy only dashboard firebase deploy --only hosting
- Push to the
To access the dashboard, your user account must have the admin custom claim.
-
Generate Service Account Key:
- Go to Firebase Console -> Project Settings -> Service accounts.
- Generate new private key.
- Save as
functions/service-account.json.
-
Run the Script:
cd functions export GOOGLE_APPLICATION_CREDENTIALS="./service-account.json" node set-admin.js your-email@example.com
-
Sign In: Log out and log back in to the dashboard to refresh your token.
After deployment, set the webhook to your production URL:
curl -X POST "https://api.telegram.org/bot<YOUR_TOKEN>/setWebhook" \
-H "Content-Type: application/json" \
-d '{"url": "https://us-central1-your-project.cloudfunctions.net/telegramWebhook"}'The bot calculates Year-to-Date performance using the correct Yahoo Finance methodology:
YTD % = ((Current Price - Year Start Price) / Year Start Price) Γ 100
Year Start Price = Close price of the first trading day of the year (typically Jan 2nd)
This matches the official YTD values displayed on Yahoo Finance.
| Script | Description |
|---|---|
npm run build |
Compile TypeScript to JavaScript |
npm run build:watch |
Watch mode for development |
npm run serve |
Build and start Firebase emulator |
npm run deploy |
Deploy to Firebase |
npm run logs |
View Firebase function logs |
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'feat: Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the ISC License.
- GrammY - Telegram Bot Framework
- Satori - SVG generation from React
- yahoo-finance2 - Yahoo Finance API wrapper
- Firebase - Cloud Functions hosting
Made with β€οΈ by iRedlof Team



