diff --git a/x.py b/x.py index d893b11..b493a85 100644 --- a/x.py +++ b/x.py @@ -1517,6 +1517,41 @@ def process_x_mention(void_agent, x_client, mention_data, queue_filepath=None, t author_username = author_info.get('username', 'unknown') author_name = author_info.get('name', author_username) + # Fallback: if username is unknown, try to find it in the thread tweets + if author_username == 'unknown' and 'tweets' in thread_data: + for tweet in thread_data['tweets']: + if tweet.get('author_id') == author_id and 'author' in tweet: + tweet_author = tweet['author'] + if tweet_author.get('username'): + author_username = tweet_author['username'] + author_name = tweet_author.get('name', author_username) + logger.info(f"Resolved unknown author via thread fallback: @{author_username} ({author_name})") + break + + # Build user ID mapping from thread data + user_id_mapping = {} + if 'tweets' in thread_data: + for tweet in thread_data['tweets']: + author_id_tweet = tweet.get('author_id') + if author_id_tweet and 'author' in tweet: + tweet_author = tweet['author'] + username = tweet_author.get('username') + if username and author_id_tweet not in user_id_mapping: + user_id_mapping[author_id_tweet] = f"@{username}" + + # Also add users from the users dict if available + if 'users' in thread_data: + for user_id, user_data in thread_data['users'].items(): + username = user_data.get('username') + if username and user_id not in user_id_mapping: + user_id_mapping[user_id] = f"@{username}" + + # Format user ID mapping for prompt + id_mapping_text = "" + if user_id_mapping: + id_mapping_lines = [f" {user_id}: {handle}" for user_id, handle in user_id_mapping.items()] + id_mapping_text = f"\n\nUSER_ID_KEY:\n" + "\n".join(id_mapping_lines) + prompt = f"""You received a mention on X (Twitter) from @{author_username} ({author_name}). MOST RECENT POST (the mention you're responding to): @@ -1527,7 +1562,7 @@ FULL THREAD CONTEXT: {thread_context} ``` -The YAML above shows the complete conversation thread. The most recent post is the one mentioned above that you should respond to, but use the full thread context to understand the conversation flow. +The YAML above shows the complete conversation thread. The most recent post is the one mentioned above that you should respond to, but use the full thread context to understand the conversation flow.{id_mapping_text} If you need to update user information, use the x_user_* tools.