Skip to content

Commit 941833c

Browse files
committed
Update - use webhook.site endpoint
1 parent 380e0db commit 941833c

1 file changed

Lines changed: 13 additions & 31 deletions

File tree

news-recommend/index.html

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6-
<title>新闻推荐 - 外部端点版</title>
6+
<title>新闻推荐</title>
77
<script src="https://telegram.org/js/telegram-web-app.js"></script>
88
<style>
99
* { margin: 0; padding: 0; box-sizing: border-box; }
@@ -22,13 +22,12 @@
2222
.submit-area { position: fixed; bottom: 0; left: 0; right: 0; background: #1a1a2e; border-top: 1px solid #333; padding: 16px; }
2323
.btn { background: #00ff88; color: #000; border: none; padding: 12px; border-radius: 8px; font-size: 15px; font-weight: 600; cursor: pointer; width: 100%; margin: 8px 0; }
2424
.btn:disabled { opacity: 0.5; }
25-
.btn-secondary { background: #333; color: #fff; }
2625
.log { background: #000; padding: 8px; border-radius: 6px; font-size: 10px; color: #0f0; margin-top: 12px; max-height: 100px; overflow-y: auto; }
2726
</style>
2827
</head>
2928
<body>
3029
<h1>📰 新闻推荐</h1>
31-
<div class="status" id="status">已连接 Telegram | 用户:<span id="userName">...</span></div>
30+
<div class="status">数据发送到 Webhook | <a href="https://webhook.site/105b6159-c20c-4212-ada3-091967d4df4d" target="_blank" style="color:#00ff88">查看数据</a></div>
3231

3332
<div class="category-filter" id="categoryFilter">
3433
<button class="category-btn active" data-category="all">全部</button>
@@ -41,14 +40,13 @@ <h1>📰 新闻推荐</h1>
4140

4241
<div class="submit-area">
4342
<div style="margin-bottom:12px">已选择 <span id="selectedCount" style="color:#00ff88;font-weight:bold">0</span></div>
44-
<button class="btn" id="sendBtn" disabled>📡 发送到外部端点</button>
45-
<button class="btn btn-secondary" id="tgBtn" disabled>📨 尝试 Telegram sendData</button>
43+
<button class="btn" id="sendBtn" disabled>📡 发送选择</button>
4644
<div class="log" id="log"></div>
4745
</div>
4846

4947
<script>
5048
const tg = window.Telegram.WebApp;
51-
const EXTERNAL_ENDPOINT = "https://httpbin.org/post";
49+
const WEBHOOK_URL = "https://webhook.site/105b6159-c20c-4212-ada3-091967d4df4d";
5250
const logs = [];
5351

5452
function log(msg) {
@@ -58,7 +56,6 @@ <h1>📰 新闻推荐</h1>
5856

5957
tg.ready(); tg.expand();
6058
const user = tg.initDataUnsafe?.user || {};
61-
document.getElementById("userName").textContent = user.username || user.first_name || "unknown";
6259
log("初始化完成");
6360

6461
const newsData = [
@@ -89,10 +86,9 @@ <h1>📰 新闻推荐</h1>
8986
const c = selectedIds.size;
9087
document.getElementById("selectedCount").textContent = c;
9188
document.getElementById("sendBtn").disabled = c === 0;
92-
document.getElementById("tgBtn").disabled = c === 0;
9389
}
9490

95-
async function sendToExternal() {
91+
async function send() {
9692
const selected = newsData.filter(n => selectedIds.has(n.id));
9793
const data = {
9894
type: "news_selection",
@@ -103,40 +99,26 @@ <h1>📰 新闻推荐</h1>
10399

104100
const btn = document.getElementById("sendBtn");
105101
btn.disabled = true; btn.textContent = "发送中...";
106-
log("发送到外部端点...");
102+
log("发送到 Webhook...");
107103

108104
try {
109-
const res = await fetch(EXTERNAL_ENDPOINT, {
105+
const res = await fetch(WEBHOOK_URL, {
110106
method: "POST",
111107
headers: {"Content-Type": "application/json"},
112108
body: JSON.stringify(data)
113109
});
114-
const result = await res.json();
115-
log("✅ 发送成功!");
116-
log(`状态码:${res.status}`);
117-
btn.textContent = "✅ 已发送";
118-
btn.className = "btn btn-secondary";
119-
120-
// 显示结果
121-
setTimeout(() => {
122-
log("请查看 httpbin.org 返回的数据");
123-
log("我来监控并回复你!");
124-
}, 2000);
110+
log(`✅ 发送成功!状态码:${res.status}`);
111+
btn.textContent = "✅ 已发送 - 等待回复";
112+
btn.className = "btn";
113+
btn.style.background = "#333";
114+
log("请等待 Bot 回复...");
125115
} catch (e) {
126116
log(`❌ 失败:${e.message}`);
127117
btn.disabled = false; btn.textContent = "🔄 重试";
128118
}
129119
}
130120

131-
function sendToTelegram() {
132-
const selected = newsData.filter(n => selectedIds.has(n.id));
133-
const data = { type: "news_selection", selected };
134-
try { tg.sendData(JSON.stringify(data)); log("✅ sendData 调用成功"); setTimeout(()=>tg.close(),1500); }
135-
catch(e) { log(`❌ sendData 失败:${e.message}`); }
136-
}
137-
138-
document.getElementById("sendBtn").onclick = sendToExternal;
139-
document.getElementById("tgBtn").onclick = sendToTelegram;
121+
document.getElementById("sendBtn").onclick = send;
140122
document.getElementById("categoryFilter").onclick = e => {
141123
if (e.target.classList.contains("category-btn")) {
142124
document.querySelectorAll(".category-btn").forEach(b => b.classList.remove("active"));

0 commit comments

Comments
 (0)