Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions plugins/twitterPlugin/src/twitterPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class TwitterPlugin {
this.postTweetFunction,
this.likeTweetFunction,
this.quoteTweetFunction,
this.getFollowersFunction,
],
getEnvironment: data?.getEnvironment || this.getMetrics.bind(this),
});
Expand Down Expand Up @@ -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",
Expand Down