Skip to content

Commit

Permalink
first pass implementing twitter account mentions action
Browse files Browse the repository at this point in the history
  • Loading branch information
stat committed Nov 14, 2024
1 parent 9cb7e9b commit 134f418
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from cdp_agentkit_core.actions.social.twitter.account_details import AccountDetailsAction
from cdp_agentkit_core.actions.social.twitter.account_mentions import AccountMentionsAction
from cdp_agentkit_core.actions.social.twitter.action import TwitterAction
from cdp_agentkit_core.actions.social.twitter.post_tweet import PostTweetAction

Expand All @@ -16,6 +17,7 @@ def get_all_twitter_actions() -> list[type[TwitterAction]]:
__all__ = [
"TwitterAction",
"AccountDetailsAction",
"AccountMentionsAction",
"PostTweetAction",
"TWITTER_ACTIONS",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from collections.abc import Callable
from json import dumps

import tweepy
from pydantic import BaseModel, Field

from cdp_agentkit_core.actions.social.twitter.action import TwitterAction

ACCOUNT_MENTIONS_PROMPT = """
This tool will return account mentions for the currently authenticated Twitter (X) user context."""


class AccountMentionsInput(BaseModel):
"""Input argument schema for Twitter account mentions action."""

account_id: str = Field(
...,
description="The account id for the Twitter (X) user to get mentions for",
)


def account_mentions(client: tweepy.Client, account_id: str) -> str:
"""Get the authenticated Twitter (X) user account mentions.
Args:
client (tweepy.Client): The Twitter (X) client used to authenticate with.
account_id (str): The Twitter (X) account id to get mentions for.
Returns:
str: A message containing account mentions for the authenticated user context.
"""
message = ""

try:
response = client.get_users_mentions(account_id)
mentions = response.data

message = f"Successfully retrieved authenticated user account mentions:{dumps(mentions)}"
except tweepy.errors.TweepyException as e:
message = f"Error retrieving authenticated user account mentions: {e}"

return message


class AccountMentionsAction(TwitterAction):
"""Twitter (X) account mentions action."""

name: str = "account_mentions"
description: str = ACCOUNT_MENTIONS_PROMPT
args_schema: type[BaseModel] | None = AccountMentionsInput
func: Callable[..., str] = account_mentions

0 comments on commit 134f418

Please sign in to comment.