Install
openclaw skills install telegram-file-browserBuild or improve Telegram inline-button file browsers and menu-style navigators. Use when creating Telegram chat UIs for browsing directories, paging lists,...
openclaw skills install telegram-file-browser⚠️ 🚨 CRITICAL BUTTON STRUCTURE WARNING 🚨
The
buttonsarray from the script is a 2D array where each inner array = one row. ALWAYS pass it directly to the message tool without modification.
- In OpenClaw context: use
response['buttons']directly- In Python scripts: use
payload['buttons']frombuild_message_payload()❌ NEVER flatten, restructure, re-group, or stringify rows.
When sending any browser menu, follow the correct workflow for your context:
If in OpenClaw (using exec + message tools):
browser_dispatcher.py via exec toolresponse['messageToolCall'] as the complete payload for the message toolpostSend, then update liveMessageId and optionally delete the previous menuIf in standalone Python script:
run_browser_action.py or import functionsbuild_message_payload(plan) and require ok: truepayload['message'] and payload['buttons'] from the validated resultCommon mistakes to avoid:
Build Telegram file-browsing flows around a single live menu plus optional side messages for previews, paths, and downloads.
When the user explicitly invokes telegram-file-browser or asks to use this skill:
~/.openclaw/workspace unless the user gave a path.config, open the configuration flow instead of the browser tree.Do not stop at describing the skill when you already have enough information to launch the UI.
This skill can be used in two different contexts. Choose the one that matches your environment.
When you're running inside OpenClaw and using exec + message tools (like right now), use browser_dispatcher.py via exec, then call the message tool with the exact JSON from the script.
⚠️ The script already validates and returns the correct payload — use it directly, don't rewrite anything.
Step 1: Run the script via exec tool
# Run the dispatcher to get the final message-tool payload
result = exec(command="python3 ~/.openclaw/workspace/skills/telegram-file-browser/scripts/browser_dispatcher.py open-root")
response = json.loads(result) # response contains messageToolCall, postSend, and compatibility fields
Step 2: Call message tool with the script's output
# ✅ CORRECT: pass the dispatcher payload through directly
message(**response['messageToolCall'])
# ❌ WRONG: don't rewrite buttons yourself
message(
action='send',
message=response['message'],
buttons=[[{...}, {...}]]
)
# ❌ WRONG: don't stringify the payload either
message(action='send', message=response['message'], buttons=json.dumps(response['buttons']))
Complete example:
# 1. Get the complete message-tool payload
result = exec(command="python3 ~/.openclaw/workspace/skills/telegram-file-browser/scripts/browser_dispatcher.py open-root")
response = json.loads(result.stdout)
if response['ok'] and response.get('messageToolCall'):
# 2. Send exactly what the dispatcher returned
msg_result = message(**response['messageToolCall'])
# 3. Update liveMessageId if requested
post_send = response.get('postSend') or {}
if msg_result.get('messageId') and post_send.get('updateLiveMessageId'):
exec(command="python3 ~/.openclaw/workspace/skills/telegram-file-browser/scripts/browser_dispatcher.py update-message-id " + str(msg_result['messageId']))
# 4. Delete the previous live menu only after the new one succeeds
previous_id = post_send.get('previousMessageId')
if previous_id and post_send.get('cleanupPreviousMessage'):
message(action='delete', messageId=previous_id)
Callback handling:
# 1. Handle callback
result = exec(command="python3 ~/.openclaw/workspace/skills/telegram-file-browser/scripts/browser_dispatcher.py handle-callback " + callback_data)
response = json.loads(result.stdout)
# 2. Execute the exact tool payload returned by the script
if response.get('messageToolCall'):
msg_result = message(**response['messageToolCall'])
post_send = response.get('postSend') or {}
if msg_result.get('messageId') and post_send.get('updateLiveMessageId'):
exec(command="python3 ~/.openclaw/workspace/skills/telegram-file-browser/scripts/browser_dispatcher.py update-message-id " + str(msg_result['messageId']))
previous_id = post_send.get('previousMessageId')
if previous_id and post_send.get('cleanupPreviousMessage'):
message(action='delete', messageId=previous_id)
Important for current Telegram/OpenClaw routing:
If a button click arrives as a plain inbound text message like tfb_root_v12_w8 instead of a native callback event, treat that text as the callback_data and run the exact same callback flow above. Do not ignore it just because it came in as a message.
Recommended detection rule:
^tfb_(root|dir|preview|path|download|back|close)_browser_dispatcher.py handle-callback <that_text> immediatelyWhen you're writing a standalone Python script (not inside OpenClaw), use the import-based approach with build_message_payload.
import sys
sys.path.insert(0, '~/.openclaw/workspace/skills/telegram-file-browser/scripts')
from run_browser_action import open_root, handle_callback
from send_plan import build_message_payload
STATE = '~/.openclaw/workspace/.openclaw/telegram-file-browser/state.json'
ROOT = '~/.openclaw/workspace'
def send_browser_plan(plan):
"""Send message using OpenClaw's message tool or Telegram API."""
if plan['toolAction'] == 'noop':
return None
if plan['toolAction'] == 'delete':
return {"action": "delete", "messageId": plan['messageId']}
if plan['toolAction'] == 'send-file':
return {"action": "send", "path": plan['path'], "caption": plan.get('caption')}
# MUST validate through build_message_payload
wrapped = build_message_payload(plan)
if not wrapped['ok']:
raise RuntimeError(wrapped['error'])
payload = wrapped['payload']
return {
"action": payload['action'],
"message": payload['message'],
"buttons": payload['buttons'],
"replyTo": payload.get('replyTo')
}
# First open
send_browser_plan(open_root(STATE, ROOT))
# Handle callback
send_browser_plan(handle_callback(STATE, callback_data))
Why build_message_payload is required in Python scripts:
Why it's NOT needed in OpenClaw context:
browser_dispatcher.py already returns a validated payload⚠️ For OpenClaw tool calls: Just use
browser_dispatcher.py— see Context 1 above.The examples below are for standalone Python scripts only.
In OpenClaw context (most common): Use browser_dispatcher.py — it already validates and returns the correct payload. Just use the JSON values directly.
In standalone Python scripts: Use run_browser_action.py + build_message_payload(plan) as the guardrail.
Supported toolAction values:
Plans that send buttons should also include viewType (for example directory or file-actions) so the validator can enforce row-shape rules.
senddeletesend-filenoopMap them to OpenClaw message actions like this:
send
browser_dispatcher.py — the response already contains validated message and buttons. Just pass them to the message tool:
message(action='send', message=response['message'], buttons=response['buttons'])
build_message_payload(plan) first, then use:
payload = wrapped["payload"]
message(action=payload["action"], message=payload["message"], buttons=payload["buttons"])
buttons as a real 2D array (each inner array = one row)⚠️ Common mistakes to avoid:
# ❌ WRONG — flatten all buttons into one row
buttons = [[{...item1...}, {...item2...}, {...item3...}]]
# ❌ WRONG — stringify buttons
buttons = json.dumps(response['buttons'])
# ✅ CORRECT — use script output directly
buttons = response['buttons']
delete
message action=deletemessageIdsend-file
message action=sendpath or filePathcaptionreplyTo is present, pass it as replyTonoop
Important runtime note:
send, not on edit.edit-message mode as replace the prior menu with minimal chat noise, not as a literal button-preserving in-place edit.Persist display mode in config.json.
edit-messageedit, implement this as:
liveMessageIdnew-messageliveMessageId to the newly sent menu after successNever place full file paths in callback_data.
Use opaque ids and store the real mapping in state.
Use the menu for navigation only.
Use separate messages for:
When a user clicks a file from a directory listing:
👁 预览, 📋 路径, ⬇️ 下载, ⬅️ 返回, ❌ 关闭.Keep pagination inside the same state machine.
Required behavior:
Persist at least:
rootcurrentstackliveMessageIdmenuVersionviewsRecommended shape:
{
"root": "/abs/root",
"current": "/abs/root/subdir",
"stack": ["/abs/root"],
"liveMessageId": "2317",
"menuVersion": 4,
"views": {
"/abs/root/subdir": {
"path": "/abs/root/subdir",
"page": 2,
"pageSize": 12,
"items": [
{ "id": "d12313", "name": "demo.py", "path": "/abs/root/subdir/demo.py", "type": "file" }
]
}
}
}
Protect against replayed and stale callbacks.
Required behavior:
noop over noisy execution for stale callbacksIf the resolved file or directory no longer exists:
When Telegram delivers a button click as a callback message such as callback_data: tfb_root_v2_w13, do this immediately:
scripts/run_browser_action.py handle-callback <state_path> <callback>toolAction == "send", run it through send_plan.py / build_message_payload(plan) firstmessage toolmessageId back into state as liveMessageIdDo not answer a callback message with a normal conversational reply when the callback belongs to the file browser.
Do not ask a follow-up unless the callback cannot be resolved safely.
Prefer silent noop over chatty recovery for stale callbacks.
If an edit fails because the menu no longer exists or cannot be edited:
liveMessageIdIf Telegram rejects callback payloads:
scripts/build_view.py — list a directory, sort entries, paginate, and emit view JSONscripts/file_browser_state.py — initialize/load/save state and manage current path, back stack, menu version, and live message idscripts/preview_file.py — generate safe file previewsscripts/render_buttons.py — build Telegram button matrices for directory and file-action viewsscripts/resolve_callback.py — resolve callback payloads into browser actionsscripts/browser_controller.py — orchestrate open-root, open-dir, file actions, back, paging, and live-message state updatesscripts/browser_config.py — load and persist display configscripts/run_browser_action.py — convert browser actions into concrete tool plans for messaging and file deliveryscripts/send_plan.py — validate send plans and build the only approved message(action="send", ...) payloadscripts/validate_buttons.py — CLI validator for plan JSON before sendingscripts/test_buttons_integrity.py — regression test for root/page/dir/file-action flows and flattened-button rejectionscripts/browser_dispatcher.py — ⭐ RECOMMENDED one-click wrapper: generates plan, validates, returns exact payload. Use this instead of hand-rolling the flow.Treat state/ as runtime-only scratch data. Do not commit it. Keep it ignored in git.
Before sending or replacing a browser menu, verify all of the following:
In OpenClaw context (using exec + message tools):
browser_dispatcher.py to get the planresponse['buttons'] directly to the message tool — no manual rewritingbuttons is a real 2D array (each inner array = one row)In standalone Python scripts:
build_message_payload(plan) to validatepayload['buttons'] from the validated resultGeneral rules (always):
replyTo is forwarded when the tool plan includes itliveMessageId is updatedTreat any manual rewrite of plan["buttons"] as a bug, not an optimization.
Read references/interaction-patterns.md when you need concrete UX guidance for: