Skip to content

Commit

Permalink
[3/3] Get Poll Results and Standardize Return Type to Tweet
Browse files Browse the repository at this point in the history
  • Loading branch information
monilpat committed Nov 13, 2024
1 parent be8e901 commit 01c6eab
Show file tree
Hide file tree
Showing 4 changed files with 304 additions and 68 deletions.
20 changes: 7 additions & 13 deletions SampleAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,14 @@ async function main() {
// },
// },
// );
// console.log(await scraper.getTweet('id'));
// const tweet = await scraper.getTweetV2('1856441982811529619', {
// expansions: ['attachments.poll_ids'],
// pollFields: ['options', 'end_datetime'],
// });
// console.log(await scraper.getTweet('1856441982811529619'));
// const tweet = await scraper.getTweetV2('1856441982811529619');
// console.log({ tweet });
// console.log('tweet', tweet);
// const tweets = await scraper.getTweetsV2(
// ['1856441982811529619', '1856429655215260130'],
// {
// expansions: ['attachments.poll_ids', 'attachments.media_keys'],
// pollFields: ['options', 'end_datetime'],
// mediaFields: ['url', 'preview_image_url'],
// },
// );
// const tweets = await scraper.getTweetsV2([
// '1856441982811529619',
// '1856429655215260130',
// ]);
// console.log('tweets', tweets);
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "agent-twitter-client",
"description": "A twitter client for agents",
"type": "module",
"keywords": [
"x",
"twitter",
Expand Down
41 changes: 24 additions & 17 deletions src/scraper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ import {
} from './tweets';
import { parseTimelineTweetsV2, TimelineV2 } from './timeline-v2';
import { fetchHomeTimeline } from './timeline-home';
import { TweetV2 } from 'twitter-api-v2';
import {
TTweetv2Expansion,
TTweetv2MediaField,
TTweetv2PlaceField,
TTweetv2PollField,
TTweetv2TweetField,
TTweetv2UserField,
} from 'twitter-api-v2';

const twUrl = 'https://twitter.com';
const UserTweetsUrl =
Expand Down Expand Up @@ -557,15 +564,15 @@ export class Scraper {
*/
async getTweetV2(
id: string,
options?: {
expansions?: string[];
tweetFields?: string[];
pollFields?: string[];
mediaFields?: string[];
userFields?: string[];
placeFields?: string[];
options: {
expansions?: TTweetv2Expansion[];
tweetFields?: TTweetv2TweetField[];
pollFields?: TTweetv2PollField[];
mediaFields?: TTweetv2MediaField[];
userFields?: TTweetv2UserField[];
placeFields?: TTweetv2PlaceField[];
},
): Promise<TweetV2 | null> {
): Promise<Tweet | null> {
return await getTweetV2(id, this.auth, options);
}

Expand All @@ -585,15 +592,15 @@ export class Scraper {
*/
async getTweetsV2(
ids: string[],
options?: {
expansions?: string[];
tweetFields?: string[];
pollFields?: string[];
mediaFields?: string[];
userFields?: string[];
placeFields?: string[];
options: {
expansions?: TTweetv2Expansion[];
tweetFields?: TTweetv2TweetField[];
pollFields?: TTweetv2PollField[];
mediaFields?: TTweetv2MediaField[];
userFields?: TTweetv2UserField[];
placeFields?: TTweetv2PlaceField[];
},
): Promise<TweetV2[]> {
): Promise<Tweet[]> {
return await getTweetsV2(ids, this.auth, options);
}

Expand Down
Loading

0 comments on commit 01c6eab

Please sign in to comment.