
___x_cmd_openclaw_setup(){
    [ "$#" -gt 0 ] ||   set -- --help

    ___x_cmd_hascmd openclaw || {
        ___x_cmd_openclaw___install || return $?
    }

    local op="$1";      shift
    case "$op" in
        -h|--help)  ___x_cmd help -m openclaw setup "$@";    return 0 ;;

        qywx)       ___x_cmd_openclaw_setup___qywx    "$@" ;;
        feishu)     ___x_cmd_openclaw_setup___feishu    "$@" ;;
    esac

    # config using telegram

    # config

    # ___x_cmd_openclaw_setup___channel
    # ___x_cmd_openclaw_setup___model
    # ___x_cmd_openclaw_setup___safe_skills

}

___x_cmd_openclaw_setup___model(){
    :

    # if you setup openai, gemini, kimi, glm, ollama in x-cmd. it will be loaded automatically.
}

___x_cmd_openclaw_setup___safe_skills(){
    :
    # setup bunch of skill that are safe

}

___x_cmd_openclaw_setup___channel(){
    ___x_cmd_openclaw_setup___telegram
    ___x_cmd_openclaw_setup___whatsapp
    ___x_cmd_openclaw_setup___discord
}

___x_cmd_openclaw_setup___telegram(){
    :
}

___x_cmd_openclaw_setup___whatsapp(){
    :
}

___x_cmd_openclaw_setup___feishu(){
    [ -d "$HOME/.openclaw/extensions/feishu" ] || {
        openclaw:info "install feishu plugins"
        ___x_cmd_openclaw___runmain plugins install @m1heng-clawd/feishu || return $?
    }
    # Restart the gateway to load plugins

    local appid; local appsecret
    ___x_cmd_feishu_cur     appid:= appsecret:= 2>/dev/null
    [ -n "$appid" ] || N=openclaw M="App ID not set. Use command setup => x feishu init"  log:ret:1

    ___x_cmd_openclaw___runmain config set channels.feishu.appId "$appid"
    ___x_cmd_openclaw___runmain config set channels.feishu.appSecret "$appsecret"
    ___x_cmd_openclaw___runmain config set channels.feishu.enabled true
}

___x_cmd_openclaw_setup___qywx(){
    [ -d "$HOME/.openclaw/extensions/wecom-openclaw-plugin" ] || {
        openclaw:info "install wecom-openclaw-plugin plugins"
        ___x_cmd_openclaw___runmain plugins install @wecom/wecom-openclaw-plugin || return $?
    }
    ___x_cmd_openclaw___runmain gateway restart

    local bot_id; local bot_secret
    ___x_cmd_qywx_cur     bot_id:= bot_secret:= 2>/dev/null
    [ -n "$bot_id" ] || {
        openclaw:info "Bot ID not set. Use command setup => x qywx init"
        ___x_cmd qywx init
    }

    ___x_cmd_openclaw___runmain config set channels.wecom.botId "$bot_id"
    ___x_cmd_openclaw___runmain config set channels.wecom.secret "$bot_secret"
    ___x_cmd_openclaw___runmain config set channels.wecom.enabled true
    ___x_cmd_openclaw___runmain config set channels.wecom.dmPolicy pairing

    ___x_cmd_openclaw___runmain gateway restart
}

___x_cmd_openclaw_setup___discord(){
    :
}
