Skip to content

feat: add sendTweet with media upload support#193

Open
Faareoh wants to merge 4 commits into
the-convocation:mainfrom
Faareoh:feat/send-tweet
Open

feat: add sendTweet with media upload support#193
Faareoh wants to merge 4 commits into
the-convocation:mainfrom
Faareoh:feat/send-tweet

Conversation

@Faareoh
Copy link
Copy Markdown
Contributor

@Faareoh Faareoh commented Apr 10, 2026

⚠️ This PR was entirely generated by Claude (claude-sonnet-4-6), inspired by
the reference implementation at https://github.com/0x4337/agent-twitter-client-grokky.

Summary

  • src/api-data.ts — adds mutationEndpoints.CreateTweet (current queryId + x.com URL)
  • src/tweets.ts — implements uploadMedia() (chunked video + simple image) and sendTweet() returning Tweet | null
  • src/scraper.ts — exposes sendTweet() as a public method on the Scraper class
  • src/_module.ts — exports the new MediaData type
  • src/tweet-mutations.test.ts — unit tests + opt-in integration tests for the mutation

Key details

  • Uses the CreateTweet GraphQL mutation (queryId: S1qcGUn68_U0lDKdMlYSGg) via POST x.com/i/api/graphql/…
  • Injects __typename: 'Tweet' on the response when absent (the CreateTweet API omits it) so the existing parser can handle it
  • Generates x-client-transaction-id when the experimental.xClientTransactionId option is enabled, to avoid Twitter's 226 "looks automated" errors
  • MediaData accepts { data: Buffer, mediaType: string }; videos use the chunked INIT/APPEND/FINALIZE flow with status polling

Test plan

  • npm test — all unit tests pass
  • Integration tests run with real credentials: set TWITTER_* env vars and run npx jest tweet-mutations --testNamePattern=integration

Faareoh added 4 commits April 10, 2026 14:14
Adds scraper.sendTweet() for posting tweets via the CreateTweet GraphQL
mutation, including image/video media upload through the chunked upload API.

- Add mutationEndpoints (CreateTweet queryId + URL) to api-data.ts
- Implement uploadMedia() with chunked video upload + polling and simple
  image upload paths
- Implement sendTweet() returning Tweet | null; injects __typename when
  absent from the CreateTweet API response to satisfy the parser
- Add optional x-client-transaction-id generation to avoid 226 errors
- Expose sendTweet on the Scraper class and export MediaData from _module.ts
- Add unit + opt-in integration tests in tweet-mutations.test.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant