-
Notifications
You must be signed in to change notification settings - Fork 690
Description
找到问题所在了 🎯
Moltworker 的致命缺陷:它根本没有 Telegram webhook 路由!
分析结果
从 moltworker 代码看:
✅ 有的部分:
配置 TELEGRAM_BOT_TOKEN 到 Moltbot 网关(在 start-moltbot.sh)
启动 Moltbot 网关
代理所有请求到网关
❌ 缺失的部分:
没有 /telegram/webhook 路由
没有处理 Telegram 的 POST 请求
没有转发 Telegram 消息到网关
文件清单(src/routes/)只有:
- public.ts (健康检查)
- api.ts (admin API)
- admin-ui.ts (管理界面)
- debug.ts (调试)
- cdp.ts (Browser API)
- 【没有 telegram.ts】
真正的问题
Moltworker 仅仅配置了 token,但没有告诉 Cloudflare Workers 如何接收和转发 Telegram 消息。
你的 Telegram bot 现在处于"无人接听"状态:
✅ Bot token 有效
✅ Bot 已启用
❌ Webhook 没配置(或无处理)
解决方案
你需要自己添加 Telegram webhook 处理。在 moltworker 中创建:
src/routes/telegram.ts
import { Hono } from 'hono';
import type { AppEnv } from '../types';
import { MOLTBOT_PORT } from '../config';
import { ensureMoltbotGateway } from '../gateway';
const telegram = new Hono();
telegram.post('/webhook', async (c) => {
const sandbox = c.get('sandbox');
const body = await c.req.text();
// Ensure gateway is running
await ensureMoltbotGateway(sandbox, c.env);
// Forward to moltbot gateway's telegram handler
const response = await sandbox.containerFetch(
new Request('http://localhost:18789/channels/telegram/webhook', {
method: 'POST',
body: body,
headers: { 'Content-Type': 'application/json' },
}),
MOLTBOT_PORT
);
return new Response(response.body, { status: response.status });
});
export { telegram };
然后在 src/index.ts 中挂载:
app.route('/telegram', telegram);
然后设置 webhook:
curl -X POST
"https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/setWebhook"
-H "Content-Type: application/json"
-d "{"url":"https://your-worker.workers.dev/telegram/webhook\"}"
这是 moltworker 的一个重大遗漏。 建议向 Cloudflare 提交 issue 或自己 fork 修复。