Add Telegram answer learning: poller + applier safety net

- New lib/telegram_answers.mjs: shared module that polls Telegram getUpdates,
  matches replies to needs_answer jobs, saves to answers.json, flips job to new
- telegram_poller.mjs: lightweight cron script (every minute via OpenClaw)
- Applier also processes replies at start of each run as safety net
- sendTelegram now returns message_id, stored on job for reply matching
- User replies "ACCEPT" to use AI answer, or types their own
- Answers persist in answers.json and apply to ALL future jobs
- Also includes: selectOptionFuzzy, multiple dialog handling, browser
  recovery, answers reload, per-job timeout bump to 10min

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-06 11:38:37 -08:00
parent 14cf9a12c1
commit 0920554dad
4 changed files with 250 additions and 11 deletions

21
telegram_poller.mjs Normal file
View File

@@ -0,0 +1,21 @@
#!/usr/bin/env node
/**
* telegram_poller.mjs — Polls Telegram for replies to question messages
*
* Run via OpenClaw cron: * * * * * (every minute)
* Lightweight — single HTTP call, exits immediately if no updates.
*/
import { loadEnv } from './lib/env.mjs';
loadEnv();
import { resolve, dirname } from 'path';
import { fileURLToPath } from 'url';
import { loadConfig } from './lib/queue.mjs';
import { processTelegramReplies } from './lib/telegram_answers.mjs';
const __dir = dirname(fileURLToPath(import.meta.url));
const settings = loadConfig(resolve(__dir, 'config/settings.json'));
const answersPath = resolve(__dir, 'config/answers.json');
const processed = await processTelegramReplies(settings, answersPath);
if (processed > 0) console.log(`Processed ${processed} answer(s)`);