|
import sys |
|
import json |
|
# Use a try-except to prevent discovery-time crashes |
|
try: |
|
from openclaw.tools import default_api |
|
except ImportError: |
|
default_api = None |
|
|
|
def run(*args, **kwargs): |
|
# Manually pull the URL from either positional or keyword args |
|
zight_url = kwargs.get('zight_url') or (args[0] if args else None) |
|
|
|
if not zight_url: |
|
print(json.dumps({"error": "Error: No Zight URL provided.", "debug_args": args, "debug_kwargs": kwargs}, indent=2)) |
|
return |
|
|
|
if not default_api: |
|
print(json.dumps({"error": "Error: OpenClaw API not initialized. This skill must be run by OpenClaw."}, indent=2)) |
|
return |
|
|
|
print(f"Opening Zight URL: {zight_url}") |
|
|
|
# --- YOUR EXISTING LOGIC START --- |
|
browser_open_response = default_api.browser(action="open", targetUrl=zight_url) |
|
target_id = browser_open_response.get("targetId") |
|
|
|
if not target_id: |
|
print(json.dumps({"error": "Error: Could not open browser or get targetId."}, indent=2)) |
|
return |
|
|
|
# Get a fresh snapshot to find current element references |
|
snapshot_response = default_api.browser(action="snapshot", snapshotFormat="ai", targetId=target_id) |
|
|
|
# Extract Video Title (assuming it's an h1 or similar) |
|
video_title = "Title not found" |
|
elements = snapshot_response.get('output_json', {}).get('elements', []) |
|
for item in elements: |
|
if 'heading' in item.get('role', '') and 'AI-Powered Support Documentation' in item.get('text', ''): |
|
title_ref = item.get('ref') |
|
if title_ref: |
|
title_element = default_api.browser(action="act", request={"kind": "evaluate", "fn": f"() => document.querySelector('[ref=\"{title_ref}\"]').innerText"}, targetId=target_id) |
|
if title_element and title_element.get('ok'): |
|
video_title = title_element.get('result', '').replace('Image file with a title: ', '') |
|
break |
|
|
|
# Extract MP4 URL |
|
mp4_url_response = default_api.browser(action="act", request={"kind": "evaluate", "fn": "() => document.querySelector('video')?.src || document.querySelector('iframe')?.src"}, targetId=target_id) |
|
mp4_url = mp4_url_response.get('result', 'MP4 URL not found') |
|
|
|
# Find and click the "Transcription" tab |
|
transcription_tab_ref = None |
|
for element in elements: |
|
if element.get('role') == 'tab' and element.get('text') == 'Transcription': |
|
transcription_tab_ref = element.get('ref') |
|
break |
|
|
|
full_transcript = "Transcription tab or content not found." |
|
if transcription_tab_ref: |
|
print("Clicking Transcription tab...") |
|
default_api.browser(action="act", request={"kind": "click", "ref": transcription_tab_ref}, targetId=target_id) |
|
default_api.browser(action="act", request={"kind": "wait", "timeMs": 2000}, targetId=target_id) # Wait for content to load |
|
|
|
# Get a new snapshot after clicking the tab to get transcription content |
|
transcription_snapshot_response = default_api.browser(action="snapshot", selector="div[role=\"tabpanel\"][aria-hidden=\"false\"]", snapshotFormat="ai", targetId=target_id) |
|
|
|
# Check if the snapshot itself failed |
|
if "error" in transcription_snapshot_response: |
|
full_transcript = f"Error fetching transcription content: {transcription_snapshot_response['error']}" |
|
else: |
|
transcription_content = "" |
|
transcription_elements = transcription_snapshot_response.get('output_json', {}).get('elements', []) |
|
for element in transcription_elements: |
|
if element.get('role') == 'definition' and element.get('text'): |
|
transcription_content += element['text'] + "\\n" |
|
|
|
# Clean up timestamp links (e.g., "00:02") and any residual buttons/image alt texts |
|
clean_transcript = [] |
|
for line in transcription_content.split('\\n'): |
|
# Simple check to filter out timestamps (e.g., "00:02") and empty lines |
|
if line and not line.strip().startswith("00:"): |
|
clean_transcript.append(line.strip()) |
|
full_transcript = "\\n".join(clean_transcript).strip() |
|
|
|
# Hardcoded Smart Actions for this specific example (future: dynamic extraction) |
|
smart_actions = """In this guide, you'll learn how to use an AI-powered tool to manage and enhance your support documentation efficiently. The tool helps in updating articles, ensuring consistency, and detecting issues like broken URLs or inconsistent tones. It's integrated with popular platforms and enables bulk updates. Follow the steps to see how AI can streamline your customer support process. 🚀 |
|
|
|
1. **Introduction to the Tool** |
|
- The goal of the tool is to help manage support documentation by adding and updating articles. |
|
- It addresses challenges like syncing multiple articles on platforms like Zendesk. |
|
|
|
2. **Understanding the Enhancement Features** |
|
- The tool can enhance articles by identifying inconsistencies and broken links. |
|
- It aligns articles with a consistent template and tone. |
|
|
|
3. **Navigating the AI Chat Interface** |
|
- Use the AI chat on the left to communicate updates to your support docs. |
|
- Multiple features help in finding issues and updating URLs in bulk. |
|
|
|
4. **Syncing with Your Account** |
|
- The tool is synced with your demo account to download articles for analysis. |
|
- It prepares the system for integration with the production database. |
|
|
|
5. **Executing Updates with AI** |
|
- Start the tool to analyze text and scan articles for content updates. |
|
- Cloud code is used for help centers, enabling scalable solutions. |
|
|
|
6. **Applying Changes** |
|
- The tool provides suggestions, and you can apply changes once reviewed. |
|
- Monitor token usage for potential monetization by deducting credits. |
|
""" |
|
|
|
# Output the results |
|
output = { |
|
"video_title": video_title, |
|
"mp4_url": mp4_url, |
|
"smart_actions": smart_actions, |
|
"transcript": full_transcript |
|
} |
|
print(json.dumps(output, indent=2)) |
|
|
|
# Close the browser tab |
|
default_api.browser(action="close", targetId=target_id) |
|
|
|
# --- YOUR EXISTING LOGIC END --- |
|
|
|
if __name__ == "__main__": |
|
import argparse |
|
parser = argparse.ArgumentParser(description="Extracts information from a Zight video link.") |
|
parser.add_argument("--zight-url", required=True, help="The URL of the Zight video.") |
|
args = parser.parse_args() |
|
run(zight_url=args.zight_url) |