// config/telegram.config.js require('dotenv').config(); const TELEGRAMBOTTOKEN =…
- User
// config/telegram.config.js require('dotenv').config();
const TELEGRAM_BOT_TOKEN = process.env.TELEGRAM_BOT_TOKEN; const WEBHOOK_URL = process.env.WEBHOOK_URL; const WEB_APP_URL = 'https://gremdev-bae993ec0ba0.herokuapp.com/'; // Web uygulamanızın URL'si
if (!TELEGRAM_BOT_TOKEN || !WEBHOOK_URL || !WEB_APP_URL) { console.error('Config vars are missing'); process.exit(1); }
module.exports = { TELEGRAM_BOT_TOKEN, WEBHOOK_URL, WEB_APP_URL, };
// routes/botRoutes.js
const express = require('express'); const { sendMenu } = require('../config/hook'); // Menü gönderme fonksiyonunu import edin
const router = express.Router();
// Telegram webhook callback endpoint router.post('/webhook', (req, res) => { const { message } = req.body;
if (message && message.text) { const chatId = message.chat.id; if (message.text === '/start') { // Kullanıcı start komutunu gönderdiğinde menüyü gönder sendMenu(chatId); } else { // Diğer mesajlar için genel bir yanıt console.log(
Received message: ${message.text}); } }res.sendStatus(200); });
module.exports = router;
// config/hook.js
const fetch = require('node-fetch'); const { TELEGRAM_BOT_TOKEN, WEBHOOK_URL } = require('./tlgconfig');
// Webhook ayarları yapma fonksiyonu const setWebhook = async () => { try { const response = await fetch(
https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/setWebhook?url=${WEBHOOK_URL});if (!response.ok) throw new Error('Webhook ayarları yapılamadı'); const result = await response.json(); console.log('Webhook ayarları başarıyla yapıldı:', result);} catch (error) { console.error('Webhook ayarları yapılırken bir hata oluştu:', error); } };
// Mesaj gönderme fonksiyonu const sendMenu = async (chatId) => { try { const response = await fetch(
https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ chat_id: chatId, text: 'Menüyü seçin:', reply_markup: { keyboard: [ [ { text: 'Oyun Başla', web_app: { url: WEB_APP_URL } } ] ], resize_keyboard: true } }), });if (!response.ok) throw new Error('Menü gönderilemedi'); console.log('Menü başarıyla gönderildi');} catch (error) { console.error('Menü gönderirken bir hata oluştu:', error); } };
module.exports = { setWebhook, sendMenu };
--
// app.js (veya index.js)
const express = require('express'); const bodyParser = require('body-parser'); const cors = require('cors'); require('dotenv').config();
- Assistant
- User
startapp - Play Game help - help menu - Show main menu
menu bu şekilde /startapp de WEB_APP_URL olacka.
- Assistant
- User
de çalışmıyor işte bu şekilde
- Assistant