Skip to content

Create tweets.go#85

Open
drQedwards wants to merge 1 commit into
xdevplatform:mainfrom
drQedwards:patch-1
Open

Create tweets.go#85
drQedwards wants to merge 1 commit into
xdevplatform:mainfrom
drQedwards:patch-1

Conversation

@drQedwards

Copy link
Copy Markdown

✅ PR Ready (Simulated)

Pull Request Details for xdevplatform/xurl

Title:
feat: add full long-form tweet support (note_tweet, article, quoted_status) + $ticker Solana graph linking

Branch: feat/long-form-tickers (from main)

Files Changed:

  • api/tweets.go (new file)
  • (You would also update api/client.go, api/shortcuts.go, tests, README, etc. in a real PR)

Diff for api/tweets.go (New File)

You can copy this into the repo.

diff --git a/api/tweets.go b/api/tweets.go
new file mode 100644
index 0000000..abc1234
--- /dev/null
+++ b/api/tweets.go
@@ -0,0 +1,92 @@
+package api
+
+import (
+	"fmt"
+	"regexp"
+	"strings"
+)
+
+// DefaultTweetFields includes long-form and article support
+var DefaultTweetFields = []string{
+	"created_at",
+	"public_metrics",
+	"conversation_id",
+	"in_reply_to_user_id",
+	"referenced_tweets",
+	"entities",
+	"attachments",
+	"note_tweet",
+	"article",
+	"quoted_status",
+}
+
+// TweetOptions for rich tweet requests
+type TweetOptions struct {
+	Fields     []string
+	Expansions []string
+}
+
+func NewTweetOptions() *TweetOptions {
+	return &TweetOptions{
+		Fields: DefaultTweetFields,
+		Expansions: []string{
+			"author_id",
+			"referenced_tweets.id",
+			"quoted_status_id",
+			"attachments.media_keys",
+		},
+	}
+}
+
+// GetTweet fetches a tweet with full long-form support
+func (c *Client) GetTweet(tweetID string, opts *TweetOptions) (*TweetResponse, error) {
+	if opts == nil {
+		opts = NewTweetOptions()
+	}
+	fieldsStr := strings.Join(opts.Fields, ",")
+	expansionsStr := strings.Join(opts.Expansions, ",")
+
+	endpoint := fmt.Sprintf("/2/tweets/%s?tweet.fields=%s&expansions=%s&user.fields=username,name,verified", tweetID, fieldsStr, expansionsStr)
+
+	var resp TweetResponse
+	err := c.execute("GET", endpoint, nil, &resp)
+	if err != nil {
+		return nil, err
+	}
+	return &resp, nil
+}
+
+// EnrichWithTickerLinks converts $TICKER to Solana graph links (like stock tickers)
+func EnrichWithTickerLinks(text string) string {
+	re := regexp.MustCompile(`\$([A-Z0-9]+)`)
+	return re.ReplaceAllStringFunc(text, func(match string) string {
+		ticker := strings.TrimPrefix(match, "$")
+		link := fmt.Sprintf("https://dexscreener.com/solana/%s", strings.ToLower(ticker))
+		return fmt.Sprintf(`<a href="%s" target="_blank" class="ticker-link">$%s 📈</a>`, link, ticker)
+	})
+}
+
+type TweetResponse struct {
+	Data struct {
+		ID            string `json:"id"`
+		Text          string `json:"text"`
+		NoteTweet     *struct{ Text string `json:"text"` } `json:"note_tweet"`
+		Article       *struct {
+			ID        string `json:"id"`
+			Title     string `json:"title"`
+			Preview   string `json:"preview"`
+			PlainText string `json:"plain_text,omitempty"`
+		} `json:"article"`
+		QuotedStatus *TweetResponse `json:"quoted_status"`
+		Entities     *struct {
+			Symbols []struct {
+				Text    string `json:"text"`
+				Indices []int  `json:"indices"`
+			} `json:"symbols"`
+		} `json:"entities"`
+		PublicMetrics map[string]int `json:"public_metrics"`
+	} `json:"data"`
+}
+
+func (t *TweetResponse) GetFullText() string {
+	if t.Data.NoteTweet != nil && t.Data.NoteTweet.Text != "" {
+		return t.Data.NoteTweet.Text
+	}
+	return t.Data.Text
+}

Next Steps to Submit Real PR

  1. Fork https://github.com/xdevplatform/xurl
  2. Create branch feat/long-form-tickers
  3. Add the file above + update other files (client.go, shortcuts.go, README.md, CHANGELOG.md)
  4. Commit with message: feat: long-form quoting + $ticker Solana links
  5. Push & open PR

PR Description Template (copy this):

Adds comprehensive support for long-form Posts via note_tweet and article fields, quoted long-form content, and enriches $TICKER symbols with direct links to Solana graphs (e.g. Dexscreener).

Would you like me to generate the full set of files (client.go updates, README patch, changelog, etc.) or a complete git diff?

Signed-off-by: Dr. Q and Company <213266729+drQedwards@users.noreply.github.com>
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.

1 participant