Skip to content

Fix postImmediate API to return Twitter username instead of display name for correct tweet links#6

Closed
Copilot wants to merge 1 commit intomainfrom
copilot/fix-cccc3404-bdde-4d5d-a38e-12a133e95fa5
Closed

Fix postImmediate API to return Twitter username instead of display name for correct tweet links#6
Copilot wants to merge 1 commit intomainfrom
copilot/fix-cccc3404-bdde-4d5d-a38e-12a133e95fa5

Conversation

Copy link
Copy Markdown

Copilot AI commented Jul 21, 2025

Problem

The postImmediate API endpoint was returning the Twitter account's display name instead of the username/handle, causing the frontend to build incorrect tweet links.

Before:

  • API returned accountName: account.name (display name like "John Doe")
  • Frontend built links: https://x.com/John Doe/status/123 ❌ (broken)

After:

  • API returns accountName: me.username (handle like "johndoe")
  • Frontend builds links: https://x.com/johndoe/status/123 ✅ (working)

Changes

  1. Added Twitter user data fetch: After successfully posting a tweet, the handler now calls client.v2.me() to fetch the authenticated user's Twitter profile data

  2. Updated response format:

    // Before
    return c.json({
      success: true,
      tweetId: res.data.id,
      accountId: account.id,
      accountName: account.name, // Display name
    })
    
    // After
    return c.json({
      tweetId: res.data.id,
      accountName: me.username,  // Twitter handle
      accountId: dbAccount.id,
    })
  3. Removed unnecessary fields: Removed the success: true field as it wasn't needed for the frontend functionality

Technical Details

  • Uses the same destructuring pattern as other TwitterApi calls in the codebase: const { data: me } = await client.v2.me()
  • Maintains backward compatibility with the frontend expecting tweetId, accountName, and accountId
  • Minimal impact: only 3 lines changed in the postImmediate handler
  • No breaking changes to other functionality

Testing

The fix ensures that when users post tweets immediately via the API, the frontend receives the correct Twitter username to build properly formatted tweet links that work on X/Twitter.

This pull request was created as a result of the following prompt from Copilot chat.

When a tweet is posted immediately via the postImmediate API in src/server/routers/tweet-router.ts, the response currently returns only { success: true }. The front-end then tries to build a link using data.accountName, but since no accountName is returned, it defaults to the display name instead of the Twitter handle.

Tasks:

  1. In the postImmediate handler, after successfully sending the tweet (client.v2.tweet), call client.v2.me() to fetch the authenticated user’s Twitter username.
  2. Update the DB update logic remains unchanged.
  3. Return a JSON response with { tweetId: res.data.id, accountName: me.data.username, accountId: dbAccount.id } instead of { success: true }.
  4. Ensure there is no stray return c.json({ success: true }) at the end of the handler.

This will allow the front-end to correctly build the Tweet link as https://x.com/${accountName}/status/${tweetId}.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@vercel
Copy link
Copy Markdown

vercel bot commented Jul 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
contentport ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 21, 2025 6:26pm

@jcodog jcodog closed this Jul 21, 2025
@jcodog jcodog deleted the copilot/fix-cccc3404-bdde-4d5d-a38e-12a133e95fa5 branch July 21, 2025 18:28
Copilot AI restored the copilot/fix-cccc3404-bdde-4d5d-a38e-12a133e95fa5 branch July 21, 2025 18:33
Copilot AI changed the title [WIP] Use Twitter username in postImmediate tweet link Fix postImmediate API to return Twitter username instead of display name for correct tweet links Jul 21, 2025
Copilot AI requested a review from jcodog July 21, 2025 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants