getFullThread
Reconstruct complete Twitter threads with all tweets and replies from a starting tweet ID, providing full conversation context for analysis.
Instructions
Reconstruct complete Twitter thread with all tweets and replies
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tweetId | Yes | The ID of the tweet to analyze thread for | |
| includeMetrics | No | Include engagement metrics for each tweet (default: true) |
Implementation Reference
- The primary handler function that executes the getFullThread tool. It fetches conversation tweets using SocialData client, sorts them chronologically, computes thread metrics, and formats the response.export const handleGetFullThread: SocialDataHandler<FullThreadArgs> = async ( _client: any, { tweetId, includeMetrics = true }: FullThreadArgs ) => { try { const socialClient = getSocialDataClient(); if (!socialClient) { return createMissingApiKeyResponse('Full Thread Analysis'); } // Search for the original tweet and related conversation const mainTweetQuery = `conversation_id:${tweetId}`; const threadResult = await socialClient.searchTweets({ query: mainTweetQuery, maxResults: 100 }); if (!threadResult.data || threadResult.data.length === 0) { // Fallback: search for replies to the tweet const repliesQuery = `to:* in_reply_to_status_id:${tweetId}`; const repliesResult = await socialClient.searchTweets({ query: repliesQuery, maxResults: 50 }); return createSocialDataResponse( formatTweetList(repliesResult.data || [], `Thread replies for tweet ${tweetId}`) ); } // Sort by creation time to reconstruct thread order const sortedThread = threadResult.data.sort((a: any, b: any) => new Date(a.tweet_created_at).getTime() - new Date(b.tweet_created_at).getTime() ); const threadAnalysis = { thread_id: tweetId, total_tweets: sortedThread.length, thread_duration: sortedThread.length > 1 ? { start: sortedThread[0]?.tweet_created_at, end: sortedThread[sortedThread.length - 1]?.tweet_created_at } : null, tweets: sortedThread.map((tweet: any) => ({ id: tweet.id_str, text: tweet.text, author: tweet.user?.screen_name, created_at: tweet.tweet_created_at, metrics: includeMetrics ? { likes: tweet.favorite_count || 0, retweets: tweet.retweet_count || 0, replies: tweet.reply_count || 0 } : undefined })) }; return createSocialDataResponse( formatAnalytics(threadAnalysis, `Full Thread Analysis for ${tweetId}`) ); } catch (error) { throw new Error(formatSocialDataError(error as Error, 'full thread analysis')); } };
- src/socialdata-tools.ts:176-192 (schema)Defines the tool description and input schema (using JSON Schema) for validating getFullThread parameters: tweetId (required string), includeMetrics (optional boolean).getFullThread: { description: 'Reconstruct complete Twitter thread with all tweets and replies', inputSchema: { type: 'object', properties: { tweetId: { type: 'string', description: 'The ID of the tweet to analyze thread for' }, includeMetrics: { type: 'boolean', description: 'Include engagement metrics for each tweet (default: true)' } }, required: ['tweetId'] } },