Reactions

Let users react to messages, posts, and comments, which are visible to others.

Reactions are the interactions that you can perform on messages, posts, or comments. The interactions can be anything such as like, dislike, love, etc. It's up to you to determine the type of reactions.

AmityReactionRepository class provides a convenient method to add, remove, and query reactions for any content. Currently, reactions are supported for Posts, Messages and Comments.

Reaction Description

Name

Data Type

Description

Attributes

referenceId

String

ID of a document

referenceType

String

Type of document

reactionName

String

Name of reaction

'like', 'love' , 'wow'

reactionId

String

ID of the reaction

reactorId

String

ID of the reactor

userDisplayName

String

Display name of the reactor

createdAt

String($date-time)

The date/time when a reaction is created

Query Reactions

You can fetch detailed information about reactions and the user who reacted to the post. AmityPostRepository and AmityCommentRepository classes provide two methods which get detailed information about reactions to the post and comment respectively. Each information is provided through AmityReaction object.

You can fetch information about a particular reaction and all the reactions through the getReactions method. The method returns collections of AmityReaction.

Below is a sample code for getting reactions from a post:

Below is a sample code for getting reactions from a comment:

Add/Remove Reaction

You can add any reactions to a given post. You can also remove any reactions added to the post. AmityPost and AmityComment objects provide addReaction and removeReaction methods for adding and removing reactions respectively. Both methods accept the reactionName the the required parameter.

Add Reaction

Below are sample codes for adding a reaction to a post and comment:

Post

Comment

Remove Reaction

Below are sample codes for removing a reaction from a post and comment :

Post

Comment

The reactionName parameter is the reaction name. This can be "like", "love", "wow" and other reaction names which has a maximum length of 100 characters. It is case sensitive. This means that "like" and "Like" are two different reactions.

Last updated