A plugin for Strapi Headless CMS that provides end to end comments feature with their moderation panel, bad words filtering, abuse reporting and more.
(Use yarn to install this plugin within your Strapi project (recommended). Install yarn with these docs.)
yarn add strapi-plugin-comments@latest
After successful installation you've to build a fresh package that includes plugin UI. To archive that simply use:
yarn build
yarn develop
or just run Strapi in the development mode with --watch-admin
option:
yarn develop --watch-admin
The Comments plugin should appear in the Plugins section of Strapi sidebar after you run app again.
Enjoy 🎉
Complete installation requirements are exact same as for Strapi itself and can be found in the documentation under Installation Requirements.
Supported Strapi versions:
- Strapi v3.3.4 (recently tested)
- Strapi v3.x
(This plugin may work with the older Strapi versions, but these are not tested nor officially supported at this time.)
We recommend always using the latest version of Strapi to start your new projects.
- Comments Public API: Elegant, entirely customizable and a fully extensible admin panel.
- Strapi & generic users: Support for built-in & also generic non-Strapi users that might be the comments authors.
- Any Content Type relation: Comments can by linked to any of your Content Types by default. Simply, you're controlling it.
- Moderation Panel: Search & Filter through the bucket with your auditory comments. Manage them by blocking single ones or full threads. All in combined list & hierarchical tree view of threads.
- Automated Bad Words filtering: By detault end users are not allowed to post abusing comments where bad words have been used.
- Abuse Reporting & Reviewing: Don't allow inferior language, react to reports from your community
To enable Content Type to work with Comments, you've to add following field to your model *.settings.json
:
"comments": {
"plugin": "comments",
"collection": "comment",
"via": "related"
}
inside the attributes
section like in example below:
"attributes": {
...,
"comments": {
"plugin": "comments",
"collection": "comment",
"via": "related"
},
...
},
{
"id": 1,
"content": "My comment content",
"blocked": null,
"blockedThread": true,
"blockReason": null,
"points": 1,
"authorUser": null,
"authorId": "207ccfdc-94ba-45eb-979c-790f6f49c392",
"authorName": "Joe Doe",
"authorEmail": "[email protected]",
"authorAvatar": null,
"created_at": "2020-07-14T20:13:01.649Z",
"updated_at": "2020-07-14T20:13:01.670Z"
}
{
"id": 1,
"content": "My comment content",
"blocked": true,
"blockedThread": null,
"blockReason": null,
"points": null,
"authorUser": {
"id": 1,
"username": "Sample User",
"email": "[email protected]",
"provider": "local",
"confirmed": true,
"blocked": false,
"role": 1,
"created_at": "2020-07-10T08:38:03.157Z",
"updated_at": "2020-07-10T08:38:03.170Z"
},
"authorId": null,
"authorName": null,
"authorEmail": null,
"authorAvatar": null,
"created_at": "2020-07-14T20:13:01.649Z",
"updated_at": "2020-07-14T20:13:01.670Z"
}
GET <host>/comments/<content-type>:<id>
Return a hierarchical tree structure of comments for specified instance of Content Type like for example Article
with ID: 1
Example URL: https://localhost:1337/comments/article:1
Example response body
[
{
-- Comment Model fields ---,
children: [
{
-- Comment Model fields ---,
children: [...]
},
...
]
},
...
]
GET <host>/comments/<content-type>:<id>/flat
Return a flat structure of comments for specified instance of Content Type like for example Article
with ID: 1
Example URL: https://localhost:1337/comments/article:1/flat
Example response body
[
{
-- Comment Model fields ---
},
{
-- Comment Model fields ---
},
...
]
Possible response codes
200
- Successful. Response with list of comments (can be empty)400
- Bad Request. Requested list for not valid / not existing Content Type
POST <host>/comments/<content-type>:<id>
Posts a Comment related to specified instance of Content Type like for example Article
with ID: 1
Example URL: https://localhost:1337/comments/article:1
Example request body
Generic (non Strapi User)
{
"authorId": "<any ID like value>",
"authorName": "Joe Doe",
"authorEmail": "[email protected]",
"content": "My sample response",
"threadOf": 2, // id of comment we would like to start / continue the thread (Optional)
"related": [{
"refId": 1,
"ref": "article",
"field": "comments"
}]
}
Strapi user
{
"authorUser": 1,
"content": "My sample response",
"threadOf": 2, // id of comment we would like to start / continue the thread (Optional)
"related": [{
"refId": 1,
"ref": "article",
"field": "comments"
}]
}
Example response body
{
-- Comment Model fields ---
}
Possible response codes
200
- Successful. Response with created Comment Model400
- Bad Request. Missing field values or bad words check fails. Error message will provide relevant reason.
PUT <host>/comments/<content-type>:<id>/comment/<commentId>
Updates a specified Comment content based on it commentId
and related to specified instance of Content Type like for example Article
with ID: 1
Example URL: https://localhost:1337/comments/article:1/comment/2
Example request body
Generic (non Strapi User)
{
"authorId": "<any ID like value>",
"authorName": "Joe Doe",
"authorEmail": "[email protected]",
"content": "My sample response"
}
Strapi user
{
"authorUser": 1,
"content": "My sample response"
}
Example response body
{
-- Comment Model fields ---
}
Possible response codes
200
- Successful. Response with updated Comment Model400
- Bad Request. Missing field values or bad words check fails. Error message will provide relevant reason.409
- Conflict. Occurs when trying to update a non existing or not own comment. Possible cause might be thatauthorId
orauthorUser
mismatch with existing comment.
PATCH <host>/comments/<content-type>:<id>/comment/<commentId>/like
Likes a specified Comment based on it commentId
and related to specified instance of Content Type like for example Article
with ID: 1
.
Example URL: https://localhost:1337/comments/article:1/comment/2/like
Example response body
{
-- Comment Model fields ---
}
Possible response codes
200
- Successful. Response with liked Comment Model.409
- Conflict. Occurs when trying to like a non existing comment.
POST <host>/comments/<content-type>:<id>/comment/<commentId>/report-abuse
Reports abuse in specified Comment content based on it commentId
and related to specified instance of Content Type like for example Article
with ID: 1
and requests moderator attention.
Example URL: https://localhost:1337/comments/article:1/comment/2/report-abuse
Example request body
{
"reason": "<reason enum>",
"content": "This comment is not relevant"
}
Available reason enums: OTHER
, BAD_WORDS
, DISCRIMINATION
Example response body
{
-- Comment Abuse Report fields ---
}
Possible response codes
200
- Successful. Response with reported abuse.409
- Conflict. Occurs when trying to report an abuse to a non existing comment.
Feel free to fork and make a Pull Request to this plugin project. All the input is warmly welcome!
For general help using Strapi, please refer to the official Strapi documentation. For additional help, you can use one of these channels to ask a question:
- Slack We're present on official Strapi slack workspace. Look for @cyp3r and DM.
- Slack - VirtusLab Open Source We're present on a public channel #strapi-molecules
- GitHub (Bug reports, Contributions, Questions and Discussions)
MIT License Copyright (c) 2020 VirtusLab Sp. z o.o. & Strapi Solutions.