summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go40
1 files changed, 34 insertions, 6 deletions
diff --git a/main.go b/main.go
index 7113036..e5ed1b0 100644
--- a/main.go
+++ b/main.go
@@ -2,14 +2,26 @@ package main
import (
"encoding/json"
+ "fmt"
"log"
"os"
"os/signal"
+ "strings"
+ "time"
"github.com/gorilla/websocket"
"github.com/nats-io/nats.go"
)
+type BlueskyPost struct {
+ Op string `json:"op"`
+ Repo string `json:"repo"`
+ Record struct {
+ Text string `json:"text"`
+ CreatedAt time.Time `json:"createdAt"`
+ } `json:"record"`
+}
+
func main() {
// Connect to NATS
nc, err := nats.Connect(nats.DefaultURL)
@@ -34,16 +46,32 @@ func main() {
return
}
- // Verify that the message is valid JSON
- var jsonMsg json.RawMessage
- if err := json.Unmarshal(message, &jsonMsg); err != nil {
- log.Println("Received non-JSON message, skipping")
+ var post BlueskyPost
+ if err := json.Unmarshal(message, &post); err != nil {
+ log.Println("Error unmarshaling JSON:", err)
continue
}
- // Publish the JSON message to NATS
- if err := nc.Publish("bsky.feed.post", message); err != nil {
+ // Extract user ID from repo field
+ userID := strings.Split(post.Repo, ".")[0]
+
+ // Determine post type (simplified for this example)
+ postType := "text"
+ if strings.Contains(post.Record.Text, "http") {
+ postType = "link"
+ }
+
+ // Create a more detailed NATS subject
+ subject := fmt.Sprintf("bsky.feed.post.user.%s.type.%s.time.%s",
+ userID,
+ postType,
+ post.Record.CreatedAt.Format("20060102"))
+
+ // Publish the JSON message to NATS with the detailed subject
+ if err := nc.Publish(subject, message); err != nil {
log.Println("Error publishing to NATS:", err)
+ } else {
+ log.Printf("Published message to subject: %s", subject)
}
}
}()