Web app Telegram.WebApp.sendData event on bot's side #1206
Unanswered
nightrider77
asked this question in
Q&A
Replies: 1 comment 1 reply
-
const TelegramBot = require('node-telegram-bot-api');
const TOKEN = 'YOUR_BOT_TOKEN';
const bot = new TelegramBot(TOKEN, { polling: true });
// Handle /start command to send an initial message
bot.on('message', (msg) => {
if (msg.text.toString() === '/start') {
bot.sendMessage(msg.chat.id, 'Hello! Click the button below to send data from the Web App.', {
reply_markup: {
inline_keyboard: [
[{ text: 'Send Data', callback_data: 'get_web_app_data' }],
],
},
});
}
});
// Handle the callback query from the button
bot.on('callback_query', (query) => {
if (query.data === 'get_web_app_data') {
const webAppData = query.message.web_app_data; // Access data here!
bot.sendMessage(query.message.chat.id, `Web App Data: ${webAppData?.data}`);
}
}); |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to send some data in my web app to my bot:
Telegram.WebApp.sendData("test_data");
But I don't see any event on bot's side, like "message" or "callback_query" with my data inside.
Am I missing something?
Beta Was this translation helpful? Give feedback.
All reactions