Answers

How do I turn WeChat Official Account articles into clean text for a RAG knowledge base?

Short answer

List the account's articles with Official Account article history ($0.04 per 10), then fetch each one with article detail ($0.02), which returns the body as plain text plus title, account and publish time. A 300-article account costs $7.20; you add the Markdown header and chunk it yourself.

An internal assistant that answers questions about your industry is only as good as what it has read, and in China a lot of that lives in Official Accounts. To get an account into your RAG index, list its articles with Official Account article history, then send each link to article detail. Detail returns the body as plain text with paragraph breaks kept, plus the title, account, author byline and publish time, which is everything a citation needs.

What the text looks like

The article HTML is reduced to text: paragraphs and headings become their own lines, scripts and styling are gone, and inline images are dropped (the cover image URL is kept in images). Tables collapse into lines of text. That is good input for embedding. If you need the original layout with images in place, this is the wrong tool; see the alternatives below.

Cost

Job Calls Cost
1 account, 300 articles 30 list + 300 detail {{cost:wechat_mp.accounts.articles.list30+wechat_mp.articles.get300}}
10 accounts, newest 50 each 50 list + 500 detail {{cost:wechat_mp.accounts.articles.list50+wechat_mp.articles.get500}}
Links your team pastes in, 1,000 1,000 detail $20.00

Deleted articles come back as not_found and cost nothing.

import os, pathlib, requests

API = "https://api.okdata.online"
H = {"Authorization": f"Bearer {os.environ['OKDATA_API_KEY']}"}
OUT = pathlib.Path("kb/wechat"); OUT.mkdir(parents=True, exist_ok=True)

def save(url):
    body = requests.get(API + "/v1/wechat_mp/articles/get", headers=H, timeout=90,
                        params={"url": url, "view": "full"}).json()
    if body["code"] != "ok":
        print("skip", url, body["code"]); return
    a = body["data"]["item"]
    header = (f"---\ntitle: {a['title']!r}\naccount: {a['author']['name']!r}\n"
              f"published: {a['published_at']}\nsource: {a['url']}\n---\n\n")
    (OUT / f"{a['id']}.md").write_text(header + f"# {a['title']}\n\n" + a["text"], encoding="utf-8")

save("https://mp.weixin.qq.com/s/xxxxxxxx")

Chunk on blank lines, 300 to 800 Chinese characters per chunk, and carry the title and source link into every chunk's metadata so answers can cite the original.

Gotchas for a knowledge base

  • Reposts. Many accounts republish others' pieces. With view=full, ext.copyright and ext.source_url help you spot and drop duplicates before they skew retrieval.
  • Freshness. Re-run the history call weekly and fetch only links you don't have yet.
  • Rights. Index for internal research, keep the source link, and don't serve whole articles back to users.
  • Untrusted text. Article text is written by strangers. Tell the model to treat retrieved passages as data, not instructions.

Alternatives

Open-source exporters such as wechat-article-exporter save articles as HTML or Markdown with images, which is better for archiving or reading offline; they work through a WeChat backend login you provide. For a handful of articles, copy-paste into your notes tool is fine. For your own account, WeChat's official API returns the full article content directly. For research pipelines across platforms, see content research.

Updated