Fetch messages from a Telegram group and produce a structured summary.
Required Environment Variables
TELEGRAM_BOT_TOKEN— Telegram bot token (some runtimes may auto-inject it for Telegram-connected agents)OPENCLAW_STATE_DIR— (optional) directory containing raw Telegram JSON/JSONL history exports; defaults to/twin-data/state(a deployment convention, not a universal OpenClaw path)
$SKILL_DIR in the commands below means this skill's installed directory. If your agent does not set it automatically, replace it with the path to this telegram-group-summary directory before running commands.
Workflow
Step 1 — Resolve the group
Run list_groups.py from the telegram-send skill to see available groups:
python3 "$SKILL_DIR/../telegram-send/scripts/list_groups.py"
Match the user's requested group name (case-insensitive fuzzy match) to get its chat_id.
If the group is not listed, it may not have interacted with this bot/agent yet.
Step 2 — Fetch messages
python3 "$SKILL_DIR/scripts/fetch_messages.py" <chat_id>
Optional flags:
--limit N— cap the number of messages (default: 100)--since-hours N— only include messages from the last N hours (e.g.--since-hours 168for 7 days)
The script tries two sources in order:
- Raw Telegram history files — walks
$OPENCLAW_STATE_DIRfor.jsonand.jsonlfiles containing Telegram message objects (primary) - Bot API
getUpdates— falls back to pending unprocessed updates from the Telegram Bot API
Local records must contain numeric chat.id (or chat_id), an epoch-seconds
date, and text or caption; message_id and from are optional. JSON may
wrap these records in objects/arrays; JSONL contains one JSON value per line.
Native OpenClaw session envelopes, the sessions.json index, and SQLite stores
are not supported. Obtain a raw Telegram export in this schema before using
local history from such installations. The legacy output label openclaw_state
identifies the directory source, not native OpenClaw compatibility.
The output JSON has this shape:
{
"chat_id": -1001234567890,
"source": "openclaw_state",
"message_count": 83,
"time_range": {"earliest": "2026-05-26T08:00:00Z", "latest": "2026-05-28T13:00:00Z"},
"messages": [
{"message_id": 1001, "sender": "Alice", "text": "Hello!", "date": "2026-05-26T08:00:00Z"}
]
}
Step 3 — Summarize
With the messages in hand, produce a structured summary:
- Overview — total messages, time range, list of unique participants
- Main topics — 3–7 bullet points covering key themes discussed
- Key announcements / decisions — anything explicitly decided, announced, or agreed upon
- Open questions / unresolved threads — unanswered questions or ongoing debates
- Action items — clear next steps or tasks mentioned by participants
- Tone — one-line assessment (e.g. "active and collaborative", "mostly announcements", "heated debate on X")
Format the summary in clear markdown so the user can skim it quickly.
Handling No Data
If source is "none" in the output, inform the user that no messages were found and suggest:
- Verify the group with
list_groups.py - Check that local history uses the supported raw Telegram schema. Empty output from an unsupported store does not mean the group has no history.
- The bot may be running in webhook mode — messages processed live aren't available via
getUpdates - Try a wider
--since-hourswindow in case the filter is too narrow
Notes
- Bot privacy mode — By default, Telegram bots in groups only receive messages directed at them (commands or replies). To summarize general group conversation, the bot must have privacy mode disabled (BotFather →
/mybots→ Bot Settings → Group Privacy → Turn off) or be a group admin. Without this, both data sources will only contain bot-directed messages, not the full chat history. textandcaptionfields are captured from ordinary messages and channel posts — photo/file messages without a caption are skipped.- Summaries are produced by the active agent from raw message data — no external summarization API is used.
- The
getUpdatesfallback does not advance the offset or changeallowed_updates; it is limited to pending updates and is not a complete history export.
Related Skills
- telegram-send — send a follow-up message to the group
- list-telegram-chats — list all known chats and their IDs