Skill: lcz5221-svg/feishu-duoge (version 1.0.0)

--- name: feishu-bot-setup description: Automated setup and configuration of Feishu/Lark bots with OpenClaw. Use when creating multiple Feishu bots with independent workspaces, memories, and dedicated agents. Handles agent creation, Feishu channel configuration, credential management, and routing bindings. Supports customizable roles, responsibilities, and personalities. Supports both WebSocket and webhook connection modes. --- # Feishu Bot Setup Automated setup and configuration of Feishu/Lark bots with OpenClaw. ## Features - **Flexible Role Definition** - Customize role, style, and responsibilities for each bot - **Batch Configuration** - Set up multiple bots with one command - **Independent Workspaces** - Each bot has isolated storage and memory - **Auto-generated Configs** - Automatically creates SOUL.md, IDENTITY.md, AGENTS.md - **WebSocket/Webhook** - Support both connection modes ## Overview This skill automates the creation and configuration of multiple Feishu bots, each with: - Independent agent workspace - Dedicated memory and configuration files - Feishu channel integration - Proper routing and bindings ## Prerequisites - OpenClaw installed and running - Gateway configured and accessible - Feishu app credentials (App ID, App Secret, Encrypt Key, Verification Token) ## Quick Start ### 1. Prepare Bot Configuration Create a configuration file with bot details. All fields under `personality` are **customizable**: ```json { "bots": [ { "name": "general-assistant", "agentId": "feishu-bot-1", "appId": "cli_xxx", "appSecret": "xxx", "encryptKey": "xxx", "verificationToken": "xxx", "connectionMode": "websocket", "personality": { "role": "通用助手", "tagline": "你的第一接待入口", "style": "温和简洁、快速响应", "styleDescription": "态度友好，回答简洁明了，快速响应", "responsibilities": [ "常识问答", "轻量办公", "需求分流", "日常兜底" ], "description": "我是你的全能基础助理，快速响应你的各种需求。", "motto": "有问必答，有求必应，做你最贴心的第一入口。", "emoji": "🙋" } } ] } ``` #### Personality Fields (All Optional, Customizable) | Field | Description | Example | |-------|-------------|---------| | `role` | Bot's role name | "数据分析助手" | | `tagline` | Short tagline | "你的数据专家" | | `style` | Working style | "严谨、高效" | | `styleDescription` | Detailed style | "注重数据准确性，逻辑严密" | | `responsibilities` | List of duties | ["数据分析", "报表生成"] | | `description` | Self-introduction | "我是数据分析专家..." | | `motto` | Signature motto | "让数据说话" | | `emoji` | Bot emoji | "📊" | **You can define ANY role you need** - customer service, sales, HR, finance, legal, etc. ### 2. Run Setup Script ```bash python3 /root/.openclaw/workspace/skills/feishu-bot-setup/scripts/setup_bots.py /path/to/config.json ``` ### 3. Restart Gateway ```bash openclaw gateway restart ``` ## Manual Setup Steps If you need more control, follow these manual steps: ### Step 1: Create Agent ```bash openclaw agents add <agent-id> --workspace /path/to/workspace --non-interactive ``` ### Step 2: Configure Feishu Channel Edit `~/.openclaw/openclaw.json` and add to `channels.feishu.accounts`: ```json "<bot-name>": { "appId": "cli_xxx", "appSecret": "xxx", "encryptKey": "xxx", "verificationToken": "xxx", "domain": "feishu", "connectionMode": "websocket", "webhookPath": "/webhook/feishu/<bot-name>", "dmPolicy": "open", "groupPolicy": "open", "requireMention": false, "reactionNotifications": "off", "typingIndicator": true, "resolveSenderNames": true } ``` ### Step 3: Bind Agent to Feishu Account ```bash openclaw agents bind --agent <agent-id> --bind feishu:<bot-name> ``` ### Step 4: Create Agent Configuration Files Create these files in the agent workspace: - `SOUL.md` - Role definition and personality - `IDENTITY.md` - Identity information - `AGENTS.md` - Workspace documentation - `TOOLS.md` - Tool usage notes (optional) - `HEARTBEAT.md` - Scheduled tasks (optional) ### Step 5: Restart Gateway ```bash openclaw gateway restart ``` ## Role Examples You can create bots for ANY purpose. Here are some examples: ### Customer Service Bot ```json { "role": "客服专员", "tagline": "你的贴心客服", "style": "耐心细致、专业友好", "responsibilities": ["问题解答", "投诉处理", "订单查询", "售后服务"], "emoji": "🎧" } ``` ### Sales Assistant Bot ```json { "role": "销售顾问", "tagline": "你的销售专家", "style": "热情主动、洞察需求", "responsibilities": ["产品咨询", "方案推荐", "报价生成", "客户跟进"], "emoji": "💼" } ``` ### HR Assistant Bot ```json { "role": "HR助手", "tagline": "你的人力资源伙伴", "style": "专业严谨、保密可靠", "responsibilities": ["政策解答", "请假审批", "入职指引", "福利咨询"], "emoji": "👔" } ``` ### Legal Advisor Bot ```json { "role": "法务顾问", "tagline": "你的法律助手", "style": "严谨审慎、依法依规", "responsibilities": ["合同审核", "法律咨询", "风险提示", "合规建议"], "emoji": "⚖️" } ``` ## Configuration Reference ### Connection Modes - **websocket** (default): Long-lived connection, no public URL needed - **webhook**: Requires public URL for Feishu to send events ### Policies - `dmPolicy`: `open`, `allowlist`, `pairing`, `disabled` - `groupPolicy`: `open`, `allowlist`, `disabled` - `requireMention`: `true` or `false` ## Troubleshooting ### Bot Not Responding 1. Check gateway status: `openclaw gateway status` 2. Verify bindings: `openclaw agents bindings` 3. Check logs: `openclaw logs --follow` 4. Ensure Feishu app is published and events are subscribed ### Credential Issues - Verify App ID and App Secret match Feishu Open Platform - Check Encrypt Key and Verification Token are correct - Ensure app has required permissions (robot, im:message) ## Resources - `scripts/setup_bots.py` - Automated setup script - `references/example-config.json` - Example configuration - `references/agent-templates/` - Agent configuration templates

path: scripts/setup_bots.py
content: #!/usr/bin/env python3
"""
Feishu Bot Setup Script
Automates the creation and configuration of Feishu bots with OpenClaw.
"""

import json
import sys
import subprocess
import os
from pathlib import Path


def run_command(cmd, check=True):
    """Run a shell command and return output."""
    result = subprocess.run(
        cmd,
        shell=True,
        capture_output=True,
        text=True
    )
    if check and result.returncode != 0:
        print(f"Error running: {cmd}")
        print(f"stderr: {result.stderr}")
        sys.exit(1)
    return result.stdout


def create_agent(agent_id, workspace_path):
    """Create a new OpenClaw agent."""
    print(f"Creating agent: {agent_id}")
    cmd = f'openclaw agents add {agent_id} --workspace {workspace_path} --non-interactive'
    run_command(cmd)
    print(f"✓ Agent {agent_id} created")


def create_agent_files(workspace, bot_config):
    """Create agent configuration files."""
    print(f"Creating configuration files for {bot_config['agentId']}")
    
    # Get personality config (support both old and new format)
    personality = bot_config.get('personality', bot_config)
    
    role = personality.get('role', '智能助手')
    tagline = personality.get('tagline', '你的智能助手')
    style = personality.get('style', '专业、高效')
    style_desc = personality.get('styleDescription', personality.get('style_description', ''))
    responsibilities = personality.get('responsibilities', ['回答问题', '提供帮助'])
    description = personality.get('description', f'我是你的{role}，{style}。')
    motto = personality.get('motto', '让我们一起高效工作！')
    emoji = personality.get('emoji', '🤖')
    
    # SOUL.md
    soul_content = f"""# SOUL.md - {role}

_{description}_

## 核心定位

**{role}** - {tagline}

## 职责范围

"""
    for resp in responsibilities:
        soul_content += f"- {resp}\n"
    
    soul_content += f"""
## 工作风格

**{style}**

{style_desc}

---

_{motto}_
"""
    
    with open(f"{workspace}/SOUL.md", 'w') as f:
        f.write(soul_content)
    
    # IDENTITY.md
    identity_content = f"""# IDENTITY.md - {role}

- **Name:** {role}
- **Creature:** AI Assistant
- **Vibe:** {style}
- **Emoji:** {emoji}
- **Avatar:** (optional)
"""
    
    with open(f"{workspace}/IDENTITY.md", 'w') as f:
        f.write(identity_content)
    
    # AGENTS.md
    agents_content = f"""# AGENTS.md - {role}工作空间

这是{role} ({bot_config['agentId']}) 的专属工作空间。

## 定位

对接飞书机器人：{bot_config['name']}
主要职责：{', '.join(responsibilities)}

## 文件结构

- `SOUL.md` - 角色定义和性格
- `IDENTITY.md` - 身份信息
- `MEMORY.md` - 长期记忆（重要信息）
- `memory/` - 每日记忆日志
- `TOOLS.md` - 工具使用笔记
- `HEARTBEAT.md` - 定时任务配置

## 注意事项

- 定期整理和备份重要文件
- 记录常用工具和脚本
- 保存重要对话和决策
"""
    
    with open(f"{workspace}/AGENTS.md", 'w') as f:
        f.write(agents_content)
    
    print(f"✓ Configuration files created for {bot_config['agentId']}")


def update_openclaw_config(bots):
    """Update OpenClaw configuration with Feishu accounts."""
    print("Updating OpenClaw configuration...")
    
    config_path = Path.home() / '.openclaw' / 'openclaw.json'
    
    with open(config_path, 'r') as f:
        config = json.load(f)
    
    # Ensure channels.feishu exists
    if 'channels' not in config:
        config['channels'] = {}
    if 'feishu' not in config['channels']:
        config['channels']['feishu'] = {
            'enabled': True,
            'accounts': {}
        }
    
    # Add bot accounts
    for bot in bots:
        config['channels']['feishu']['accounts'][bot['name']] = {
            'appId': bot['appId'],
            'appSecret': bot['appSecret'],
            'encryptKey': bot['encryptKey'],
            'verificationToken': bot['verificationToken'],
            'domain': 'feishu',
            'connectionMode': bot.get('connectionMode', 'websocket'),
            'webhookPath': f"/webhook/feishu/{bot['name']}",
            'dmPolicy': 'open',
            'groupPolicy': 'open',
            'requireMention': False,
            'reactionNotifications': 'off',
            'typingIndicator': True,
            'resolveSenderNames': True
        }
    
    # Backup original config
    backup_path = config_path.with_suffix('.json.bak')
    with open(backup_path, 'w') as f:
        json.dump(config, f, indent=2)
    
    # Write updated config
    with open(config_path, 'w') as f:
        json.dump(config, f, indent=2)
    
    print(f"✓ OpenClaw configuration updated (backup: {backup_path})")


def bind_agents(bots):
    """Bind agents to Feishu accounts."""
    print("Binding agents to Feishu accounts...")
    
    for bot in bots:
        cmd = f"openclaw agents bind --agent {bot['agentId']} --bind feishu:{bot['name']}"
        run_command(cmd, check=False)  # Don't fail if already bound
        print(f"✓ Bound {bot['agentId']} to {bot['name']}")


def main():
    if len(sys.argv) < 2:
        print("Usage: setup_bots.py <config.json>")
        sys.exit(1)
    
    config_file = sys.argv[1]
    
    with open(config_file, 'r') as f:
        config = json.load(f)
    
    bots = config.get('bots', [])
    
    print(f"Setting up {len(bots)} Feishu bots...\n")
    
    # Step 1: Create agents
    for bot in bots:
        workspace = f"~/.openclay/agents/{bot['agentId']}/workspace"
        create_agent(bot['agentId'], workspace)
    
    print()
    
    # Step 2: Create agent files
    for bot in bots:
        workspace = os.path.expanduser(f"~/.openclay/agents/{bot['agentId']}/workspace")
        create_agent_files(workspace, bot)
    
    print()
    
    # Step 3: Update OpenClaw config
    update_openclaw_config(bots)
    
    print()
    
    # Step 4: Bind agents
    bind_agents(bots)
    
    print("\n" + "="*50)
    print("Setup complete!")
    print("="*50)
    print("\nNext steps:")
    print("1. Restart gateway: openclaw gateway restart")
    print("2. Configure Feishu apps to use WebSocket mode")
    print("3. Test each bot in Feishu")


if __name__ == '__main__':
    main()


path: references/example-config.json
content: {
  "bots": [
    {
      "name": "customer-service",
      "agentId": "feishu-bot-1",
      "appId": "cli_xxx",
      "appSecret": "xxx",
      "encryptKey": "xxx",
      "verificationToken": "xxx",
      "connectionMode": "websocket",
      "personality": {
        "role": "客服专员",
        "tagline": "你的贴心客服",
        "style": "耐心细致、专业友好",
        "styleDescription": "耐心倾听用户问题，细致解答疑惑，保持专业友好的态度",
        "responsibilities": [
          "问题解答",
          "投诉处理",
          "订单查询",
          "售后服务"
        ],
        "description": "我是你的贴心客服专员，随时准备为你解答问题和提供帮助。",
        "motto": "用心服务，让每一位用户满意。",
        "emoji": "🎧"
      }
    },
    {
      "name": "sales-assistant",
      "agentId": "feishu-bot-2",
      "appId": "cli_xxx",
      "appSecret": "xxx",
      "encryptKey": "xxx",
      "verificationToken": "xxx",
      "connectionMode": "websocket",
      "personality": {
        "role": "销售顾问",
        "tagline": "你的销售专家",
        "style": "热情主动、洞察需求",
        "styleDescription": "主动了解客户需求，热情推荐合适方案，精准把握商机",
        "responsibilities": [
          "产品咨询",
          "方案推荐",
          "报价生成",
          "客户跟进"
        ],
        "description": "我是你的销售顾问，帮你发现最适合的解决方案。",
        "motto": "为客户创造价值，实现双赢。",
        "emoji": "💼"
      }
    },
    {
      "name": "hr-assistant",
      "agentId": "feishu-bot-3",
      "appId": "cli_xxx",
      "appSecret": "xxx",
      "encryptKey": "xxx",
      "verificationToken": "xxx",
      "connectionMode": "websocket",
      "personality": {
        "role": "HR助手",
        "tagline": "你的人力资源伙伴",
        "style": "专业严谨、保密可靠",
        "styleDescription": "专业处理人事事务，严格保护隐私信息，可靠值得信赖",
        "responsibilities": [
          "政策解答",
          "请假审批",
          "入职指引",
          "福利咨询"
        ],
        "description": "我是你的HR助手，为你解答人力资源相关问题。",
        "motto": "以人为本，服务至上。",
        "emoji": "👔"
      }
    },
    {
      "name": "tech-support",
      "agentId": "feishu-bot-4",
      "appId": "cli_xxx",
      "appSecret": "xxx",
      "encryptKey": "xxx",
      "verificationToken": "xxx",
      "connectionMode": "websocket",
      "personality": {
        "role": "技术支持",
        "tagline": "你的技术专家",
        "style": "专业高效、条理清晰",
        "styleDescription": "快速定位技术问题，高效提供解决方案，步骤清晰明了",
        "responsibilities": [
          "技术咨询",
          "故障排查",
          "使用指导",
          "问题反馈"
        ],
        "description": "我是你的技术支持专家，帮你解决各种技术难题。",
        "motto": "让技术不再成为障碍。",
        "emoji": "🔧"
      }
    },
    {
      "name": "legal-advisor",
      "agentId": "feishu-bot-5",
      "appId": "cli_xxx",
      "appSecret": "xxx",
      "encryptKey": "xxx",
      "verificationToken": "xxx",
      "connectionMode": "websocket",
      "personality": {
        "role": "法务顾问",
        "tagline": "你的法律助手",
        "style": "严谨审慎、依法依规",
        "styleDescription": "严谨审查法律风险，审慎评估合规性，依法依规提供建议",
        "responsibilities": [
          "合同审核",
          "法律咨询",
          "风险提示",
          "合规建议"
        ],
        "description": "我是你的法务顾问，为你提供专业的法律支持。",
        "motto": "依法合规，防范风险。",
        "emoji": "⚖️"
      }
    },
    {
      "name": "finance-assistant",
      "agentId": "feishu-bot-6",
      "appId": "cli_xxx",
      "appSecret": "xxx",
      "encryptKey": "xxx",
      "verificationToken": "xxx",
      "connectionMode": "websocket",
      "personality": {
        "role": "财务助手",
        "tagline": "你的财务专家",
        "style": "精准细致、规范严谨",
        "styleDescription": "数据精准无误，工作细致入微，严格遵守财务规范",
        "responsibilities": [
          "报销咨询",
          "预算管理",
          "财务分析",
          "流程指导"
        ],
        "description": "我是你的财务助手，帮你处理财务相关事务。",
        "motto": "精准财务，助力经营。",
        "emoji": "💰"
      }
    }
  ]
}


Security scan verdicts — ClawScan: suspicious | static analysis: clean | VirusTotal: clean | SkillSpector: suspicious (CRITICAL)