Conversation
📝 WalkthroughWalkthroughAdded Twitter integration to the indexer: new direct dependency on Changes
Sequence DiagramsequenceDiagram
participant Indexer
participant ImageService
participant TelegramAPI as Telegram API
participant TwitterAPI as Twitter API
Indexer->>Indexer: Start (check TWITTER_* envs)
alt credentials present
Indexer->>TwitterAPI: Initialize client
TwitterAPI-->>Indexer: Client ready
end
loop on block event
Indexer->>ImageService: getDuckImage()
ImageService-->>Indexer: duckImageURL
Indexer->>ImageService: downloadImage(duckImageURL)
ImageService-->>Indexer: image bytes
Indexer->>TelegramAPI: send photo with image
alt twitterEnabled
Indexer->>TwitterAPI: sendTweet(text[, image])
TwitterAPI-->>Indexer: post response
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
main.go (1)
477-487:log.Fatalwill crash the application on transient API failures.Using
log.FatalingetDuckImagewill terminate the entire indexer if the random-d.uk API is temporarily unavailable. Additionally, the type assertion on line 485 can panic if the response doesn't contain a"url"string field.Suggested fix: Return error and use fallback
-func getDuckImage() string { +func getDuckImage() (string, error) { + const fallbackImage = "https://random-d.uk/api/1.gif" // or your preferred fallback resp, err := http.Get("https://random-d.uk/api/v2/random") if err != nil { - log.Fatal(err) + return fallbackImage, fmt.Errorf("failed to fetch duck image: %w", err) } defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + return fallbackImage, fmt.Errorf("duck API returned status %d", resp.StatusCode) + } + var result map[string]interface{} - json.NewDecoder(resp.Body).Decode(&result) - imageURL := result["url"].(string) - return imageURL + if err := json.NewDecoder(resp.Body).Decode(&result); err != nil { + return fallbackImage, fmt.Errorf("failed to decode duck response: %w", err) + } + + imageURL, ok := result["url"].(string) + if !ok || imageURL == "" { + return fallbackImage, fmt.Errorf("invalid url in duck response") + } + return imageURL, nil }Then update the caller in
handleEventto handle the error appropriately.
🤖 Fix all issues with AI agents
In `@main.go`:
- Around line 407-423: The call to i.sendTweet(tweetMsg, duckImageURL) passes an
image URL that sendTweet ignores; either remove the unused duckImageURL
parameter from the call and update the sendTweet method signature (and all
callers) to accept only the message, or implement media upload support inside
sendTweet (use Twitter media upload API, attach returned media_id when posting)
so the duckImageURL is actually uploaded and attached; locate the sendTweet
method and update its signature and implementation (and any other callers)
accordingly to keep signatures consistent.
🧹 Nitpick comments (2)
main.go (2)
489-507: Unused function:downloadImageis never called.This function appears to have been added for Twitter media upload support, but it's not used anywhere in the codebase. Consider either:
- Removing it if image upload isn't planned
- Integrating it into
sendTweetif image attachment is intended#!/bin/bash # Verify downloadImage is not called anywhere rg -n "downloadImage" --type go
509-528: UnusedimageURLparameter should be removed or implemented.The
imageURLparameter insendTweetis declared but never used. This creates confusion about the function's intended behavior.If text-only tweets are the final design
-func (i *Indexer) sendTweet(text string, imageURL string) error { +func (i *Indexer) sendTweet(text string) error { if !i.twitterEnabled || i.twitterClient == nil { return nil } // Create tweet request input := &types.CreateInput{ Text: gotwi.String(text), } // Post the tweet _, err := managetweet.Create(context.Background(), i.twitterClient, input) if err != nil { return fmt.Errorf("failed to post tweet: %w", err) } log.Println("Tweet posted successfully") return nil }
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
go.sumis excluded by!**/*.sum
📒 Files selected for processing (2)
go.modmain.go
🔇 Additional comments (4)
main.go (2)
76-78: LGTM!The new Twitter-related fields are appropriately added to the Indexer struct. Using a separate
twitterEnabledflag alongside the client pointer provides a clean guard for conditional Twitter functionality.
148-172: Good graceful degradation pattern.The Twitter client initialization properly handles missing credentials and initialization failures without crashing the application. The conditional check for all four environment variables before attempting initialization is appropriate.
go.mod (2)
25-25: Verify if the adder v0.35.0 update intentionally requires gouroboros v0.146.0.The
gouroborosversion is an indirect dependency determined bygithub.com/blinklabs-io/adder v0.35.0. Check the adder changelog or go.mod to confirm whether the v0.146.0 requirement is intentional and compatible with your use case.
13-13: v0.18.1 is a valid release and the API usage in main.go aligns with this version. No action needed.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
| // Send tweet if Twitter is enabled (shorter format for 280 char limit) | ||
| if i.twitterEnabled { | ||
| tweetMsg := fmt.Sprintf( | ||
| "🦆 New Block!\n\n"+ | ||
| "Pool: %s\n"+ | ||
| "Tx: %d | Size: %.2fKB\n"+ | ||
| "Epoch: %d | Lifetime: %d\n\n"+ | ||
| "pooltool.io/realtime/%d", | ||
| i.poolName, blockEvent.Payload.TransactionCount, blockSizeKB, | ||
| i.epochBlocks, i.totalBlocks, | ||
| blockEvent.Context.BlockNumber) | ||
|
|
||
| err = i.sendTweet(tweetMsg, duckImageURL) | ||
| if err != nil { | ||
| log.Printf("failed to send tweet: %s", err) | ||
| } | ||
| } |
There was a problem hiding this comment.
The imageURL parameter is passed but not used.
The duckImageURL is passed to sendTweet() but the function ignores it and only posts text. If image attachment is intended, the Twitter media upload API needs to be integrated. If text-only tweets are the goal, consider removing the unused parameter to avoid confusion.
Option 1: Remove unused parameter if text-only is intended
- err = i.sendTweet(tweetMsg, duckImageURL)
+ err = i.sendTweet(tweetMsg)And update the function signature accordingly.
🤖 Prompt for AI Agents
In `@main.go` around lines 407 - 423, The call to i.sendTweet(tweetMsg,
duckImageURL) passes an image URL that sendTweet ignores; either remove the
unused duckImageURL parameter from the call and update the sendTweet method
signature (and all callers) to accept only the message, or implement media
upload support inside sendTweet (use Twitter media upload API, attach returned
media_id when posting) so the duckImageURL is actually uploaded and attached;
locate the sendTweet method and update its signature and implementation (and any
other callers) accordingly to keep signatures consistent.
feat(twitter posts): long live duckBot
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.