let response = try await feed.addActivity(
request: .init(
type: "post",
text: "I love this movie!",
collectionRefs: ["movies:lord_of_the_rings"]
)
)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
val response: Result<ActivityData> = feed.addActivity(
request = FeedAddActivityRequest(
type = "post",
text = "I love this movie!",
collectionRefs = listOf("movies:lord_of_the_rings")
)
)const response = await feed.addActivity({
type: "post",
text: "I love this movie!",
collection_refs: ["movies:lord_of_the_rings"],
});const response = await client.feeds.addActivity({
type: 'post',
feeds: [...],
text: 'I love this movie!',
collection_refs: ['movies:lord_of_the_rings'],
});final response = await feed.addActivity(
request: const FeedAddActivityRequest(
type: 'post',
text: 'I love this movie!',
collectionRefs: ['movies:lord_of_the_rings'],
),
);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)
}AddActivityRequest activity =
AddActivityRequest.builder()
.type("post")
.feeds(List.of("user:jack"))
.text("I love this movie!")
.userID("jack")
.collectionRefs(List.of("movies:lord_of_the_rings"))
.build();
AddActivityResponse response = feeds.addActivity(activity).execute().getData();$activity = new GeneratedModels\AddActivityRequest(
type: 'post',
feeds: ['user:jack'],
text: 'I love this movie!',
userID: 'jack',
collectionRefs: ['movies:lord_of_the_rings']
);
$response = $feedsClient->addActivity($activity);var activity = new AddActivityRequest
{
Type = "post",
Text = "I love this movie!",
UserID = "jack",
Feeds = new List<string> { "user:jack" },
CollectionRefs = new List<string> { "movies:lord_of_the_rings" }
};
var response = await _feedsV3Client.AddActivityAsync(activity);response = client.feeds.add_activity(
type="post",
feeds=["user:jack"],
text="I love this movie!",
user_id="jack",
collection_refs=["movies:lord_of_the_rings"]
)activity_request = GetStream::Generated::Models::AddActivityRequest.new(
type: 'post',
text: 'I love this movie!',
user_id: 'jack',
feeds: ['user:jack'],
collection_refs: ['movies:lord_of_the_rings']
)
response = client.feeds.add_activity(activity_request)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
let createResponse = try await client.createCollections(
request: .init(
collections: [
.init(
name: "movies",
id: "lord_of_the_rings",
custom: [
"title": "Lord of the Rings",
"genre": "fantasy",
"rating": 9
]
)
]
)
)
// Add the reference to an activity
let feed = client.feed(group: "user", id: "jack")
let activityResponse = try await feed.addActivity(
request: .init(
type: "post",
text: "I love this movie!",
collectionRefs: ["movies:lord_of_the_rings"]
)
)
// Read the feed and see the enriched collection data
try await feed.getOrCreate()
let activities = feed.state.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"
// }
// }
// }
// ],
// ...
// }// Create a collection
val createResponse: Result<CreateCollectionsResponse> = client.createCollections(
request = CreateCollectionsRequest(
collections = listOf(
CollectionRequest(
name = "movies",
id = "lord_of_the_rings",
custom = mapOf(
"title" to "Lord of the Rings",
"genre" to "fantasy",
"rating" to 9
)
)
)
)
)
// Add the reference to an activity
val feed = client.feed(group = "user", id = "jack")
val activityResponse: Result<ActivityData> = feed.addActivity(
request = FeedAddActivityRequest(
type = "post",
text = "I love this movie!",
collectionRefs = listOf("movies:lord_of_the_rings")
)
)
// Read the feed and see the enriched collection data
feed.getOrCreate()
val activities = feed.state.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"
// }
// }
// }
// ],
// ...
// }// Create a collection
await client.createCollections({
collections: [
{
name: "movies",
id: "lord_of_the_rings",
custom: {
title: "Lord of the Rings",
genre: "fantasy",
rating: 9,
},
},
],
});
// Add the reference to an activity
const feed = client.feed("user", "jack");
await feed.addActivity({
type: "post",
text: "I love this movie!",
collection_refs: ["movies:lord_of_the_rings"],
});
// Read the feed and see the enriched collection data
const response = await feed.getOrCreate({});
console.log(response);
/*
{
"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"
}
}
}
],
...
}
*/// Create a collection
await client.feeds.createCollections({
collections: [
{
name: "movies",
id: "lord_of_the_rings",
custom: {
title: "Lord of the Rings",
genre: "fantasy",
rating: 9,
},
},
],
});
// Add the reference to an activity
const feed = client.feeds.feed("user", "jack");
await feed.addActivity({
type: "post",
text: "I love this movie!",
collection_refs: ["movies:lord_of_the_rings"],
user_id: "jack",
});
// Read the feed and see the enriched collection data
const response = await feed.getOrCreate({ user_id: "jack" });
console.log(response);
/*
{
"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"
}
}
}
],
...
}
*/// Create a collection
final createResponse = await client.createCollections(
collections: [
const CollectionRequest(
name: 'movies',
id: 'lord_of_the_rings',
custom: {
'title': 'Lord of the Rings',
'genre': 'fantasy',
'rating': 9,
},
),
],
);
// Add the reference to an activity
final feed = client.feed(group: 'user', id: 'jack');
final activityResponse = await feed.addActivity(
request: const FeedAddActivityRequest(
type: 'post',
text: 'I love this movie!',
collectionRefs: ['movies:lord_of_the_rings'],
),
);
// Read the feed and see the enriched collection data
await feed.getOrCreate();
final activities = feed.state.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"
// }
// }
// }
// ],
// ...
// }// 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"
// }
// }
// }
// ],
// ...
// }// Create a collection
Map<String, Object> customData = new HashMap<>();
customData.put("title", "Lord of the Rings");
customData.put("genre", "fantasy");
customData.put("rating", 9);
CollectionRequest collection = CollectionRequest.builder()
.name("movies")
.id("lord_of_the_rings")
.custom(customData)
.build();
CreateCollectionsRequest createRequest = CreateCollectionsRequest.builder()
.collections(List.of(collection))
.build();
feeds.createCollections(createRequest).execute().getData();
// Add the reference to an activity
AddActivityRequest activity =
AddActivityRequest.builder()
.type("post")
.feeds(List.of("user:jack"))
.text("I love this movie!")
.userID("jack")
.collectionRefs(List.of("movies:lord_of_the_rings"))
.build();
feeds.addActivity(activity).execute().getData();
// Read the feed and see the enriched collection data
Feed feed = new Feed("user", "jack", feeds);
GetOrCreateFeedRequest feedRequest = GetOrCreateFeedRequest.builder()
.userID("jack")
.build();
GetOrCreateFeedResponse feedResponse = feed.getOrCreate(feedRequest).getData();
List<Activity> activities = feedResponse.getActivities();
// 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"
// }
// }
// }
// ],
// ...
// }// Create a collection
$collection = new GeneratedModels\CollectionRequest(
name: 'movies',
id: 'lord_of_the_rings',
custom: (object)[
'title' => 'Lord of the Rings',
'genre' => 'fantasy',
'rating' => 9,
]
);
$feedsClient->createCollections(
new GeneratedModels\CreateCollectionsRequest(collections: [$collection])
);
// Add the reference to an activity
$activity = new GeneratedModels\AddActivityRequest(
type: 'post',
feeds: ['user:jack'],
text: 'I love this movie!',
userID: 'jack',
collectionRefs: ['movies:lord_of_the_rings']
);
$feedsClient->addActivity($activity);
// Read the feed and see the enriched collection data
$feed = $feedsClient->feed('user', 'jack');
$response = $feed->getOrCreateFeed(
new GeneratedModels\GetOrCreateFeedRequest(userID: 'jack')
);
$activities = $response->getData()->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"
// }
// }
// }
// ],
// ...
// }// Create a collection
var collection = new CollectionRequest
{
Name = "movies",
ID = "lord_of_the_rings",
Custom = new Dictionary<string, object>
{
{ "title", "Lord of the Rings" },
{ "genre", "fantasy" },
{ "rating", 9 }
}
};
await _feedsV3Client.CreateCollectionsAsync(
new CreateCollectionsRequest { Collections = new List<CollectionRequest> { collection } }
);
// Add the reference to an activity
var activity = new AddActivityRequest
{
Type = "post",
Text = "I love this movie!",
UserID = "jack",
Feeds = new List<string> { "user:jack" },
CollectionRefs = new List<string> { "movies:lord_of_the_rings" }
};
await _feedsV3Client.AddActivityAsync(activity);
// Read the feed and see the enriched collection data
var feedResponse = await _feedsV3Client.GetOrCreateFeedAsync(
FeedGroupID: "user",
FeedID: "jack",
request: new GetOrCreateFeedRequest { UserID = "jack" }
);
var activities = feedResponse.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"
// }
// }
// }
// ],
// ...
// }# Create a collection
response = client.feeds.create_collections(
collections=[
CollectionRequest(
name="movies",
id="lord_of_the_rings",
custom={
"title": "Lord of the Rings",
"genre": "fantasy",
"rating": 9,
}
)
]
)
# Add the reference to an activity
response = client.feeds.add_activity(
type="post",
feeds=["user:jack"],
text="I love this movie!",
user_id="jack",
collection_refs=["movies:lord_of_the_rings"]
)
# Read the feed and see the enriched collection data
feed = client.feeds.feed("user", "jack")
feed_response = feed.get_or_create(user_id="jack")
activities = feed_response.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"
# }
# }
# }
# ],
# ...
# }# Create a collection
collection = GetStream::Generated::Models::CollectionRequest.new(
name: 'movies',
id: 'lord_of_the_rings',
custom: {
title: 'Lord of the Rings',
genre: 'fantasy',
rating: 9
}
)
request = GetStream::Generated::Models::CreateCollectionsRequest.new(
collections: [collection]
)
client.feeds.create_collections(request)
# Add the reference to an activity
activity_request = GetStream::Generated::Models::AddActivityRequest.new(
type: 'post',
text: 'I love this movie!',
user_id: 'jack',
feeds: ['user:jack'],
collection_refs: ['movies:lord_of_the_rings']
)
client.feeds.add_activity(activity_request)
# Read the feed and see the enriched collection data
feed = client.feed('user', 'jack')
feed_request = GetStream::Generated::Models::GetOrCreateFeedRequest.new(user_id: 'jack')
feed_response = feed.get_or_create_feed(feed_request)
activities = feed_response.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