Spaces:
Running
Update index.html
Browse filesfrom telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup, WebAppInfo
from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes
BOT_TOKEN = "YOUR_BOT_TOKEN"
HF_URL = "https://your-space-name.hf.space"
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
keyboard = [[
InlineKeyboardButton(
"Open App 🚀",
web_app=WebAppInfo(url=HF_URL)
)
]]
reply_markup = InlineKeyboardMarkup(keyboard)
await update.message.reply_text("Click below:", reply_markup=reply_markup)
async def receive_data(update: Update, context: ContextTypes.DEFAULT_TYPE):
data = update.effective_message.web_app_data.data
await update.message.reply_text(f"Received: {data}")
app = ApplicationBuilder().token(BOT_TOKEN).build()
app.add_handler(CommandHandler("start", start))
app.run_polling()
- index.html +21 -17
|
@@ -1,19 +1,23 @@
|
|
| 1 |
-
<!
|
| 2 |
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
</html>
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
<html>
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<title>Telegram Web App</title>
|
| 6 |
+
<script src="https://telegram.org/js/telegram-web-app.js"></script>
|
| 7 |
+
</head>
|
| 8 |
+
<body>
|
| 9 |
+
<h2>Welcome 👋</h2>
|
| 10 |
+
<p>This app is opened from Telegram.</p>
|
| 11 |
+
|
| 12 |
+
<button onclick="sendData()">Send Data to Bot</button>
|
| 13 |
+
|
| 14 |
+
<script>
|
| 15 |
+
const tg = window.Telegram.WebApp;
|
| 16 |
+
tg.ready();
|
| 17 |
+
|
| 18 |
+
function sendData() {
|
| 19 |
+
tg.sendData("Hello from Hugging Face!");
|
| 20 |
+
}
|
| 21 |
+
</script>
|
| 22 |
+
</body>
|
| 23 |
</html>
|