From 5a5688de7c807879e7c701d51607996700fd36e9 Mon Sep 17 00:00:00 2001 From: samarth30 Date: Tue, 17 Dec 2024 14:33:35 +0530 Subject: [PATCH] fix: added messages missing functions in scraper file --- src/scraper.ts | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/src/scraper.ts b/src/scraper.ts index bc3f2cd..e10af30 100644 --- a/src/scraper.ts +++ b/src/scraper.ts @@ -25,7 +25,7 @@ import { fetchProfileFollowers, getFollowing, getFollowers, - followUser + followUser, } from './relationships'; import { QueryProfilesResponse, QueryTweetsResponse } from './timeline-v1'; import { getTrends } from './trends'; @@ -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 = @@ -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, + ); } /** @@ -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, + ); } /** @@ -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( @@ -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 { + 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 { + return await sendDirectMessage(this.auth, conversationId, text); + } + private getAuthOptions(): Partial { return { fetch: this.options?.fetch,