const TelegramBot = require('node-telegram-bot-api');
const express = require('express');
const path = require('path');

// Replace with your Telegram bot token
const token = '7156396550:AAHDZpktrcJhFv2xYP9mlS__WD8E2WUu1JM';

// Create a bot that uses 'polling' to fetch new updates
const bot = new TelegramBot(token, { polling: true });

// Create an Express app to serve your WebGL game
const app = express();
const port = process.env.PORT || 3000;

// Serve static files from the 'public' directory
app.use(express.static(path.join(__dirname, 'public')));

// Define a route to handle incoming requests and serve the WebGL game
app.get('/', (req, res) => {
  res.sendFile(path.join(__dirname, 'public', 'index.html'));
});

// Start the Express server
app.listen(port, () => {
  console.log(`Server is running on http://localhost:${port}`);
});

// Listen for incoming messages from Telegram
bot.on('message', (msg) => {
  const chatId = msg.chat.id;

  // Respond to '/start' command
  if (msg.text.toString().toLowerCase() === '/start') {
    const imagePath = path.join(__dirname, 'public', 'icon.png');

    bot.sendPhoto(chatId, imagePath, {
        caption: 'Welcome! Click the button below to play Shiba Chef Game.',
        reply_markup: {
            inline_keyboard: [
                [{
                    text: 'Click to Play',
                    url: `https://noumantecshield.github.io/ShibaChef_test/`
                }]
            ]
        }
    });
  }
});

console.log('Bot is running...');
