Telegram Mini App: can't transfer data from mini app to bot - Stack Overflow

admin2025-04-18  3

I am writing a bot for Telegram using the python-telegram-bot library. I am connecting mini app to it. The application starts and can even receive data from the bot, but for some reason the data does not pass in the opposite direction: tg.sendData is called in the mini application, but the message handler in the bot is not called.

Update: I've explored various examples and implementations of mini-apps and discovered that replacing InlineKeyboardButton with KeyboardButton and InlineKeyboardMarkup with ReplyKeyboardMarkup makes data transmission work. Does this mean that InlineKeyboardButton cannot be used to launch mini-apps? However, I’ve seen bots that launch mini-apps using InlineKeyboardButton. Does this imply that additional steps are required to make it work with inline buttons?

The bot code:

from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup, WebAppInfo
from telegram.ext import Application, CommandHandler, MessageHandler, ContextTypes, filters
from telegram_token import TELEGRAM_TOKEN


async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
    keyboard = [
        [InlineKeyboardButton(
            "
转载请注明原文地址:http://anycun.com/QandA/1744921481a89514.html