diff --git a/plugins/twitterPlugin/src/twitterPlugin.ts b/plugins/twitterPlugin/src/twitterPlugin.ts index 5e8b4549..1a014677 100644 --- a/plugins/twitterPlugin/src/twitterPlugin.ts +++ b/plugins/twitterPlugin/src/twitterPlugin.ts @@ -43,6 +43,7 @@ class TwitterPlugin { this.postTweetFunction, this.likeTweetFunction, this.quoteTweetFunction, + this.getFollowersFunction, ], getEnvironment: data?.getEnvironment || this.getMetrics.bind(this), }); @@ -220,6 +221,59 @@ class TwitterPlugin { }); } + get getFollowersFunction() { + return new GameFunction({ + name: "get_followers", + description: + "Retrieve the list of followers for a given user ID. Use this to analyze a user's audience or find potential accounts to engage with.", + args: [ + { name: "user_id", description: "The Twitter user ID to get followers for" }, + ] as const, + executable: async (args, logger) => { + try { + if (!args.user_id) { + return new ExecutableGameFunctionResponse( + ExecutableGameFunctionStatus.Failed, + "User ID is required" + ); + } + + logger(`Getting followers for user id: ${args.user_id}`); + + const followers = await this.twitterClient.v2.followers(args.user_id, { + max_results: 100, + "user.fields": ["public_metrics", "description"], + }); + + const feedbackMessage = + "Followers found:\n" + + JSON.stringify( + followers.data.map((user: any) => ({ + userId: user.id, + username: user.username, + name: user.name, + description: user.description, + followers: user.public_metrics?.followers_count, + following: user.public_metrics?.following_count, + })) + ); + + logger(feedbackMessage); + + return new ExecutableGameFunctionResponse( + ExecutableGameFunctionStatus.Done, + feedbackMessage + ); + } catch (e) { + return new ExecutableGameFunctionResponse( + ExecutableGameFunctionStatus.Failed, + "Failed to get followers" + ); + } + }, + }); + } + get quoteTweetFunction() { return new GameFunction({ name: "quote_tweet",