Loading...
Loading...
Stage and send local media files through OpenClaw QQBot with safe temporary staging and automatic cleanup
npx skill4agent add aradotso/hermes-skills openclaw-qqbot-send-skillSkill by ara.so — Hermes Skills collection.
<qqmedia>...</qqmedia>~/.openclaw/media/qqbot/<qqmedia>...</qqmedia>git clone https://github.com/ZJunCher/openclaw-qqbot-send-skill.git
cd openclaw-qqbot-send-skillscripts/stage_media.py~/.openclaw/media/qqbot/SKILL.mdimport subprocess
import os
# Step 1: Stage the local file
source_file = "/home/user/Pictures/photo.jpg"
result = subprocess.run(
["python", "scripts/stage_media.py", source_file],
capture_output=True,
text=True,
check=True
)
staged_path = result.stdout.strip()
# Step 2: Send with QQBot using qqmedia tags
qqbot_message = f"<qqmedia>{staged_path}</qqmedia>"
# ... send qqbot_message through your QQBot integration ...
# Step 3: Clean up the staged copy
subprocess.run(
["python", "scripts/stage_media.py", "--cleanup", staged_path],
check=True
)# No staging or cleanup needed for URLs
url = "https://example.com/image.png"
qqbot_message = f"<qqmedia>{url}</qqmedia>"
# ... send directly through QQBot ...import subprocess
files = [
"/path/to/image1.png",
"/path/to/video.mp4",
"/path/to/audio.mp3"
]
staged_files = []
try:
# Stage all files
for source in files:
result = subprocess.run(
["python", "scripts/stage_media.py", source],
capture_output=True,
text=True,
check=True
)
staged_path = result.stdout.strip()
staged_files.append(staged_path)
# Send each file
qqbot_message = f"<qqmedia>{staged_path}</qqmedia>"
# ... send through QQBot ...
finally:
# Always clean up all staged files
for staged in staged_files:
subprocess.run(
["python", "scripts/stage_media.py", "--cleanup", staged],
check=False # Don't fail if cleanup fails
)python scripts/stage_media.py <source_path>~/.openclaw/media/qqbot/python scripts/stage_media.py "/home/user/document.pdf"
# Output: /home/user/.openclaw/media/qqbot/a1b2c3d4.pdfpython scripts/stage_media.py --cleanup <staged_path>python scripts/stage_media.py --cleanup "/home/user/.openclaw/media/qqbot/a1b2c3d4.pdf"# In scripts/stage_media.py, locate:
MAX_FILE_SIZE = 10 * 1024 * 1024 # 10 MB
# Change to desired size, e.g., 20 MB:
MAX_FILE_SIZE = 20 * 1024 * 1024~/.openclaw/media/qqbot/MEDIA_DIRscripts/stage_media.pystaged = subprocess.run(["python", "scripts/stage_media.py", source], ...).stdout.strip()
subprocess.run(["python", "scripts/stage_media.py", "--cleanup", staged], ...)# NEVER clean up the original source
subprocess.run(["python", "scripts/stage_media.py", "--cleanup", source], ...)
# NEVER clean up HTTP(S) URLs
subprocess.run(["python", "scripts/stage_media.py", "--cleanup", url], ...)
# NEVER guess or construct the staged path
subprocess.run(["python", "scripts/stage_media.py", "--cleanup", "~/.openclaw/media/qqbot/file.txt"], ...)~/.openclaw/media/qqbot/MAX_FILE_SIZEimport os
if os.path.exists(source_file):
# proceed with staging
else:
print(f"File not found: {source_file}")~/.openclaw/media/qqbot/staged_path = None
try:
staged_path = stage_file(source)
send_to_qqbot(staged_path)
except Exception as e:
print(f"Send failed: {e}")
finally:
if staged_path:
try:
cleanup_file(staged_path)
except Exception as e:
print(f"Cleanup failed for {staged_path}: {e}")
# Log but don't delete manually#!/usr/bin/env python3
import subprocess
import sys
import os
def send_media_to_qqbot(source_path):
"""Stage, send, and clean up media for QQBot."""
# Check if it's a URL
if source_path.startswith(("http://", "https://")):
print(f"Sending URL directly: {source_path}")
qqbot_message = f"<qqmedia>{source_path}</qqmedia>"
# Send through QQBot API here
return True
# Check if file exists
if not os.path.exists(source_path):
print(f"Error: File not found: {source_path}")
return False
staged_path = None
try:
# Stage the file
result = subprocess.run(
["python", "scripts/stage_media.py", source_path],
capture_output=True,
text=True,
check=True
)
staged_path = result.stdout.strip()
print(f"Staged to: {staged_path}")
# Send through QQBot
qqbot_message = f"<qqmedia>{staged_path}</qqmedia>"
print(f"Sending: {qqbot_message}")
# ... actual QQBot send logic here ...
return True
except subprocess.CalledProcessError as e:
print(f"Staging failed: {e.stderr}")
return False
finally:
# Always clean up the staged file
if staged_path:
try:
subprocess.run(
["python", "scripts/stage_media.py", "--cleanup", staged_path],
check=True
)
print(f"Cleaned up: {staged_path}")
except subprocess.CalledProcessError as e:
print(f"Cleanup failed: {e.stderr}")
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: send_media.py <file_path_or_url>")
sys.exit(1)
send_media_to_qqbot(sys.argv[1])