Activity Feeds V3 is in closed alpha — do not use it in production (just yet).

Activities

Creating Activities

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

// Add an activity to 1 feed
const response = await feed.addActivity({
  type: "post",
  text: "apple stock will go up",
});

console.log(response.activity);

//...or multiple feeds
const response = await client.addActivity({
  fids: ["user:1", "stock:apple"],
  type: "post",
  text: "apple stock will go up",
});

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

Image & Video

feed.addActivity({
  type: "post",
  text: "look at NYC",
  attachments: [
    {
      type: "image",
      image_url: "https://example.com/image.png",
      custom: {},
    },
  ],
});

Stories

For a story you typically want multiple attachments and an expiration set:

const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);

feed.addActivity({
  type: "story",
  text: "My story",
  expires_at: tomorrow.toISOString(),
  attachments: [
    {
      type: "image",
      image_url: "https://example.com/image.png",
      custom: {},
    },
    {
      type: "video",
      image_url: "https://example.com/video.mp4",
      custom: {},
    },
  ],
});

Restricted Visibility

feed.addActivity({
  type: "post",
  text: "Premium content",
  visibility: "tag",
  visibility_tag: "premium",
});
// Only users with the permission to read premium activities can read this

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.
fidsThe list of feed IDs 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:

client.upsertActivities({
  activities: [
    {
      fids: ["user:123"],
      id: "1",
      type: "post",
      text: "hi",
    },
    {
      fids: ["user:456"],
      id: "2",
      type: "post",
      text: "hi",
    },
  ],
});

Updating & Deleting Activities

This example shows how to update or delete an activity:

// Update an activity
client.updateActivity({
  activity_id: "123",
  text: "Updated text",
  custom: {
    color: "blue",
  },
});

client.deleteActivity({
  activity_id: "123",
  hard_delete: false, // Soft delete sets deleted at but retains the data, hard delete fully removes it
});

// Batch delete activities
client.removeActivities({
  activity_ids: ["123", "456"],
  hard_delete: false,
});

Activity & Feed Visibility

Feed groups have a default visibility level. You can also set a custom visibility policy on the feed, or even on individual activities.

Feed Visibility Levels

LevelDescription
visibleViewing/following: anyone can see the content in this feed or follow it. Posting: only the owner or member/follower with the post permission can post
publicViewing/following: anyone can see the content in this feed. Posting: everyone can post
followersViewing/following: you can only view this feed after you are approved as a follower. Posting: only the owner or member/follower with the post permission can post
membersViewing/following: the content is not visible unless you are a member. Posting: only the owner or member/follower with the post permission can post
privateOnly the owner has access

By default the feed will use the feed group’s default visibility level.

Activity Visibility Levels

  • public: marks the activity as public
  • private: marks the activity as private
  • tag:mytag: marks the activity as only visible to followers/members with the permission to see this tag

This visibility system is very flexible and allows you to build:

  • Apps like Patreon where only certain levels of users can see your content
  • Apps like Strava where it’s possible to share your activity with nobody, everyone or your followers
© Getstream.io, Inc. All Rights Reserved.