Skip to main content
Back to Blog

Build a Telegram Bot for Pokemon Card Price Alerts

PokemonPriceTracker Team

•2 min read
Build a Telegram Bot for Pokemon Card Price Alerts

Build a Telegram Pokemon Price Alert Bot

Why Telegram Bots?

  • 300M+ active users (popular internationally)
  • Excellent bot API with webhooks
  • Built-in push notifications
  • Free serverless deployment

Quick Start

npm init -y
npm install telegraf dotenv axios

Create bot via @BotFather → /newbot

Complete Bot Code

const { Telegraf } = require('telegraf');
const axios = require('axios');

const bot = new Telegraf(process.env.TELEGRAM_BOT_TOKEN);
const API_KEY = process.env.POKEMON_API_KEY;
const API_BASE = 'https://www.pokemonpricetracker.com/api/v2';

// Store user alerts in memory (use database in production)
const userAlerts = new Map();

// /price command
bot.command('price', async (ctx) => {
  const cardName = ctx.message.text.split(' ').slice(1).join(' ');

  if (!cardName) {
    return ctx.reply('Usage: /price <card name>');
  }

  const response = await axios.post(
    `${API_BASE}/parse-title`,
    { title: cardName },
    { headers: { 'Authorization': `Bearer ${API_KEY}` } }
  );

  if (response.data.matches?.[0]) {
    const card = response.data.matches[0].card;
    ctx.reply(
      `💰 *${card.name}*\n` +
      `Set: ${card.setName}\n` +
      `Price: $${card.prices.market.toFixed(2)}`,
      { parse_mode: 'Markdown' }
    );
  }
});

// /alert command
bot.command('alert', async (ctx) => {
  const args = ctx.message.text.split(',');
  if (args.length < 2) {
    return ctx.reply('Usage: /alert <card name>, <target price>');
  }

  const cardName = args[0].replace('/alert', '').trim();
  const targetPrice = parseFloat(args[1].trim());

  const userId = ctx.from.id;

  if (!userAlerts.has(userId)) {
    userAlerts.set(userId, []);
  }

  userAlerts.get(userId).push({
    cardName,
    targetPrice,
    chatId: ctx.chat.id
  });

  ctx.reply(`✅ Alert set for ${cardName} at $${targetPrice}`);
});

bot.launch();

// Check alerts periodically
setInterval(async () => {
  for (const [userId, alerts] of userAlerts.entries()) {
    for (const alert of alerts) {
      // Check current price
      const response = await axios.post(
        `${API_BASE}/parse-title`,
        { title: alert.cardName },
        { headers: { 'Authorization': `Bearer ${API_KEY}` } }
      );

      if (response.data.matches?.[0]) {
        const currentPrice = response.data.matches[0].card.prices.market;

        if (currentPrice <= alert.targetPrice) {
          bot.telegram.sendMessage(
            alert.chatId,
            `🔔 *Price Alert!*\n${alert.cardName} is now $${currentPrice}!`,
            { parse_mode: 'Markdown' }
          );
        }
      }
    }
  }
}, 3600000); // Check hourly

Deploy to Vercel

// api/telegram-webhook.js
module.exports = async (req, res) => {
  if (req.method === 'POST') {
    await bot.handleUpdate(req.body);
    res.status(200).send('OK');
  } else {
    res.status(200).send('Bot is running');
  }
};

Get Free API Key →

PokemonPriceTracker Team

Related Articles

Stay Updated

Subscribe to our newsletter for the latest Pokemon card market trends, investment opportunities, and exclusive insights delivered straight to your inbox.