···44 "context"
55 "encoding/json"
66 "fmt"
77+ "io"
78 "log/slog"
89 "net/http"
910 "net/url"
···112113 _, _ = w.Write(b)
113114}
114115116116+// FeedInteractions details the interactions that a user had with a feed when they viewed it
117117+type FeedInteractions struct {
118118+ Interactions []Interaction `json:"interactions"`
119119+}
120120+121121+type Interaction struct {
122122+ Item string `json:"item"`
123123+ Event string `json:"event"`
124124+}
125125+126126+// HandleFeedInteractions will handle when the client sends back a feed interaction so you can improve
127127+// the feed quality for the user
128128+func (s *Server) HandleFeedInteractions(w http.ResponseWriter, r *http.Request) {
129129+ slog.Debug("handle feed interactions")
130130+ userDID, err := getRequestUserDID(r)
131131+ if err != nil {
132132+ slog.Error("validate user auth", "error", err)
133133+ http.Error(w, "validate auth", http.StatusUnauthorized)
134134+ return
135135+ }
136136+137137+ body, err := io.ReadAll(r.Body)
138138+ if err != nil {
139139+ slog.Error("read feed interactions request body", "error", err)
140140+ http.Error(w, "read body", http.StatusBadRequest)
141141+ return
142142+ }
143143+144144+ var feedInteractions FeedInteractions
145145+ err = json.Unmarshal(body, &feedInteractions)
146146+ if err != nil {
147147+ slog.Error("decode feed interactions request body", "error", err)
148148+ http.Error(w, "decode body", http.StatusBadRequest)
149149+ return
150150+ }
151151+152152+ // here is where you would likely do something with the data that is sent to you such as improving the
153153+ // data you store for a users feed
154154+ for _, interaction := range feedInteractions.Interactions {
155155+ slog.Info("interaction for user", "user", userDID, "item", interaction.Item, "interaction", interaction.Event)
156156+ }
157157+}
158158+115159// WellKnownResponse is what's returned on a well-known endpoint
116160type WellKnownResponse struct {
117161 Context []string `json:"@context"`
+1
readme.md
···2525* FEED_DISPLAY_NAME - This is the name you will give your feed that users will be able to see
2626* FEED_DESCRIPTION - This is a description of your feed that users will be able to see
2727* FEED_DID - This is the DID that will be used to register the record. Unless you know what you are doing it's best to use `did:web:` + FEED_HOST_NAME (eg "did:web:demo-feed.com")
2828+* ACCEPTS_INTERACTIONS - Set this to be true if you wish your feed to accepts interactions such as "show more" or "show less"
28292930First you need to run the feed generator by building the application `go build -o demo-feed-generator ./cmd/feed-generator/main.go` and then running it `./demo-feed-generator`
3031