Skip to content

Commit

Permalink
fix: added messages missing functions in scraper file
Browse files Browse the repository at this point in the history
  • Loading branch information
samarth30 committed Dec 17, 2024
1 parent bab20b8 commit 5a5688d
Showing 1 changed file with 46 additions and 4 deletions.
50 changes: 46 additions & 4 deletions src/scraper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
fetchProfileFollowers,
getFollowing,
getFollowers,
followUser
followUser,
} from './relationships';
import { QueryProfilesResponse, QueryTweetsResponse } from './timeline-v1';
import { getTrends } from './trends';
Expand Down Expand Up @@ -64,6 +64,12 @@ import {
TTweetv2TweetField,
TTweetv2UserField,
} from 'twitter-api-v2';
import {
DirectMessagesResponse,
getDirectMessageConversations,
sendDirectMessage,
SendDirectMessageResponse,
} from './messages';

const twUrl = 'https://twitter.com';
const UserTweetsUrl =
Expand Down Expand Up @@ -448,7 +454,12 @@ export class Scraper {
replyToTweetId?: string,
mediaData?: { data: Buffer; mediaType: string }[],
) {
return await createCreateTweetRequest(text, this.auth, replyToTweetId, mediaData);
return await createCreateTweetRequest(
text,
this.auth,
replyToTweetId,
mediaData,
);
}

/**
Expand All @@ -463,7 +474,12 @@ export class Scraper {
replyToTweetId?: string,
mediaData?: { data: Buffer; mediaType: string }[],
) {
return await createCreateLongTweetRequest(text, this.auth, replyToTweetId, mediaData);
return await createCreateLongTweetRequest(
text,
this.auth,
replyToTweetId,
mediaData,
);
}

/**
Expand Down Expand Up @@ -780,7 +796,7 @@ export class Scraper {
text: string,
quotedTweetId: string,
options?: {
mediaData: { data: Buffer; mediaType: string }[],
mediaData: { data: Buffer; mediaType: string }[];
},
) {
return await createQuoteTweetRequest(
Expand Down Expand Up @@ -821,6 +837,32 @@ export class Scraper {
await followUser(userName, this.auth);
}

/**
* Fetches direct message conversations
* @param count Number of conversations to fetch (default: 50)
* @param cursor Pagination cursor for fetching more conversations
* @returns Array of DM conversations and other details
*/
public async getDirectMessageConversations(
userId: string,
cursor?: string,
): Promise<DirectMessagesResponse> {
return await getDirectMessageConversations(userId, this.auth, cursor);
}

/**
* Sends a direct message to a user.
* @param conversationId The ID of the conversation to send the message to.
* @param text The text of the message to send.
* @returns The response from the Twitter API.
*/
public async sendDirectMessage(
conversationId: string,
text: string,
): Promise<SendDirectMessageResponse> {
return await sendDirectMessage(this.auth, conversationId, text);
}

private getAuthOptions(): Partial<TwitterAuthOptions> {
return {
fetch: this.options?.fetch,
Expand Down

0 comments on commit 5a5688d

Please sign in to comment.