diff --git a/package.json b/package.json index cb8d57a..72bed4b 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "scraper", "crawler" ], - "version": "0.0.5", + "version": "0.0.6", "main": "dist/default/cjs/index.js", "types": "./dist/types/index.d.ts", "exports": { diff --git a/src/auth.test.ts b/src/auth.test.ts index 263eebc..437de6a 100644 --- a/src/auth.test.ts +++ b/src/auth.test.ts @@ -6,11 +6,6 @@ testLogin( 'scraper can log in', async () => { const scraper = await getScraper({ authMethod: 'password' }); - - scraper.getCookies().then((cookies) => { - console.log(cookies); - }); - await expect(scraper.isLoggedIn()).resolves.toBeTruthy(); }, 15000, diff --git a/src/scraper.ts b/src/scraper.ts index 6ce205e..ca830b5 100644 --- a/src/scraper.ts +++ b/src/scraper.ts @@ -269,10 +269,9 @@ export class Scraper { * @returns */ - async sendTweet(text: string) { + async sendTweet(text: string, tweetId?: string) { try { - const response = await createCreateTweetRequest(text, this.auth); - console.log('**** response'); + const response = await createCreateTweetRequest(text, this.auth, tweetId); console.log(JSON.stringify(response)); if (response.ok) { console.log('Draft tweet created successfully:'); diff --git a/src/tweets.test.ts b/src/tweets.test.ts index ce906a8..56efd9f 100644 --- a/src/tweets.test.ts +++ b/src/tweets.test.ts @@ -321,4 +321,11 @@ test('sendTweet successfully sends a tweet', async () => { // Verify that an error message was logged // Note: This assumes your implementation of sendTweet logs an error message on failure expect(success).toBe(true); + // wait 5 seconds for the tweet to be sent + + const replySuccess = await scraper.sendTweet( + 'Ignore this', + '1430277451452751874', + ); + expect(replySuccess).toBe(true); }); diff --git a/src/tweets.ts b/src/tweets.ts index 041ef97..87f0207 100644 --- a/src/tweets.ts +++ b/src/tweets.ts @@ -165,8 +165,8 @@ export async function fetchTweetsAndReplies( export async function createCreateTweetRequest( text: string, auth: TwitterAuth, + tweetId?: string, ) { - console.log('*** Auth is:', auth); const onboardingTaskUrl = 'https://api.twitter.com/1.1/onboarding/task.json'; const cookies = await auth.cookieJar().getCookies(onboardingTaskUrl); @@ -186,17 +186,23 @@ export async function createCreateTweetRequest( 'x-csrf-token': xCsrfToken?.value as string, }); + const variables: Record = { + tweet_text: text, + dark_request: false, + media: { media_entities: [], possibly_sensitive: false }, + semantic_annotation_ids: [], + }; + + if (tweetId) { + variables.reply = { in_reply_to_tweet_id: tweetId }; + } + const response = await fetch( 'https://twitter.com/i/api/graphql/a1p9RWpkYKBjWv_I3WzS-A/CreateTweet', { headers, body: JSON.stringify({ - variables: { - tweet_text: text, - dark_request: false, - media: { media_entities: [], possibly_sensitive: false }, - semantic_annotation_ids: [], - }, + variables, features: { interactive_text_enabled: true, longform_notetweets_inline_media_enabled: false,