--- title: "Document skill" description: "Create, read, and edit WeCom documents and smart spreadsheets (智能表格) through wecom-cli." --- The `wecomcli-doc` skill gives the AI the ability to manage WeCom documents and smart spreadsheets (智能表格). It can read document content in Markdown, create new documents or spreadsheets, overwrite document text, manage sub-sheets and field definitions, and perform full CRUD operations on spreadsheet records. All operations accept either a `docid` or a `url` to identify the target document. ## Document management ### get_doc_content Fetches the full content of a document in Markdown format. Uses an **async polling mechanism**: the first call returns a `task_id`, and you must re-call with that ID until `task_done` is `true`. First call (no `task_id`): ```bash wecom-cli doc get_doc_content '{"docid": "DOCID", "type": 2}' ``` Subsequent polling calls: ```bash wecom-cli doc get_doc_content '{"docid": "DOCID", "type": 2, "task_id": "TASK_ID"}' ``` You can also identify the document by URL: ```bash wecom-cli doc get_doc_content '{"url": "https://doc.weixin.qq.com/doc/xxx", "type": 2}' ``` ### create_doc Creates a new document or smart spreadsheet. Create a document: ```bash wecom-cli doc create_doc '{"doc_type": 3, "doc_name": "Project weekly report"}' ``` Create a smart spreadsheet: ```bash wecom-cli doc create_doc '{"doc_type": 10, "doc_name": "Task tracker"}' ``` The `docid` is only returned at creation time. Save it if you need to reference the document later. A newly created smart spreadsheet always includes one default sub-sheet. Use `smartsheet_get_sheet` to find its `sheet_id`. ### edit_doc_content Overwrites the document body with Markdown content. `content_type` is always `1`. ```bash wecom-cli doc edit_doc_content '{"docid": "DOCID", "content": "# Title\n\nBody content here.", "content_type": 1}' ``` ## Smart spreadsheet — structure management ### smartsheet_get_sheet Lists all sub-sheets in a smart spreadsheet, including `sheet_id`, title, and type. ```bash wecom-cli doc smartsheet_get_sheet '{"docid": "DOCID"}' ``` ### smartsheet_add_sheet Adds an empty sub-sheet. The new sheet has no views, records, or fields — populate it with the field and record operations below. ```bash wecom-cli doc smartsheet_add_sheet '{"docid": "DOCID", "properties": {"title": "New sheet"}}' ``` ### smartsheet_update_sheet Renames a sub-sheet. ```bash wecom-cli doc smartsheet_update_sheet '{"docid": "DOCID", "properties": {"sheet_id": "SHEET_ID", "title": "Renamed sheet"}}' ``` ### smartsheet_delete_sheet Permanently deletes a sub-sheet. ```bash wecom-cli doc smartsheet_delete_sheet '{"docid": "DOCID", "sheet_id": "SHEET_ID"}' ``` Deleting a sub-sheet is irreversible. ### smartsheet_get_fields Lists all fields (columns) in a sub-sheet, including `field_id`, `field_title`, and `field_type`. ```bash wecom-cli doc smartsheet_get_fields '{"docid": "DOCID", "sheet_id": "SHEET_ID"}' ``` ### smartsheet_add_fields Adds one or more fields to a sub-sheet. A single sub-sheet supports at most 150 fields. ```bash wecom-cli doc smartsheet_add_fields '{"docid": "DOCID", "sheet_id": "SHEET_ID", "fields": [{"field_title": "Task name", "field_type": "FIELD_TYPE_TEXT"}]}' ``` ### smartsheet_update_fields Renames a field. You cannot change the field type — `field_type` must be the same as the original. The new title must differ from the current one. ```bash wecom-cli doc smartsheet_update_fields '{"docid": "DOCID", "sheet_id": "SHEET_ID", "fields": [{"field_id": "FIELD_ID", "field_title": "New title", "field_type": "FIELD_TYPE_TEXT"}]}' ``` ### smartsheet_delete_fields Permanently deletes one or more fields. Get the `field_id` from `smartsheet_get_fields`. ```bash wecom-cli doc smartsheet_delete_fields '{"docid": "DOCID", "sheet_id": "SHEET_ID", "field_ids": ["FIELD_ID"]}' ``` Deleting a field is irreversible. ## Smart spreadsheet — data management ### smartsheet_get_records Returns all records in a sub-sheet. ```bash wecom-cli doc smartsheet_get_records '{"docid": "DOCID", "sheet_id": "SHEET_ID"}' ``` You can also use a URL: ```bash wecom-cli doc smartsheet_get_records '{"url": "https://doc.weixin.qq.com/smartsheet/xxx", "sheet_id": "SHEET_ID"}' ``` ### smartsheet_add_records Adds one or more rows. Recommended maximum: 500 rows per call. Before adding records, the AI checks field types via `smartsheet_get_fields`. For single-select or multi-select (Option) fields, existing option IDs must be matched exactly. ```bash wecom-cli doc smartsheet_add_records '{"docid": "DOCID", "sheet_id": "SHEET_ID", "records": [{"values": {"Task name": [{"type": "text", "text": "Complete requirements doc"}], "Priority": [{"text": "High"}]}}]}' ``` ### smartsheet_update_records Updates one or more rows. Requires the `record_id` from `smartsheet_get_records`. Use `key_type` to specify whether values are keyed by field title or field ID. ```bash wecom-cli doc smartsheet_update_records '{"docid": "DOCID", "sheet_id": "SHEET_ID", "key_type": "CELL_VALUE_KEY_TYPE_FIELD_TITLE", "records": [{"record_id": "RECORD_ID", "values": {"Task name": [{"type": "text", "text": "Updated content"}]}}]}' ``` System-managed fields — creation time, last edit time, creator, and last editor — cannot be updated. ### smartsheet_delete_records Permanently deletes one or more rows. Maximum 500 rows per call. Get `record_id` values from `smartsheet_get_records`. ```bash wecom-cli doc smartsheet_delete_records '{"docid": "DOCID", "sheet_id": "SHEET_ID", "record_ids": ["RECORD_ID_1", "RECORD_ID_2"]}' ``` Deleting records is irreversible. ## Typical workflows ### Reading a document ```bash wecom-cli doc get_doc_content '{"docid": "DOCID", "type": 2}' ``` If `task_done` is `false`, the AI calls again with the returned `task_id`: ```bash wecom-cli doc get_doc_content '{"docid": "DOCID", "type": 2, "task_id": "TASK_ID"}' ``` It repeats this until `task_done` is `true`, then presents the Markdown content. ### Creating and editing a document ```bash wecom-cli doc create_doc '{"doc_type": 3, "doc_name": "Meeting notes"}' ``` Save the returned `docid`. ```bash wecom-cli doc edit_doc_content '{"docid": "DOCID", "content": "# Meeting notes\n\n- Item one\n- Item two", "content_type": 1}' ``` ### Setting up a smart spreadsheet ```bash wecom-cli doc create_doc '{"doc_type": 10, "doc_name": "Task tracker"}' ``` ```bash wecom-cli doc smartsheet_get_sheet '{"docid": "DOCID"}' ``` ```bash wecom-cli doc smartsheet_add_fields '{"docid": "DOCID", "sheet_id": "SHEET_ID", "fields": [{"field_title": "Task name", "field_type": "FIELD_TYPE_TEXT"}, {"field_title": "Status", "field_type": "FIELD_TYPE_TEXT"}]}' ``` ### Adding rows to a spreadsheet ```bash wecom-cli doc smartsheet_get_fields '{"docid": "DOCID", "sheet_id": "SHEET_ID"}' ``` For USER-type fields, the AI also calls `wecomcli-contact` to resolve names to `userid` values. ```bash wecom-cli doc smartsheet_add_records '{"docid": "DOCID", "sheet_id": "SHEET_ID", "records": [{"values": {"Task name": [{"type": "text", "text": "Complete requirements doc"}]}}]}' ``` ### Updating and deleting rows ```bash wecom-cli doc smartsheet_get_records '{"docid": "DOCID", "sheet_id": "SHEET_ID"}' ``` ```bash wecom-cli doc smartsheet_update_records '{"docid": "DOCID", "sheet_id": "SHEET_ID", "key_type": "CELL_VALUE_KEY_TYPE_FIELD_TITLE", "records": [{"record_id": "RECORD_ID", "values": {"Task name": [{"type": "text", "text": "Revised content"}]}}]}' ``` ```bash wecom-cli doc smartsheet_delete_records '{"docid": "DOCID", "sheet_id": "SHEET_ID", "record_ids": ["RECORD_ID"]}' ``` ## Key constraints - All operations accept `docid` or `url` — you do not need to know both. - For USER-type spreadsheet fields, values must be `userid` strings obtained via `wecomcli-contact`. Names cannot be used directly. - `edit_doc_content` overwrites the entire document body. The AI reads the current content first when a partial edit is intended. - If `errcode` is not `0`, the AI retries once. If it fails again, it reports `errcode` and `errmsg` to you.