# flarum-publisher-skill **Repository Path**: dbfedbf/flarum-publisher-skill ## Basic Information - **Project Name**: flarum-publisher-skill - **Description**: No description available - **Primary Language**: Unknown - **License**: EPL-1.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-12 - **Last Updated**: 2026-03-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Flarum Publisher 用于向 Flarum 论坛发布文章的 OpenClaw 技能工具。 ## 概述 Flarum Publisher 是一个用于与 Flarum 论坛系统集成的 Python 技能模块,专为 OpenClaw 平台设计,提供文章发布、标签管理、回复创建等常用功能。通过 REST API 与 Flarum 论坛进行交互,支持 Markdown 和 HTML 格式内容的发布。 ## 触发关键词 以下关键词将触发此技能: - 在示例网站发布 - 发布到示例网站 - flarum发布 - 发布文章到示例网站 ## 快速开始 ### 前置要求 - Python 3.7+ - Flarum 论坛账号 - API Key(需从论坛管理员处获取) - 论坛用户 ID ### 安装依赖 ```bash pip install requests ``` ### 基础配置 #### 环境变量配置(推荐) 在 OpenClaw 平台中,建议通过环境变量配置以下参数: - `FLARUM_BASE_URL`:Flarum 论坛的基础 URL - `FLARUM_API_KEY`:API 密钥 - `FLARUM_USER_ID`:用户 ID(可选) #### 代码配置 ```python from scripts.flarum_api_client import get_client # 获取 API 客户端 api_client = get_client() ``` ### 在 OpenClaw 中使用 ```python from scripts.openclaw_flarum import get_openclaw_flarum # 获取 OpenClaw Flarum 实例 flarum = get_openclaw_flarum() # 发布文章 result = flarum.publish_article( title="测试文章", content="这是一篇测试文章", tag_ids=["1"] ) if result['success']: print(f"发布成功: {result['data']['url']}") else: print(f"发布失败: {result['error']}") ``` ## 常用发布任务 ### 发布事件文章(标准格式) ```python from scripts.publish_article import publish_incident result = publish_incident( title="服务器故障处理报告", fault_description="数据库连接超时问题", handling_result="已修复并优化连接池配置" ) ``` ### 使用指定标签发布 ```python from scripts.publish_article import publish_incident_with_tag_name result = publish_incident_with_tag_name( title="网络故障处理", fault_description="网络延迟过高", handling_result="已更换网络线路", tag_name="故障报告" ) ``` ### 发布普通文章 ```python from scripts.publish_article import publish_article result = publish_article( title="技术分享:Flarum 最佳实践", content="# 内容摘要\n\n本文介绍...", tag_ids=["1", "2"] ) ``` ### 快速发布 ```python from scripts.publish_article import quick_publish result = quick_publish( title="今日分享", content="这是一篇快速发布的文章" ) ``` ## 列出可用标签 ```python from scripts.publish_article import list_tags tags = list_tags() for tag in tags: print(f"{tag['name']} (ID: {tag['id']})") ``` ## 查看最近文章 ```python from scripts.publish_article import list_recent_articles articles = list_recent_articles(limit=10) for article in articles: print(f"{article['title']} - {article['createdAt']}") ``` ## 内容格式支持 ### Markdown 格式 ```python content = """# 标题 ## 二级标题 - 列表项1 - 列表项2 **粗体** 和 *斜体* [链接文字](https://example.com) """ ``` ### HTML 格式 ```python content = """

标题

这是一个段落,含有 粗体斜体

""" ``` ## 高级 API 操作 ### 获取单篇文章 ```python from scripts.flarum_api_client import get_client client = get_client() discussion = client.get_discussion(discussion_id=123) ``` ### 更新文章 ```python client.update_discussion( discussion_id=123, title="新标题", content="更新后的内容" ) ``` ### 删除文章 ```python client.delete_discussion(discussion_id=123) ``` ### 创建回复 ```python client.create_post( discussion_id=123, content="这是我的回复内容" ) ``` ### 批量发布 ```python from scripts.usage_examples import example_batch_publish example_batch_publish() ``` ## 错误处理 所有 API 方法在出错时会返回包含错误信息的字典。建议进行如下处理: ```python result = publish_article(title="测试", content="内容") if 'errors' in result: print(f"发布失败: {result['errors']}") else: print(f"发布成功,文章ID: {result['id']}") ``` ## 注意事项 1. **API Key 安全**:请妥善保管您的 API Key,不要将其提交到公开仓库 2. **频率限制**:注意论坛的 API 调用频率限制,避免频繁请求 3. **内容审核**:发布内容需符合论坛社区规范 4. **标签有效性**:使用标签前请确保标签 ID 或名称正确 ## 资源 - [Flarum 官方文档](https://docs.flarum.org/) - [Flarum API 参考](./api_reference.md) ## 示例代码 更多使用示例请参考 `scripts/usage_examples.py` 文件。