@memberjunction/actions-bizapps-social
Version:
Social Media Actions for MemberJunction - Twitter, LinkedIn, Facebook, Instagram, TikTok, YouTube, HootSuite, Buffer
185 lines • 5.06 kB
TypeScript
import { BaseSocialMediaAction, MediaFile, SocialPost, SearchParams, SocialAnalytics } from '../../base/base-social.action';
import { AxiosInstance, AxiosError } from 'axios';
/**
* Base class for all Twitter/X actions.
* Handles Twitter-specific authentication, API interactions, and rate limiting.
* Uses Twitter API v2 with OAuth 2.0.
*/
export declare abstract class TwitterBaseAction extends BaseSocialMediaAction {
protected get platformName(): string;
protected get apiBaseUrl(): string;
/**
* Upload endpoint for media
*/
protected get uploadApiUrl(): string;
/**
* Axios instance for making HTTP requests
*/
private _axiosInstance;
/**
* Get or create axios instance with interceptors
*/
protected get axiosInstance(): AxiosInstance;
/**
* Refresh the access token using the refresh token
*/
protected refreshAccessToken(): Promise<void>;
/**
* Get the authenticated user's info
*/
protected getCurrentUser(): Promise<TwitterUser>;
/**
* Upload media to Twitter
*/
protected uploadSingleMedia(file: MediaFile): Promise<string>;
/**
* Wait for media processing to complete (for videos)
*/
private waitForMediaProcessing;
/**
* Get media category based on MIME type
*/
private getMediaCategory;
/**
* Validate media file meets Twitter requirements
*/
protected validateMediaFile(file: MediaFile): void;
/**
* Create a tweet
*/
protected createTweet(tweetData: CreateTweetData): Promise<Tweet>;
/**
* Delete a tweet
*/
protected deleteTweet(tweetId: string): Promise<void>;
/**
* Get tweets with specified parameters
*/
protected getTweets(endpoint: string, params?: Record<string, any>): Promise<Tweet[]>;
/**
* Get paginated tweets
*/
protected getPaginatedTweets(endpoint: string, params?: Record<string, any>, maxResults?: number): Promise<Tweet[]>;
/**
* Convert Twitter tweet to common format
*/
protected normalizePost(tweet: Tweet): SocialPost;
/**
* Normalize Twitter analytics to common format
*/
protected normalizeAnalytics(twitterMetrics: TwitterMetrics): SocialAnalytics;
/**
* Search for tweets - implemented in search action
*/
protected searchPosts(params: SearchParams): Promise<SocialPost[]>;
/**
* Handle Twitter-specific errors
*/
protected handleTwitterError(error: AxiosError): never;
/**
* Parse Twitter-specific rate limit headers
*/
protected parseRateLimitHeaders(headers: any): {
remaining: number;
reset: Date;
limit: number;
} | null;
/**
* Build search query with operators
*/
protected buildSearchQuery(params: SearchParams): string;
/**
* Format date for Twitter API (RFC 3339)
*/
protected formatTwitterDate(date: Date | string): string;
}
/**
* Twitter-specific interfaces
*/
export interface TwitterUser {
id: string;
name: string;
username: string;
profile_image_url?: string;
description?: string;
created_at: string;
verified?: boolean;
}
export interface CreateTweetData {
text: string;
media?: {
media_ids: string[];
};
poll?: {
options: string[];
duration_minutes: number;
};
reply?: {
in_reply_to_tweet_id: string;
};
quote_tweet_id?: string;
}
export interface Tweet {
id: string;
text: string;
created_at: string;
author_id?: string;
conversation_id?: string;
public_metrics?: {
retweet_count: number;
reply_count: number;
like_count: number;
quote_count: number;
bookmark_count: number;
impression_count: number;
};
attachments?: {
media_keys?: string[];
poll_ids?: string[];
};
entities?: {
hashtags?: Array<{
start: number;
end: number;
tag: string;
}>;
mentions?: Array<{
start: number;
end: number;
username: string;
}>;
urls?: Array<{
start: number;
end: number;
url: string;
expanded_url: string;
}>;
};
referenced_tweets?: Array<{
type: 'retweeted' | 'quoted' | 'replied_to';
id: string;
}>;
}
export interface TwitterMetrics {
impression_count: number;
engagement_count: number;
retweet_count: number;
reply_count: number;
like_count: number;
quote_count: number;
bookmark_count: number;
url_link_clicks: number;
user_profile_clicks: number;
video_view_count?: number;
}
export interface TwitterSearchParams {
query: string;
start_time?: string;
end_time?: string;
max_results?: number;
next_token?: string;
since_id?: string;
until_id?: string;
sort_order?: 'recency' | 'relevancy';
}
//# sourceMappingURL=twitter-base.action.d.ts.map