mapInfluenceNetwork
Analyze and visualize Twitter user influence networks by mapping connections such as followers, following, and mutual links around a central user to uncover patterns and relationships.
Instructions
Map user influence network and connection patterns
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| centerUser | Yes | Central user to map network around | |
| connectionTypes | No | Types of connections to analyze | |
| depth | No | Network depth to analyze (default: 2) |
Implementation Reference
- The primary handler function implementing the mapInfluenceNetwork tool. It analyzes Twitter interactions (mentions) around a center user to build an influence network map, calculating connections, influence scores, and network metrics.export const handleMapInfluenceNetwork: SocialDataHandler<NetworkMappingArgs> = async ( _client: any, { centerUser, depth = 2, connectionTypes = ['followers', 'following', 'mutual'] }: NetworkMappingArgs ) => { try { const socialClient = getSocialDataClient(); if (!socialClient) { return createMissingApiKeyResponse('Influence Network Mapping'); } // Get users who frequently interact with the center user const mentionsQuery = `@${centerUser}`; const mentionsResult = await socialClient.searchTweets({ query: mentionsQuery, maxResults: 100 }); // Get users the center user mentions const centerMentionsQuery = `from:${centerUser} @`; const centerMentionsResult = await socialClient.searchTweets({ query: centerMentionsQuery, maxResults: 50 }); // Build network map const networkNodes = new Map(); // Add center user networkNodes.set(centerUser, { username: centerUser, type: 'center', connections: [], influence_score: 100 }); // Process mentions TO the center user (incoming connections) const incomingConnections = new Map(); mentionsResult.data?.forEach((tweet: any) => { const user = tweet.user; if (user && user.screen_name !== centerUser) { const existing = incomingConnections.get(user.screen_name) || 0; incomingConnections.set(user.screen_name, existing + 1); if (!networkNodes.has(user.screen_name)) { networkNodes.set(user.screen_name, { username: user.screen_name, name: user.name, type: 'incoming', mention_frequency: existing + 1, followers_count: user.followers_count, verified: user.verified, influence_score: Math.min(90, (user.followers_count || 0) / 1000) }); } } }); // Process mentions FROM the center user (outgoing connections) const outgoingConnections = new Set(); centerMentionsResult.data?.forEach((tweet: any) => { const mentions = tweet.text?.match(/@(\w+)/g) || []; mentions.forEach((mention: string) => { const username = mention.substring(1); if (username !== centerUser) { outgoingConnections.add(username); if (!networkNodes.has(username)) { networkNodes.set(username, { username, type: 'outgoing', influence_score: 50 }); } } }); }); // Calculate network metrics const networkMap = { center_user: centerUser, network_depth: depth, total_nodes: networkNodes.size, connection_types: connectionTypes, network_metrics: { incoming_connections: incomingConnections.size, outgoing_connections: outgoingConnections.size, total_unique_connections: new Set([...incomingConnections.keys(), ...outgoingConnections]).size, network_density: Math.round((incomingConnections.size + outgoingConnections.size) / 2), influence_centrality: Math.min(100, (incomingConnections.size * 2) + outgoingConnections.size) }, top_connected_users: Array.from(networkNodes.values()) .filter(node => node.type !== 'center') .sort((a, b) => (b.influence_score || 0) - (a.influence_score || 0)) .slice(0, 15) .map(node => ({ username: node.username, name: node.name, connection_type: node.type, influence_score: Math.round(node.influence_score || 0), followers: node.followers_count, verified: node.verified })), network_insights: { most_active_mentioner: Array.from(incomingConnections.entries()) .sort(([,a], [,b]) => b - a)[0]?.[0] || 'None', network_reach_estimate: Math.round( Array.from(networkNodes.values()) .reduce((sum, node) => sum + (node.followers_count || 0), 0) / 1000 ) + 'K', connection_strength: incomingConnections.size > 20 ? 'Strong' : incomingConnections.size > 5 ? 'Moderate' : 'Developing' } }; return createSocialDataResponse( formatAnalytics(networkMap, `Influence Network Map for @${centerUser}`) ); } catch (error) { throw new Error(formatSocialDataError(error as Error, 'influence network mapping')); } };
- src/socialdata-tools.ts:289-315 (schema)Tool registration definition including description and input schema (JSON Schema) for the mapInfluenceNetwork tool.mapInfluenceNetwork: { description: 'Map user influence network and connection patterns', inputSchema: { type: 'object', properties: { centerUser: { type: 'string', description: 'Central user to map network around' }, depth: { type: 'number', description: 'Network depth to analyze (default: 2)', minimum: 1, maximum: 3 }, connectionTypes: { type: 'array', items: { type: 'string', enum: ['followers', 'following', 'mutual'] }, description: 'Types of connections to analyze' } }, required: ['centerUser'] } },
- src/types/socialdata.ts:89-93 (schema)TypeScript interface defining the input arguments for the mapInfluenceNetwork handler.export interface NetworkMappingArgs { centerUser: string; depth?: number; connectionTypes?: ('followers' | 'following' | 'mutual')[]; }
- src/index.ts:483-486 (registration)Dispatch case in the main CallToolRequest handler that routes calls to mapInfluenceNetwork to the specific handler function.case 'mapInfluenceNetwork': { const args = request.params.arguments as any; response = await handleMapInfluenceNetwork(client, args); break;