diff --git a/README.md b/README.md index 231976b..0158651 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,24 @@ Environment shortcuts: - `read` returns full text for Notes and Articles when present. - Use `--plain` for stable, script-friendly output (no emoji, no color). +### JSON Schema + +When using `--json`, tweet objects include: + +| Field | Type | Description | +|-------|------|-------------| +| `id` | string | Tweet ID | +| `text` | string | Full tweet text (includes Note/Article content when present) | +| `author` | object | `{ username, name }` | +| `authorId` | string | Author's user ID | +| `createdAt` | string | Timestamp | +| `replyCount` | number | Number of replies | +| `retweetCount` | number | Number of retweets | +| `likeCount` | number | Number of likes | +| `conversationId` | string | Thread conversation ID | +| `inReplyToStatusId` | string? | Parent tweet ID (present if this is a reply) | +| `quotedTweet` | object? | Embedded quote tweet with `{ id, text, author, authorId }` (present if this is a quote tweet) | + ## Query IDs (GraphQL) X rotates GraphQL “query IDs” frequently. Each GraphQL operation is addressed as: diff --git a/src/lib/twitter-client.ts b/src/lib/twitter-client.ts index e5f5379..7a957b7 100644 --- a/src/lib/twitter-client.ts +++ b/src/lib/twitter-client.ts @@ -180,6 +180,9 @@ type GraphqlTweetResult = { }>; }>; }; + quoted_status_result?: { + result?: GraphqlTweetResult; + }; }; export type TweetResult = @@ -212,6 +215,15 @@ export interface TweetData { likeCount?: number; conversationId?: string; inReplyToStatusId?: string; + quotedTweet?: { + id: string; + text: string; + author: { + username: string; + name: string; + }; + authorId?: string; + }; } export interface GetTweetResult { @@ -686,6 +698,29 @@ export class TwitterClient { const text = this.extractTweetText(result); if (!text) return undefined; + // Extract quoted tweet if present + let quotedTweet: TweetData['quotedTweet'] = undefined; + const quotedResult = result.quoted_status_result?.result; + if (quotedResult?.rest_id) { + const quotedUserResult = quotedResult?.core?.user_results?.result; + const quotedUserLegacy = quotedUserResult?.legacy; + const quotedUserCore = quotedUserResult?.core; + const quotedUsername = quotedUserLegacy?.screen_name ?? quotedUserCore?.screen_name; + const quotedName = quotedUserLegacy?.name ?? quotedUserCore?.name ?? quotedUsername; + const quotedText = this.extractTweetText(quotedResult); + if (quotedUsername && quotedText) { + quotedTweet = { + id: quotedResult.rest_id, + text: quotedText, + author: { + username: quotedUsername, + name: quotedName || quotedUsername, + }, + authorId: quotedUserResult?.rest_id, + }; + } + } + return { id: result.rest_id, text, @@ -700,6 +735,7 @@ export class TwitterClient { name: name || username, }, authorId: userId, + quotedTweet, }; }