Reactions

Overview

You can react to both activities and comments. It’s possible to configure any reaction types that best fit your app.

When adding reactions and the enforce_unique flag is set to true, the existing reaction of a user will be overridden with the new reaction. Use this flag if you want to ensure users have a single reaction per each comment/activity. The default value is false, in which case users can have multiple reactions.

// Add a reaction to an activity
const addResponse = await client.addActivityReaction({
  activity_id: "activity_123",
  type: "like",
  custom: {
    emoji: "❤️",
  },
  // Optionally override existing reaction
  enforce_unique: true,
});

console.log(addResponse.reaction);

// Adding a reaction without triggering push notifications
await client.addActivityReaction({
  activity_id: "activity_123",
  type: "like",
  custom: {
    emoji: "❤️",
  },
  skip_push: true,
});

// Add a reaction to a comment
await client.addCommentReaction({
  id: comment.id,
  type: "like",
  custom: {
    emoji: "👍",
  },
  // Optionally override existing reaction
  enforce_unique: true,
});

// Adding a comment reaction without triggering push notifications
await client.addCommentReaction({
  id: comment.id,
  type: "like",
  custom: {
    emoji: "👍",
  },
  skip_push: true,
});
const deleteResponse = await client.deleteActivityReaction({
  activity_id: activity.id,
  type: "like",
});
console.log(deleteResponse.reaction);

Overview of the reaction model

FeedsReactionResponse

NameTypeDescriptionConstraints
activity_idstringID of the activity that was reacted toRequired
comment_idstringID of the comment that was reacted to-
created_atnumberWhen the reaction was createdRequired
customobjectCustom data for the reaction-
typestringType of reactionRequired
updated_atnumberWhen the reaction was last updatedRequired
userUserResponseUser who created the reactionRequired

By default creating a reaction doesn’t create an activity.

When you read a feed the reactions are included. Here’s an example:

const feed = client.feed("user", "sara");
await feed.getOrCreate();

console.log(feed.state.getLatestValue().activities?.[0].own_reactions);
console.log(feed.state.getLatestValue().activities?.[0].latest_reactions);
console.log(feed.state.getLatestValue().activities?.[0].reaction_groups);

Querying Reactions

You can query reactions to both activities and comments. Here are some examples:

await client.queryActivityReactions({
  activity_id: activity.id,
  // Provide optional filters
  filter: {
    reaction_type: "like",
  },
});

await client.queryCommentReactions({
  id: comment.id,
  // Provide optional filters

  filter: {
    reaction_type: "like",
  },
});

Reaction Queryable Built-In Fields

nametypedescriptionsupported operationsexample
reaction_typestring or list of stringsThe type of reaction$in, $eq{ reaction_type: { $in: [ 'like', 'heart', 'thumbs_up' ] } }
user_idstring or list of stringsThe ID of the user who created the reaction$in, $eq{ user_id: { $eq: 'user_123' } }
created_atstring, must be formatted as an RFC3339 timestampThe time the reaction was created$eq, $gt, $gte, $lt, $lte{ created_at: { $gte: '2023-12-04T09:30:20.45Z' } }