WeChat to IMA
Save a WeChat article into IMA with two user-facing flows:
- 解析公众号文章 → 存到 IMA 笔记
- 解析公众号文章 → 查知识库 → 加入该知识库
不要把内部实现细节当成用户流程来描述。
Workflow
- Parse the WeChat article.
- Keep inline body images in original order.
- If the body contains no inline images, insert the cover image near the top.
- If the user wants 笔记: save into IMA notes and read back once to verify the note is not empty.
- If the user wants 知识库: resolve the target knowledge base by name or ID, then add the parsed article there as a Markdown knowledge item.
Flow mapping
scripts/save_wechat_to_ima.py → 解析公众号文章 → 存到 IMA 笔记scripts/save_wechat_to_ima.py → 解析公众号文章 → 查知识库 → 加入该知识库
Requirements
- IMA credentials are required. Configure either:
- environment variables:
IMA_OPENAPI_CLIENTID and IMA_OPENAPI_APIKEY - or local files:
~/.config/ima/client_id and ~/.config/ima/api_key - Python 3 and Node.js must be available.
- Run
npm install once inside this skill directory so the bundled extractor dependencies are available. skills/ima-skill/ima_api.cjs is used when present, so this skill stays aligned with the latest IMA OpenAPI wrapper and error handling.
Setup
Option A: environment variables
export IMA_OPENAPI_CLIENTID="<your_client_id>"
export IMA_OPENAPI_APIKEY="<your_api_key>"
Option B: local credential files
mkdir -p ~/.config/ima
printf '%s' '<your_client_id>' > ~/.config/ima/client_id
printf '%s' '<your_api_key>' > ~/.config/ima/api_key
Install dependencies
cd skills/wechat-to-ima
npm install
Quick start
Save to IMA notes
python3 scripts/save_wechat_to_ima.py "https://mp.weixin.qq.com/s/xxxxx"
Save to a named IMA knowledge base
python3 scripts/save_wechat_to_ima.py "https://mp.weixin.qq.com/s/xxxxx" "知识库名称"
Behavior:
- without a knowledge-base argument → save to IMA notes
- with a knowledge-base name or ID → save to that knowledge base only, without creating an extra user-visible note
Common errors
missing env: ... → IMA credentials are not configured yetknowledge base not found: ... → the specified knowledge base name/ID cannot be resolvedknowledge base ambiguous: ... → multiple knowledge bases matched; use the exact name or ID- extractor/dependency errors → run
npm install in this skill directory first
Output
The script prints JSON with:
titleaccountauthorpublish_timebody_img_countcover_usedmarkdown_pathnote_idreadback_okknowledge_base_name (when requested)knowledge_base_id (when requested)knowledge_media_id (when requested)knowledge_file_name (when requested)
Notes
- Prefer this skill over ad-hoc manual parsing when the user wants the article stored in IMA.
- This skill is self-contained for article parsing and does not depend on a separate
wechat-article-extractor installation. - The IMA readback check uses plain text, so it confirms content landed successfully but does not visually render images in the terminal output.
- When the user names a target knowledge base, this skill resolves the knowledge base by name and routes the article into that knowledge base only.
- Knowledge-base mode should not create an extra user-visible IMA note. Instead, upload the rebuilt Markdown into the target knowledge base as the final artifact.
- Strict target rule: if the user specified a knowledge-base name, do not silently substitute another addable knowledge base. If exact resolution fails, stop and report that the requested target is not found/accessible, then use a logged-in IMA desktop/web session or ask for the exact knowledge-base ID.
- If parsing succeeds but the article body has no inline images, that is expected for some articles; use the cover-image fallback instead of treating it as a failure.
- If the original article contains code or code-block-style content, preserve it as fenced Markdown code blocks when importing into IMA; do not flatten code into ordinary prose.