Activity Feeds v3 is in beta — try it out!

Activities

Creating Activities

The example below shows how to create an activity and add it to a feed.

feedsClient := client.Feeds()
response, err := feedsClient.AddActivity(context.Background(), &getstream.AddActivityRequest{
	Type:   "post",
	Feeds:  []string{"user:john", "stock:apple"},
	Text:   getstream.PtrTo("apple stock will go up"),
	UserID: getstream.PtrTo("john"),
})
if err != nil {
	log.Fatal("Error adding activity:", err)
}
log.Printf("Activity added successfully: %+v", response)

The above example was quite simple. Here are a few more examples:

Image & Video

response, err := client.Feeds().AddActivity(context.Background(), &getstream.AddActivityRequest{
	Type:   "post",
	Feeds:  []string{"user:john"},
	Text:   getstream.PtrTo("look at NYC"),
	UserID: getstream.PtrTo("john"),
	Attachments: []getstream.Attachment{
		{
			AssetUrl: getstream.PtrTo("https://example.com/image.png"),
			Type:     getstream.PtrTo("image"),
			Title:    getstream.PtrTo("Amazing Video"),
			Custom: map[string]interface{}{},
		},
	},
})

Sharing activities

When creating an activity it’s possible to set parent_id, setting this field will increase the share_count of the parent activity. This feature lets you implement “retweets”.

When reading an activity with parent id set, you can access the parent activity with activity.parent.

feedsClient := client.Feeds()
response, err := feedsClient.AddActivity(context.Background(), &getstream.AddActivityRequest{
	Type:   "post",
	Feeds:  []string{"user:john"},
	Text:   getstream.PtrTo("Couldn't agree more!"),
  ParentID:   getstream.PtrTo("<activity to share>"),
	UserID: getstream.PtrTo("john"),
})
if err != nil {
	log.Fatal("Error adding activity:", err)
}
log.Printf("Activity added successfully: %+v", response)

Overview of All Activity Fields

Here’s an overview of all the fields you can add when creating an activity:

FieldDescription
idEither set your own id, or let our server generate it. Setting your own ID can be convenient if your activity maps 1 to 1 to something in your database.
typeThe type of activity. Defaults to “post” if not provided.
feedsThe list of feeds (format: “group id:feed id”) to add this activity to
textThe text for this activity
attachmentsA list of attachments. Video, images, location, etc. Also supports custom attachments
customAny custom data you want to add
visibilityVisibility levels for the activity
locationSpecify an activity location. This allows for feeds to show content close to you. Format: ActivityLocation(lat: 40.014984, lng: -105.270546)
expiresAtWhen the activity expires. After this timestamp it’s only visible to the person who created this activity (or server side API calls)
mentionedUserIdsA list of users mentioned in this activity
parentIdThe parent activity. Used for replies/reshares etc
searchDataAny extra data you want to search on for this activity
filterTagsArray of strings that you can filter on when querying the feed
interestTagsEither set the interest tags manually or enable an activity processor to have AI determine the topics for this activity. Used for “for you” style feeds

Adding Many Activities

You can also batch add activities. Here’s an example:

activities := []getstream.ActivityRequest{
	{
		Type:   "post",
		Feeds:  []string{"user:123"},
		Text:   getstream.PtrTo("Batch activity 1"),
		UserID: getstream.PtrTo("john"),
	},
	{
		Type:   "post",
		Feeds:  []string{"user:456"},
		Text:   getstream.PtrTo("Batch activity 2"),
		UserID: getstream.PtrTo("alice"),
	},
}
response, err := client.Feeds().UpsertActivities(context.Background(), &getstream.UpsertActivitiesRequest{
	Activities: activities,
})

Updating & Deleting Activities

This example shows how to update or delete an activity:

// Update an activity
updateRequest := &getstream.UpdateActivityRequest{
  Text:   stringPtr("Updated text"),
  UserID: stringPtr("john"),
  Custom: map[string]any{
    "color": "blue",
  },
}

updateResponse, err := client.Feeds().UpdateActivity(context.Background(), "123", updateRequest)
if err != nil {
  log.Fatal("Error updating activity:", err)
}
log.Printf("Activity updated successfully: %+v", updateResponse)

// Delete a single activity (soft delete)
deleteRequest := &getstream.DeleteActivityRequest{
  HardDelete: boolPtr(false), // Soft delete
}

deleteResponse, err := client.Feeds().DeleteActivity(context.Background(), "123", deleteRequest)
if err != nil {
  log.Fatal("Error deleting activity:", err)
}
log.Printf("Activity deleted successfully: %+v", deleteResponse)

// Batch delete activities
batchDeleteRequest := &getstream.DeleteActivitiesRequest{
  Ids:        []string{"123", "456"},
  UserID:     stringPtr("john"),
  HardDelete: boolPtr(false), // Soft delete
}

batchDeleteResponse, err := client.Feeds().DeleteActivities(context.Background(), batchDeleteRequest)
if err != nil {
  log.Fatal("Error batch deleting activities:", err)
}
log.Printf("Activities batch deleted successfully: %+v", batchDeleteResponse)

Partial activity updates

A partial update can be used to set and unset specific fields when it is necessary to retain additional custom data fields on the object. AKA a patch style update. Both set and unset can be used in the same request. The dotted-notation is also available for both set and unset for the custom field.

// Partially set some fields
updateRequest := &getstream.UpdateActivityPartialRequest{
  UserID: stringPtr("<user id>"),
  Set: map[string]any{
    "text": "Japan has over 6,800 islands.",
    "custom": map[string]any{
      "topic": "fun facts",
      "color": "blue",
    },
  }
}

updateResponse, err := client.Feeds().UpdateActivityPartial(context.Background(), "123", updateRequest)
if err != nil {
  log.Fatal("Error updating activity:", err)
}
log.Printf("Activity updated successfully: %+v", updateResponse)

// Partially unset some fields
updateRequest := &getstream.UpdateActivityPartialRequest{
  UserID: stringPtr("<user id>"),
  Unset: []string{"custom.color"},
}

updateResponse, err := client.Feeds().UpdateActivityPartial(context.Background(), "123", updateRequest)
if err != nil {
  log.Fatal("Error updating activity:", err)
}
log.Printf("Activity updated successfully: %+v", updateResponse)
© Getstream.io, Inc. All Rights Reserved.