Activity Feeds v3 is in beta — try it out!

Activities and Enrichment

Overview

Collections are added to activities in the form of collection references. An activity can reference up to 10 collections.

Support for adding collections directly when creating activities is coming soon.

Adding Collections to an Activity

feedsClient := client.Feeds()
response, err := feedsClient.AddActivity(context.Background(), &getstream.AddActivityRequest{
	Type:          "post",
	Feeds:         []string{"user:jack"},
	Text:          getstream.PtrTo("I love this movie!"),
	UserID:        getstream.PtrTo("jack"),
	CollectionRefs: []string{"movies:lord_of_the_rings"},
})
if err != nil {
	log.Fatal("Error adding activity:", err)
}

Enrichment

When you have added collection references to your activities these will automatically be enriched with the collection data when reading feeds.

// Create a collection
_, err := client.Feeds().CreateCollections(context.Background(), &getstream.CreateCollectionsRequest{
	Collections: []getstream.CollectionRequest{
		{
			Name: "movies",
			ID:   "lord_of_the_rings",
			Custom: map[string]any{
				"title":  "Lord of the Rings",
				"genre":  "fantasy",
				"rating": 9,
			},
		},
	},
})
if err != nil {
	log.Fatal("Error creating collections:", err)
}

// Add the reference to an activity
feedsClient := client.Feeds()
feed := feedsClient.Feed("user", "jack")
_, err = feedsClient.AddActivity(context.Background(), &getstream.AddActivityRequest{
	Type:          "post",
	Feeds:         []string{"user:jack"},
	Text:          getstream.PtrTo("I love this movie!"),
	UserID:        getstream.PtrTo("jack"),
	CollectionRefs: []string{"movies:lord_of_the_rings"},
})
if err != nil {
	log.Fatal("Error adding activity:", err)
}

// Read the feed and see the enriched collection data
response, err := feed.GetOrCreate(context.Background(), &getstream.GetOrCreateFeedRequest{
	UserID: getstream.PtrTo("jack"),
})
if err != nil {
	log.Fatal("Error reading feed:", err)
}
activities := response.Data.Activities
// The activities will contain enriched collection data in the collections field
// Example response structure:
// {
//     "activities": [
//         {
//             "type": "post",
//             "text": "I love this movie!",
//             "collections": {
//                 "movies:lord_of_the_rings": {
//                     "name": "movies",
//                     "id": "lord_of_the_rings",
//                     "custom": {
//                         "title": "Lord of the Rings",
//                         "genre": "fantasy",
//                         "rating": 9
//                     },
//                     "user_id": "jack",
//                     "created_at": "2025-01-01T00:00:00.000Z",
//                     "updated_at": "2025-01-01T00:00:00.000Z",
//                     "status": "ok"
//                 }
//             }
//         }
//     ],
//     ...
// }

The enrichment is a best effort process. Missing or deleted collections will not be enriched but will be retured with a status of notfound

© Getstream.io, Inc. All Rights Reserved.