Reactions

Introduction

Reactions are a quick and easy way to provide feedback to Reactable entities via an emoji. Each User can only submit one Reaction per Reactable.

The Reactions of all Users are then summarized in order to obtain a quick picture of user sentiment for the Reactable.

Model Definition

Relations

KeyRelationTypeRelation Field(s)

user

Belongs to

user_id

reactable

Reactable

Morph to

reactable_type, reactable_id

Reactable types

Appends

The following appends can be applied on all Reactable entities:

reactions_summary

Adds the reactions_summary append to the response, containing the reaction and the count. The reaction counts are sorted from highest to lowest.

Example response:

{
  "reactions_summary": [
    {
      "reaction": "👍",
      "count": 2
    },
    {
      "reaction": "👎",
      "count": 1
    }
  ]
}

List by reactable

List the Reactions for given Reactable.

Definition

GET /api/reactions/{reactableType}/{reactableId}

Example Request

$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('POST', '/api/reactions/infoboardPost/1', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
]);

Example Response

[
  {
    "user_id": 1,
    "reactable_id": 1,
    "reactable_type": "infoboardPost",
    "value": "👍",
    "created_at": "2024-07-01 12:00:00",
    "updated_at": "2024-07-01 12:00:00"
  },
  {
    "user_id": 2,
    "reactable_id": 1,
    "reactable_type": "infoboardPost",
    "value": "👍",
    "created_at": "2024-07-01 13:00:00",
    "updated_at": "2024-07-01 13:00:00"
  },
  {
    "user_id": 3,
    "reactable_id": 1,
    "reactable_type": "infoboardPost",
    "reaction": "👎",
    "created_at": "2024-07-01 14:00:00",
    "updated_at": "2024-07-01 14:00:00"
  }
]

Summary by reactable

Get a summary of Reactions for given Reactable. It has the same structure as the reactions_summary append.

Definition

GET /api/reactions/{reactableType}/{reactableId}/summary

Example Request

$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('POST', '/api/reactions/infoboardPost/1/summary', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
]);

Example Response

[
  {
    "reaction": "👍",
    "count": 2
  },
  {
    "reaction": "👎",
    "count": 1
  }
]

Create or update

Create a new Reaction. If the reaction for given reactable_type, reactable_id and the authenticated User's ID exits, it will be updated.

Definition

POST /api/reactions

Request Keys

KeyTypeDescription

reactable_id*

integer

The ID of the Reactable entity.

reactable_type*

string

The Reactable type of the Reaction.

value*

string

The emoji to react to the Reactable entity.

Keys with * are required.

Example Request

$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('POST', '/api/reactions', [
    'headers' => ['Authorization' => "Bearer {accessToken}"],
    'json' => [
        'reactable_id' => 1,
        'reactable_type' => 'infoboardPost',
        'value' => "👍"
    ]
]);

Example Response

{
  "id": 4,
  "reactable_id": 1,
  "reactable_type": "infoboardPost",
  "value": "👍",
  "user_id": 1,
  "created_at": "2024-07-01 15:00:00",
  "updated_at": "2024-07-01 15:00:00"
}

Delete

Delete an Reaction by id.

Definition

DELETE /api/reactions/{id}

Example Request

$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('DELETE', '/api/reactions/4', [
    'headers' => ['Authorization' => "Bearer {accessToken}"]
]);

Example Response

{
  "status": "success",
  "data": []
}

Last updated