this repo has no description
40
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix X mention username resolution and add user ID mapping

**Fixes the '@unknown (unknown)' issue:**
- Added fallback username resolution when thread_data['users'] lookup fails
- Scans thread tweets to find author info when primary lookup returns 'unknown'
- Logs successful fallback resolutions

**Added User ID Mapping Key:**
- Builds comprehensive user_id → @username mapping from thread data
- Appends USER_ID_KEY section to prompts showing all participants
- Helps void understand who is who when user IDs appear without handles

**Example output:**
```
USER_ID_KEY:
1232326955652931584: @cameron_pfiffer
1188460292998602752: @scholzmx
1950680610282094592: @void_comind
```

This resolves cases where the X API doesn't consistently provide usernames in mention data, using the thread context as a reliable fallback source.

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>

+36 -1
+36 -1
x.py
··· 1517 1517 author_username = author_info.get('username', 'unknown') 1518 1518 author_name = author_info.get('name', author_username) 1519 1519 1520 + # Fallback: if username is unknown, try to find it in the thread tweets 1521 + if author_username == 'unknown' and 'tweets' in thread_data: 1522 + for tweet in thread_data['tweets']: 1523 + if tweet.get('author_id') == author_id and 'author' in tweet: 1524 + tweet_author = tweet['author'] 1525 + if tweet_author.get('username'): 1526 + author_username = tweet_author['username'] 1527 + author_name = tweet_author.get('name', author_username) 1528 + logger.info(f"Resolved unknown author via thread fallback: @{author_username} ({author_name})") 1529 + break 1530 + 1531 + # Build user ID mapping from thread data 1532 + user_id_mapping = {} 1533 + if 'tweets' in thread_data: 1534 + for tweet in thread_data['tweets']: 1535 + author_id_tweet = tweet.get('author_id') 1536 + if author_id_tweet and 'author' in tweet: 1537 + tweet_author = tweet['author'] 1538 + username = tweet_author.get('username') 1539 + if username and author_id_tweet not in user_id_mapping: 1540 + user_id_mapping[author_id_tweet] = f"@{username}" 1541 + 1542 + # Also add users from the users dict if available 1543 + if 'users' in thread_data: 1544 + for user_id, user_data in thread_data['users'].items(): 1545 + username = user_data.get('username') 1546 + if username and user_id not in user_id_mapping: 1547 + user_id_mapping[user_id] = f"@{username}" 1548 + 1549 + # Format user ID mapping for prompt 1550 + id_mapping_text = "" 1551 + if user_id_mapping: 1552 + id_mapping_lines = [f" {user_id}: {handle}" for user_id, handle in user_id_mapping.items()] 1553 + id_mapping_text = f"\n\nUSER_ID_KEY:\n" + "\n".join(id_mapping_lines) 1554 + 1520 1555 prompt = f"""You received a mention on X (Twitter) from @{author_username} ({author_name}). 1521 1556 1522 1557 MOST RECENT POST (the mention you're responding to): ··· 1527 1562 {thread_context} 1528 1563 ``` 1529 1564 1530 - 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. 1565 + 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} 1531 1566 1532 1567 If you need to update user information, use the x_user_* tools. 1533 1568