这个 Skill 为 OpenClaw 提供企业微信审批功能集成,支持:
# 企业微信应用配置
WECOM_CORP_ID="your_corp_id"
WECOM_SECRET="your_agent_secret"
WECOM_AGENT_ID=your_agent_id
在 templates.json 文件中配置审批模板:
{
"templates": [
{
"id": "88219328193",
"name": "请假审批",
"description": "员工请假申请审批"
},
{
"id": "88219328194",
"name": "报销审批",
"description": "费用报销申请审批"
}
]
}
from wecom_approval import WeComApproval
approval = WeComApproval()
templates = approval.list_templates()
for template in templates:
print(f"{template['name']}: {template['description']}")
from wecom_approval import WeComApproval
approval = WeComApproval()
template = approval.get_template_detail(template_id="88219328193")
print(template)
当获取请假模板详情时,Vacation 控件的返回格式如下:
{
"template_content": {
"controls": [
{
"property": {
"control": "Vacation",
"id": "Vacation-15111111111",
"title": [
{
"text": "请假",
"lang": "zh_CN"
}
],
"require": 1
},
"config": {
"vacation": {
"selector": {
"type": "single",
"options": [
{
"key": "1",
"value": [
{
"text": "事假",
"lang": "zh_CN"
}
]
},
{
"key": "2",
"value": [
{
"text": "病假",
"lang": "zh_CN"
}
]
},
{
"key": "3",
"value": [
{
"text": "年假",
"lang": "zh_CN"
}
]
}
],
"exp_type": 0
},
"attendance": {
"date_range": {
"type": "hour",
"new_begin": 1568077200,
"new_end": 1568368800,
"new_duration": 291600
},
"type": 1
}
}
}
}
]
}
}
说明:
vacation.selector: 请假类型选择器(事假、病假、年假等)
vacation.attendance.date_range: 时间范围配置
type: "hour" 表示按小时计算
new_begin: 开始时间戳(Unix时间戳,单位秒)
new_end: 结束时间戳(Unix时间戳,单位秒)
new_duration: 时长(秒)
from wecom_approval import WeComApproval
approval = WeComApproval()
template_detail = approval.get_template_detail(template_id="88219328193")
controls = approval.parse_template_controls(template_detail)
for control in controls:
print(f"{control['title']} [{control['type_name']}]")
if control['required']:
print(" * 必填")
from wecom_approval import WeComApproval
approval = WeComApproval()
# 获取模板详情
template_detail = approval.get_template_detail(template_id="88219328193")
controls = approval.parse_template_controls(template_detail)
# 构建表单数据
form_data = []
for control in controls:
# 这里可以根据实际情况获取用户输入
value = "用户输入的值"
# 验证值
is_valid, error_msg = approval.validate_control_value(control, value)
if not is_valid:
print(error_msg)
continue
# 构建表单项
form_item = approval.build_form_item(control, value)
form_data.append(form_item)
# 生成摘要信息
summary_list = approval.generate_summary_list(form_data, template_name="请假审批")
# 提交审批申请
result = approval.apply_event(
template_id="88219328193",
creator_userid="zhangsan",
form_data=form_data,
summary_list=summary_list,
use_template_approver=1
)
print(result)
当提交包含 Vacation 控件的审批时,数据格式如下:
{
"creator_userid": "zhangsan",
"template_id": "88219328193",
"use_template_approver": 1,
"apply_data": {
"contents": [
{
"control": "Vacation",
"id": "Vacation-15111111111",
"value": {
"vacation": {
"selector": {
"type": "single",
"options": [
{
"key": "1",
"value": [
{
"text": "事假",
"lang": "zh_CN"
}
]
}
],
"exp_type": 0
},
"attendance": {
"date_range": {
"type": "hour",
"new_begin": 1568077200,
"new_end": 1568368800,
"new_duration": 291600
},
"type": 1
}
}
}
}
]
},
"summary_list": [
{
"summary_info": [
{
"text": "请假审批",
"lang": "zh_CN"
}
]
},
{
"summary_info": [
{
"text": "事假",
"lang": "zh_CN"
}
]
},
{
"summary_info": [
{
"text": "2024-01-15到2024-01-16",
"lang": "zh_CN"
}
]
}
]
}
用户也可以使用简化的字符串格式输入,系统会自动转换为企业微信API需要的格式:
# 用户输入:"2024-01-15 08:00:00到2024-01-15 17:00:00"
# 系统自动转换为:
{
"vacation": {
"attendance": {
"date_range": {
"type": "hour",
"new_begin": 1705276800,
"new_end": 1705309200,
"new_duration": 32400
},
"type": 1
}
}
}
时间格式支持:
"2024-01-15 08:00:00到2024-01-15 17:00:00"
"2024-01-15到2024-01-16"
"上午8点到下午5点"
| 操作 | 参数 | 说明 |
|------|------|------|
| list_templates | - | 列出所有审批模板 |
| get_template | template_id | 获取审批模板详情 |
| get_template_by_name | name | 根据名称获取模板 |
| parse_template_controls | template_id 或 template_detail | 解析模板控件 |
| submit_approval | template_id, creator_userid, form_data, summary_list | 提交审批申请 |
| get_approval_detail | sp_no | 获取审批详情 |
| chat | message, sender_id, user_id | 聊天交互 |
机器人:列出所有可用的审批模板
机器人:审批申请提交成功!审批编号:202401150001,你可以继续提交其他审批申请。
机器人:还需要补充以下必填内容:
请重新提供完整信息,例如:
'帮我完成请假审批,请假类型为事假,请假理由为外出办事,请假时间为上午8点到下午5点'
机器人:选择请假模板,列出需要填写的内容,引导用户一步步填写
机器人:审批申请提交成功!审批编号:202401150002,你可以继续提交其他审批申请。
用户(sender_id: "WangXiaoMing"):帮我完成请假审批,请假类型为事假,请假理由为外出办事,请假时间为上午8点到下午5点
机器人:审批申请提交成功!
审批编号:202401150001
你可以继续提交其他审批申请。
用户(sender_id: "WangXiaoMing"):帮我提交请假审批,请假理由为家里有事
机器人:还需要补充以下必填内容:
1. 请假类型
2. 请假时间
请重新提供完整信息,例如:
'帮我完成请假审批,请假类型为事假,请假理由为外出办事,请假时间为上午8点到下午5点'
用户:帮我完成请假审批,请假类型为病假,请假理由为身体不适,请假时间为2024-01-15到2024-01-16
机器人:审批申请提交成功!
审批编号:202401150002
你可以继续提交其他审批申请。
用户(sender_id: "WangXiaoMing"):我要请假
机器人:好的,为你选择了【请假审批】模板!
需要填写以下内容:
1. 请假类型[单选/多选] *
选项:事假、病假、年假
2. 开始日期[日期] *
3. 结束日期[日期] *
4. 请假原因[多行文本]
让我们开始填写吧!
【1/4】请假类型[单选/多选] *
选项:事假、病假、年假
请输入内容(或回复'取消'退出):
用户:事假
机器人:【2/4】开始日期[日期] *
请输入内容...
用户:abc
机器人:输入有误:控件 开始日期 必须是日期
请重新输入(或回复'取消'退出):
用户:2024-01-15
机器人:【3/4】结束日期[日期] *
请输入内容...
用户:2024-01-16
机器人:【4/4】请假原因[多行文本]
请输入内容...
用户:家里有事
机器人:审批申请提交成功!
审批编号:202401150003
你可以继续提交其他审批申请。
用户(sender_id: "LiSi"):帮我提交报销审批,报销类型为差旅费,报销金额为800元,报销原因为去上海出差,开始日期为2024-01-10,结束日期为2024-01-12
机器人:审批申请提交成功!
审批编号:202401150004
你可以继续提交其他审批申请。
| 类型 | 说明 |
|------|------|
| Text | 文本 |
| Textarea | 多行文本 |
| Number | 数字 |
| Money | 金额 |
| Date | 日期/日期+时间 |
| Selector | 单选/多选 |
| Contact | 成员/部门 |
| Tips | 说明文字 |
| File | 附件 |
| Table | 明细 |
| Attendance | 假勤控件 |
| Vacation | 请假控件 |
| Location | 位置 |
| RelatedApproval | 关联审批单 |
| Formula | 公式 |
| DateRange | 时长 |
| BankAccount | 收款账户 |
| 功能 | 接口 |
|------|------|
| 获取审批模板详情 | /cgi-bin/oa/gettemplatedetail |
| 提交审批申请 | /cgi-bin/oa/applyevent |
共 1 个版本