feat: support rich content in long-form tweets (X Articles)

Add support for extracting rich content from X's long-form tweets,
including embedded code snippets, markdown blocks, quoted tweets,
and other structured content that was previously lost.

Changes:
- Add fieldToggles with withArticleRichContentState to TweetDetail API request
- Implement Draft.js content_state parser (renderContentState) that converts
  blocks and entities to readable markdown format
- Add content_state type definition to GraphqlTweetResult

Supported content:
- Block types: paragraphs, headers, ordered/unordered lists, blockquotes
- Entity types: MARKDOWN (code blocks), DIVIDER, TWEET, LINK, IMAGE

No impact on regular tweets - rich content only adds payload when present.

Includes 20 unit tests for the parser and an opt-in live smoke test.

Co-authored-by: Christian Catalan <[email protected]>
This commit is contained in:
cc-vps
2026-01-12 05:12:33 +00:00
committed by Peter Steinberger
co-authored by Christian Catalan
parent e0b960db1a
commit 316cdf77be
5 changed files with 615 additions and 0 deletions
+19
View File
@@ -130,6 +130,25 @@ export type GraphqlTweetResult = {
};
}>;
}>;
/** Draft.js content state for rich article content */
content_state?: {
blocks: Array<{
key: string;
type: string;
text: string;
data?: Record<string, unknown>;
entityRanges: Array<{ key: number; offset: number; length: number }>;
inlineStyleRanges: Array<{ offset: number; length: number; style: string }>;
}>;
entityMap: Array<{
key: string;
value: {
type: string;
mutability: string;
data: Record<string, unknown>;
};
}>;
};
};
};
plain_text?: string;