🎯 技能分享
社区贡献的 OpenClaw 技能模块
📚 技能库
官方技能
| 技能名称 | 功能描述 | 难度 | 更新时间 |
|---|---|---|---|
| weather | 天气查询 | ⭐ | 2026-03 |
| search | 网络搜索 | ⭐ | 2026-03 |
| calculator | 数学计算 | ⭐ | 2026-03 |
| file-manager | 文件管理 | ⭐⭐ | 2026-02 |
| 邮件发送 | ⭐⭐ | 2026-02 | |
| calendar | 日程管理 | ⭐⭐ | 2026-02 |
| database | 数据库操作 | ⭐⭐⭐ | 2026-01 |
| api-client | API 调用 | ⭐⭐⭐ | 2026-01 |
| code-executor | 代码执行 | ⭐⭐⭐⭐ | 2026-01 |
社区技能
| 技能名称 | 作者 | 功能描述 | 评分 |
|---|---|---|---|
| notion-sync | @dev1 | Notion 同步 | ⭐⭐⭐⭐ |
| slack-bot | @dev2 | Slack 机器人 | ⭐⭐⭐⭐ |
| github-helper | @dev3 | GitHub 辅助 | ⭐⭐⭐⭐⭐ |
| data-analyzer | @dev4 | 数据分析 | ⭐⭐⭐⭐ |
| report-generator | @dev5 | 报告生成 | ⭐⭐⭐ |
🛠️ 技能开发指南
技能结构
一个完整的技能包含以下文件:
skills/
└── my-skill/
├── skill.json # 技能配置
├── skill.py # 技能实现
├── skill.md # 技能文档
└── tests/
└── test_skill.py # 测试文件skill.json 配置
json
{
"name": "weather",
"version": "1.0.0",
"description": "查询城市天气信息",
"author": "OpenClaw Team",
"triggers": ["天气", "weather", "气温"],
"parameters": {
"city": {
"type": "string",
"description": "城市名称",
"required": true
}
},
"returns": {
"temperature": "温度",
"condition": "天气状况",
"humidity": "湿度"
}
}技能实现示例
python
# skill.py
from openclaw import Skill, skill_param
class WeatherSkill(Skill):
"""天气查询技能"""
name = "weather"
description = "查询指定城市的天气信息"
@skill_param("city", type=str, required=True)
async def execute(self, city: str) -> dict:
"""
执行天气查询
Args:
city: 城市名称
Returns:
包含天气信息的字典
"""
# 调用天气 API
weather_data = await self.fetch_weather(city)
return {
"city": city,
"temperature": weather_data["temp"],
"condition": weather_data["condition"],
"humidity": weather_data["humidity"],
"suggestion": self.get_suggestion(weather_data)
}
async def fetch_weather(self, city: str) -> dict:
"""获取天气数据"""
# 实现天气 API 调用
pass
def get_suggestion(self, weather: dict) -> str:
"""生成穿衣建议"""
temp = weather["temp"]
if temp < 10:
return "天气较冷,建议穿厚外套"
elif temp < 20:
return "天气适中,建议穿薄外套"
else:
return "天气较热,建议穿短袖"🌟 热门技能详解
1. GitHub Helper
功能: GitHub 仓库管理和 PR 审查
使用场景:
- 自动创建 Issue
- PR 代码审查
- Release Notes 生成
配置示例:
json
{
"name": "github-helper",
"config": {
"token": "${GITHUB_TOKEN}",
"default_repo": "owner/repo",
"review_template": "standard"
}
}使用示例:
用户:帮我查看最近的 PR
AI:我来帮你查看 owner/repo 的最近 PR...
用户:对这个 PR 进行代码审查
AI:正在分析 PR #123 的代码变更...2. Data Analyzer
功能: 数据分析和可视化
使用场景:
- CSV/Excel 数据分析
- 自动生成图表
- 数据报告生成
配置示例:
json
{
"name": "data-analyzer",
"config": {
"output_dir": "./reports",
"chart_style": "modern",
"language": "zh-CN"
}
}使用示例:
用户:分析这份销售数据
AI:我来分析销售数据...
- 总销售额:¥1,234,567
- 增长率:+15%
- 最佳产品:产品A
用户:生成趋势图
AI:已生成销售趋势图,保存到 ./reports/trend.png3. Report Generator
功能: 自动生成各类报告
使用场景:
- 周报/月报生成
- 项目进度报告
- 会议纪要整理
模板示例:
markdown
# {{title}}
## 概述
{{summary}}
## 完成事项
{{#each completed}}
- {{this}}
{{/each}}
## 进行中
{{#each in_progress}}
- {{this}}
{{/each}}
## 下周计划
{{#each next_week}}
- {{this}}
{{/each}}📝 技能开发最佳实践
1. 错误处理
python
class MySkill(Skill):
async def execute(self, **params):
try:
result = await self.do_something(params)
return {"success": True, "data": result}
except ValidationError as e:
return {"success": False, "error": f"参数错误: {e}"}
except APIError as e:
return {"success": False, "error": f"API 调用失败: {e}"}
except Exception as e:
self.logger.error(f"未知错误: {e}")
return {"success": False, "error": "内部错误,请稍后重试"}2. 参数验证
python
from pydantic import BaseModel, validator
class WeatherParams(BaseModel):
city: str
@validator('city')
def validate_city(cls, v):
if len(v) < 2:
raise ValueError('城市名称太短')
return v
class WeatherSkill(Skill):
params_model = WeatherParams
async def execute(self, city: str):
# 参数已自动验证
pass3. 缓存优化
python
from functools import lru_cache
from datetime import datetime, timedelta
class WeatherSkill(Skill):
@lru_cache(maxsize=100)
def _get_cached_weather(self, city: str, date: str):
"""缓存天气数据(按天)"""
return self.fetch_weather(city)
async def execute(self, city: str):
today = datetime.now().strftime('%Y-%m-%d')
return self._get_cached_weather(city, today)🚀 发布你的技能
发布流程
开发测试
bash# 本地测试 openclaw test my-skill # 运行测试用例 pytest tests/打包
bashopenclaw package my-skill发布
bashopenclaw publish my-skill
质量要求
- ✅ 完整的文档(skill.md)
- ✅ 测试覆盖率 > 80%
- ✅ 错误处理完善
- ✅ 日志记录规范
- ✅ 无敏感信息硬编码
💬 技能讨论
遇到问题?有新想法?