← Back to Skills Marketplace
lhq2103387078

Feishu Doc

by lhq2103387078 · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ⚠ pending
55
Downloads
0
Stars
0
Active Installs
1
Versions
Install in OpenClaw
/install feishu-create-doc
Description
飞书云文档创建与管理。当用户提到"创建飞书文档"、"新建飞书文档"、"生成文档发送到飞书"、"飞书文档写入"等时使用。 支持创建带标题和富文本内容的飞书文档,包含段落、标题、列表等格式。
README (SKILL.md)

飞书文档创建

核心流程

1. 获取用户授权(仅首次)

feishu-user-token.json 不存在或 token 过期,需要用户重新授权:

授权链接:

https://open.feishu.cn/open-apis/authen/v1/authorize?client_id=cli_a95aca1714f89cd2&redirect_uri=http://localhost:6010/oauth/feishu/callback&scope=offline_access docx:document docx:document:create docx:document.block:convert&response_type=code

用户访问链接 → 授权 → 飞书跳转回 localhost:6010 → 回调 URL 中的 code=xxx 即为授权码

2. 交换 Token

import urllib.request

# 1. 获取 app_access_token
app_body = '{"app_id":"cli_a95aca1714f89cd2","app_secret":"oq9F8U4J3dnAyYR9AHRnigntKkOKPQ1K"}'
req = urllib.request.Request(
    "https://open.feishu.cn/open-apis/auth/v3/app_access_token/internal",
    data=app_body.encode("utf-8"),
    headers={"Content-Type": "application/json; charset=utf-8"},
    method="POST"
)
app_token = json.loads(urllib.request.urlopen(req).read().decode("utf-8"))["app_access_token"]

# 2. 用 code 换取 user_access_token
code = "用户授权后获得的code"
user_body = json.dumps({"grant_type": "authorization_code", "code": code}).encode("utf-8")
req = urllib.request.Request(
    "https://open.feishu.cn/open-apis/authen/v1/oidc/access_token",
    data=user_body,
    headers={
        "Authorization": f"Bearer {app_token}",
        "Content-Type": "application/json; charset=utf-8"
    },
    method="POST"
)
result = json.loads(urllib.request.urlopen(req).read().decode("utf-8"))
user_token = result["data"]["access_token"]
refresh_token = result["data"]["refresh_token"]

3. 创建文档(关键:请求体格式!)

import json, urllib.request

token = "user_access_token"
headers = {
    "Authorization": f"Bearer {token}",
    "Content-Type": "application/json; charset=utf-8"
}

# 创建文档 - 请求体直接用 {"title": "标题"} 而不是 {"document_style": {"title": ...}}!
body = json.dumps({"title": "文档标题"}, ensure_ascii=False).encode("utf-8")
req = urllib.request.Request(
    "https://open.feishu.cn/open-apis/docx/v1/documents",
    data=body,
    headers=headers,
    method="POST"
)
doc_id = json.loads(urllib.request.urlopen(req).read().decode("utf-8"))["data"]["document"]["document_id"]

4. 添加内容块

base_url = f"https://open.feishu.cn/open-apis/docx/v1/documents/{doc_id}/blocks/{doc_id}/children"

def add_text(text, indent=0):
    block = {"block_type": 2, "text": {"elements": [{"type": "text_run", "text_run": {"content": text}}]}}
    if indent > 0:
        block["style"] = {"indent_level": indent}
    body = json.dumps({"children": [block]}, ensure_ascii=False).encode("utf-8")
    req = urllib.request.Request(base_url, data=body, headers=headers, method="POST")
    urllib.request.urlopen(req)

def add_heading(text, level=1):
    key = f"heading{level}"
    block = {"block_type": level + 2, key: {"elements": [{"type": "text_run", "text_run": {"content": text}}]}}
    body = json.dumps({"children": [block]}, ensure_ascii=False).encode("utf-8")
    req = urllib.request.Request(base_url, data=body, headers=headers, method="POST")
    urllib.request.urlopen(req)

Block Type 参考:

Type 类型
2 文本段落
3 一级标题
4 二级标题
5 三级标题

关键要点

  1. 请求体格式:创建文档用 {"title": "xxx"},不是 {"document_style": {"title": ...}}
  2. 编码:所有请求必须用 UTF-8 编码,Content-Type: application/json; charset=utf-8
  3. Token 存储C:\\Users\\廖洪庆\\.openclaw-autoclaw\\credentials\\feishu-user-token.json
  4. 请求限流:每个请求间隔 0.3-0.5 秒,避免 429 错误
Capability Tags
cryptorequires-oauth-tokenrequires-sensitive-credentials
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install feishu-create-doc
  3. After installation, invoke the skill by name or use /feishu-create-doc
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.0
feishu-create-doc 1.0.0 - Initial release: Create and manage Feishu (飞书) cloud documents via API. - Supports creating documents with titles and rich text (paragraphs, headings, lists, etc.). - Includes detailed flow for user OAuth authorization, token exchange, and token storage. - Clear description of necessary API request formats, encoding, and request rate limits. - Reference for content block types and how to add them programmatically.
Metadata
Slug feishu-create-doc
Version 1.0.0
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 1
Frequently Asked Questions

What is Feishu Doc?

飞书云文档创建与管理。当用户提到"创建飞书文档"、"新建飞书文档"、"生成文档发送到飞书"、"飞书文档写入"等时使用。 支持创建带标题和富文本内容的飞书文档,包含段落、标题、列表等格式。 It is an AI Agent Skill for Claude Code / OpenClaw, with 55 downloads so far.

How do I install Feishu Doc?

Run "/install feishu-create-doc" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is Feishu Doc free?

Yes, Feishu Doc is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does Feishu Doc support?

Feishu Doc is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created Feishu Doc?

It is built and maintained by lhq2103387078 (@lhq2103387078); the current version is v1.0.0.

💬 Comments