Reactions and Feeds

Read Feeds with Reactions

When using reactions, it is possible to request enriched activities that include both attached reactions by type and reaction counters.

Listed below are the parameters for retrieving reactions.

The “recent” parameter includes up to 5 of the most recent reactions per type

Parameters

nametypedescriptiondefaultoptional
recentbooleanInclude the 5 most recent reactions to activities per type.-
ownbooleanInclude the current user’s reaction to activities.-
countsbooleanInclude the total count of reaction (by kind) to activities.-
user_idstringFilter reactions to specific user.-
// read bob's timeline and include most recent reactions to all activities and their total count
	opts := []stream.GetActivitiesOption{
		stream.WithEnrichRecentReactions(),
		stream.WithEnrichReactionCounts(),
	}
	resp, err := feed.GetEnrichedActivities(context.TODO(), opts...)
	if err != nil {
		panic(err)
	}

	// read bob's timeline and include most recent reactions to all activities and his own reactions
	opts = []stream.GetActivitiesOption{
		stream.WithEnrichOwnReactions(),
		stream.WithEnrichRecentReactions(),
		stream.WithEnrichReactionCounts(),
	}
	resp, err := feed.GetEnrichedActivities(context.TODO(), opts...)
	if err != nil {
		panic(err)
	}

 // read bob's timeline and include reactions from john
 opts = []stream.GetActivitiesOption{
		stream.WithEnrichOwnReactions(),
		stream.WithEnrichUserReactions("john"),
	}
	resp, err := feed.GetEnrichedActivities(context.TODO(), opts...)
	if err != nil {
		panic(err)
	}

Notify Other Feeds

When adding a reaction, you can use the target_feeds parameter to notify a list of users about the new reaction. When specified, all targeted feeds will receive an activity containing a reference to the reaction.

// adds a comment reaction to the activity and notifies Thierry's notification feed
	r := stream.AddReactionRequestObject{
		Kind:    "comment",
		ActivityID: activityID,
		UserID:   "bob",
		Data: map[string]any{
			"text": "@thierry great post!",
		},
		TargetFeeds: []string{"notification:thierry"},
	}
	resp, err := client.Reactions().Add(context.TODO(), r)
	if err != nil {
		panic(err)
	}

The targetFeeds field is limited to a maximum of 20 targets per API request.

© Getstream.io, Inc. All Rights Reserved.