### Installation and Configuration Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Instructions for installing the Strapi Comments Plugin and configuring its settings. ```APIDOC ## Installation Install the plugin via npm or yarn and rebuild your Strapi project. ```bash # Install via yarn (recommended) yarn add strapi-plugin-comments@latest # Rebuild Strapi yarn build yarn develop ``` ## Configuration Configure the plugin in `config/plugins.ts` to enable comments and customize their behavior. ```typescript // config/plugins.ts module.exports = ({ env }) => ({ comments: { enabled: true, config: { badWords: true, // Enable profanity filtering moderatorRoles: ["Authenticated"], approvalFlow: ["api::page.page"], // Content Types requiring approval entryLabel: { "*": ["Title", "title", "Name", "name", "Subject", "subject"], "api::page.page": ["MyField"], }, blockedAuthorProps: ["email"], // Hide author email from responses reportReasons: { BAD_LANGUAGE: "BAD_LANGUAGE", DISCRIMINATION: "DISCRIMINATION", OTHER: "OTHER", MY_CUSTOM_REASON: "MY_CUSTOM_REASON", }, gql: { auth: false, // Set to true to require authentication for GraphQL }, client: { url: "https://myapp.com", contactEmail: "contact@myapp.com", }, }, }, }); ``` ``` -------------------------------- ### Install Strapi Comments Plugin Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Install the plugin using yarn and then rebuild and develop your Strapi application. ```bash # Install via yarn (recommended) yarn add strapi-plugin-comments@latest # Rebuild Strapi yarn build yarn develop ``` -------------------------------- ### Get Plugin Configuration via API Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Retrieve the current configuration settings for the Strapi Comments plugin using a GET request. Requires an admin JWT token for authorization. ```bash # Get config for moderation panel curl -X GET "http://localhost:1337/api/comments/moderate/config" \ -H "Authorization: Bearer " # Get config for settings page curl -X GET "http://localhost:1337/api/comments/settings/config" \ -H "Authorization: Bearer " ``` -------------------------------- ### Rebuild Strapi Instance Source: https://github.com/virtuslab-open-source/strapi-plugin-comments/blob/master/README.md Rebuild the Strapi application after installing the plugin to ensure it appears in the sidebar. ```bash yarn build yarn develop ``` -------------------------------- ### Response Structure for Get Comments by Author Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt This is an example of the JSON response received when retrieving comments by a specific author. ```json { "data": [ { "id": 1, "content": "My first comment", "blocked": false, "createdAt": "2024-01-15T10:30:00.000Z" }, { "id": 5, "content": "Another comment I made", "blocked": false, "createdAt": "2024-01-16T09:00:00.000Z" } ], "meta": { "pagination": { "page": 1, "pageSize": 10, "pageCount": 1, "total": 2 } } } ``` -------------------------------- ### GET /api/comments/settings/config Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Retrieve the current plugin configuration for the settings page. ```APIDOC ## GET /api/comments/settings/config ### Description Retrieve the current plugin configuration for the settings page. ### Method GET ### Endpoint `/api/comments/settings/config` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```bash curl -X GET "http://localhost:1337/api/comments/settings/config" \ -H "Authorization: Bearer " ``` ### Response #### Success Response (200) Returns the plugin configuration object. #### Response Example (Example response structure would be detailed here if provided in source) ``` -------------------------------- ### Install Strapi Comments Plugin Source: https://github.com/virtuslab-open-source/strapi-plugin-comments/blob/master/README.md Use yarn to add the latest version of the plugin to your Strapi project. ```bash yarn add strapi-plugin-comments@latest ``` -------------------------------- ### Response Structure for Updated Comment Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt This is an example of the JSON response received after successfully updating a comment. ```json { "id": 3, "documentId": "ghi789", "content": "Updated comment content with corrections.", "blocked": false, "author": { "id": "guest-user-123", "name": "Guest User" }, "createdAt": "2024-01-15T11:00:00.000Z", "updatedAt": "2024-01-15T11:30:00.000Z" } ``` -------------------------------- ### GET /api/comments/moderate/config Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Retrieve the current plugin configuration for the moderation panel. ```APIDOC ## GET /api/comments/moderate/config ### Description Retrieve the current plugin configuration for the moderation panel. ### Method GET ### Endpoint `/api/comments/moderate/config` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```bash curl -X GET "http://localhost:1337/api/comments/moderate/config" \ -H "Authorization: Bearer " ``` ### Response #### Success Response (200) Returns the plugin configuration object. #### Response Example (Example response structure would be detailed here if provided in source) ``` -------------------------------- ### Get Comments GraphQL Response Source: https://github.com/virtuslab-open-source/strapi-plugin-comments/blob/master/README.md Example response structure for the hierarchical comment query. ```json { "data": { "findAllInHierarchy": [ { "id": 1, "content": "Test", "blocked": false, "children": [ { "id": 6, "content": "Text to search for" } // ... ], "threadOf": null, "author": { "id": "123456", "name": "Joe Doe" } } // ... ] } } ``` -------------------------------- ### Response Structure for Posted Comment Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt This is an example of the JSON response received after successfully posting a comment. ```json { "id": 3, "documentId": "ghi789", "content": "This is my comment on the article.", "blocked": false, "blockedThread": false, "approvalStatus": "APPROVED", "author": { "id": "guest-user-123", "name": "Guest User" }, "threadOf": null, "createdAt": "2024-01-15T11:00:00.000Z", "updatedAt": "2024-01-15T11:00:00.000Z" } ``` -------------------------------- ### Configure Strapi Comments Plugin Source: https://github.com/virtuslab-open-source/strapi-plugin-comments/blob/master/README.md Set up the Comments plugin by adding its configuration to `config/plugins.js` or `config/plugins.ts`. This example shows how to enable the plugin and configure various options like bad word filtering, moderator roles, and approval flow. ```typescript module.exports = ({ env }) => ({ //... comments: { enabled: true, config: { badWords: false, moderatorRoles: ["Authenticated"], approvalFlow: ["api::page.page"], entryLabel: { "*": ["Title", "title", "Name", "name", "Subject", "subject"], "api::page.page": ["MyField"], }, blockedAuthorProps: ["name", "email"], reportReasons: { MY_CUSTOM_REASON: "MY_CUSTOM_REASON", }, gql: { // ... }, }, }, //... }); ``` -------------------------------- ### Get Flat Comments List Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Retrieve comments in a flat list format with pagination metadata. Supports filtering by content. ```bash # Get flat comments list curl -X GET "http://localhost:1337/api/comments/api::page.page:njx99iv4p4txuqp307ye8625/flat" \ -H "Content-Type: application/json" # Response { "data": [ { "id": 1, "documentId": "abc123", "content": "First comment", "blocked": false, "threadOf": null, "gotThread": true, "threadFirstItemId": 2, "author": { "id": "user-123", "name": "John Doe" }, "createdAt": "2024-01-15T10:30:00.000Z" }, { "id": 2, "documentId": "def456", "content": "Reply to first comment", "blocked": false, "threadOf": 1, "gotThread": false, "author": { "id": "user-456", "name": "Jane Smith" } } ], "meta": { "pagination": { "page": 1, "pageSize": 10, "pageCount": 1, "total": 2 } } } # With filtering curl -X GET "http://localhost:1337/api/comments/api::page.page:njx99iv4p4txuqp307ye8625/flat?filters[content][$contains]=great" ``` -------------------------------- ### GET /api/comments/moderate/all Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Retrieves all comments across all Content Types for the moderation panel. ```APIDOC ## GET /api/comments/moderate/all ### Description Retrieves all comments across all Content Types for the moderation panel. ### Query Parameters - **page** (number) - Optional - Page number for pagination - **pageSize** (number) - Optional - Number of items per page - **filters[blocked]** (boolean) - Optional - Filter by blocked status ``` -------------------------------- ### REST API Comment Response Source: https://github.com/virtuslab-open-source/strapi-plugin-comments/blob/master/README.md Example of the hierarchical tree structure returned by the REST API for comments. ```json [ { // -- Comment Model fields ---, "children": [ { // -- Comment Model fields ---, "children": [ // ... ] } // ... ] } // ... ] ``` -------------------------------- ### Get Comments (GraphQL) Source: https://github.com/virtuslab-open-source/strapi-plugin-comments/blob/master/README.md Retrieves comments in a hierarchical structure, supporting sorting. ```APIDOC ### Query: findAllInHierarchy #### Description Retrieves comments in a hierarchical structure, supporting sorting. #### Endpoint `http://localhost:1337/graphql` #### Query Parameters - **relation** (string) - Required - Specifies the relation to fetch comments from (e.g., `api::page.page:njx99iv4p4txuqp307ye8625`). #### Request Example ```graphql query { findAllInHierarchy(relation: "api::page.page:njx99iv4p4txuqp307ye8625") { id content blocked children { id content } threadOf { id } author { id name } } } ``` #### Response Example ```json { "data": { "findAllInHierarchy": [ { "id": 1, "content": "Test", "blocked": false, "children": [ { "id": 6, "content": "Text to search for" } // ... ], "threadOf": null, "author": { "id": "123456", "name": "Joe Doe" } } // ... ] } } ``` #### Supported Features - Sorting ``` -------------------------------- ### Get Comments (by Author) Source: https://github.com/virtuslab-open-source/strapi-plugin-comments/blob/master/README.md Retrieves comments associated with a specific author ID. The authorType parameter accepts GENERIC or STRAPI. ```graphql query { findAllPerAuthor(authorId: 1, authorType: STRAPI) { // authorType might be one of [GENERIC, STRAPI] data { id content blocked threadOf { id } } } } ``` ```json { "data": { "findAllPerAuthor": { "data": [ { "id": 4, "content": "Hackaton test comment", "blocked": false, "threadOf": { "id": 1 } } // ... ] } } ``` -------------------------------- ### Get Comments by Generic User ID Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Retrieves all comments created by a specific generic user. Requires the user's generic ID and the `/generic` path. ```bash curl -X GET "http://localhost:1337/api/comments/author/guest-user-123/generic" \ -H "Content-Type: application/json" ``` -------------------------------- ### Get Comments by Strapi User ID Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Retrieves all comments created by a specific authenticated Strapi user. Requires the user's Strapi ID. ```bash curl -X GET "http://localhost:1337/api/comments/author/1" \ -H "Content-Type: application/json" ``` -------------------------------- ### Get Comments (flat structure) Source: https://github.com/virtuslab-open-source/strapi-plugin-comments/blob/master/README.md Retrieves a flat list of comments for a specific relation, supporting filtering, sorting, and pagination. ```graphql query { findAllFlat( relation: "api::page.page:njx99iv4p4txuqp307ye8625" filters: { content: { contains: "Test" } } ) { id content blocked threadOf { id } author { id name } } } ``` ```json { "data": { "findAllFlat": [ { "id": 3, "content": "Test", "blocked": false, "threadOf": null, "author": { "id": "123456", "name": "Joe Doe" } } // ... ] } } ``` -------------------------------- ### Get Comments Response Structure Source: https://github.com/virtuslab-open-source/strapi-plugin-comments/blob/master/README.md The standard JSON response format for comment retrieval endpoints, including data and pagination metadata. ```json { "data": [ { // -- Comment Model fields --- }, { // -- Comment Model fields --- } // ... ], "meta": { "pagination": { // payload based on Strapi REST Pagination specification } } } ``` -------------------------------- ### GET /api/comments/:contentType:documentId/flat Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Retrieves all comments in a flat list format with pagination metadata, suitable for custom rendering or processing. ```APIDOC ## GET /api/comments/:contentType:documentId/flat ### Description Retrieves all comments in a flat list format with pagination metadata, suitable for custom rendering or processing. ### Method GET ### Endpoint `/api/comments/:contentType:documentId/flat` ### Query Parameters - **filters[content][$contains]** (string) - Optional - Filters comments where the content contains the specified string. ### Response #### Success Response (200) - **data** (array) - An array of comment objects. - **id** (integer) - The unique identifier of the comment. - **documentId** (string) - The ID of the document the comment is associated with. - **content** (string) - The content of the comment. - **blocked** (boolean) - Indicates if the comment is blocked. - **threadOf** (integer|null) - The ID of the parent comment if this is a reply. - **gotThread** (boolean) - Indicates if this comment has replies. - **threadFirstItemId** (integer) - The ID of the first comment in the thread. - **author** (object) - Information about the comment author. - **id** (string) - The author's unique identifier. - **name** (string) - The author's name. - **createdAt** (string) - The date and time the comment was created. - **meta** (object) - Metadata about the response. - **pagination** (object) - Pagination details. - **page** (integer) - The current page number. - **pageSize** (integer) - The number of items per page. - **pageCount** (integer) - The total number of pages. - **total** (integer) - The total number of comments. #### Response Example ```json { "data": [ { "id": 1, "documentId": "abc123", "content": "First comment", "blocked": false, "threadOf": null, "gotThread": true, "threadFirstItemId": 2, "author": { "id": "user-123", "name": "John Doe" }, "createdAt": "2024-01-15T10:30:00.000Z" }, { "id": 2, "documentId": "def456", "content": "Reply to first comment", "blocked": false, "threadOf": 1, "gotThread": false, "author": { "id": "user-456", "name": "Jane Smith" } } ], "meta": { "pagination": { "page": 1, "pageSize": 10, "pageCount": 1, "total": 2 } } } ``` ### Request Example ```bash # Get flat comments list curl -X GET "http://localhost:1337/api/comments/api::page.page:njx99iv4p4txuqp307ye8625/flat" \ -H "Content-Type: application/json" # With filtering curl -X GET "http://localhost:1337/api/comments/api::page.page:njx99iv4p4txuqp307ye8625/flat?filters[content][$contains]=great" ``` ``` -------------------------------- ### Get Comments (flat structure) Source: https://github.com/virtuslab-open-source/strapi-plugin-comments/blob/master/README.md Retrieves comments in a flat structure for a specific content type instance. Supports filtering, field selection, sorting, and pagination. ```APIDOC ## GET /api/comments/:api::.:/flat ### Description Retrieves a flat structure of comments for a specified instance of a Content Type. ### Method GET ### Endpoint `/api/comments/api::.:/flat` ### Query Parameters - **filtering** (object) - Optional - Allows filtering of comments. - **fields** (string) - Optional - Allows selection of specific fields. - **sort** (string) - Optional - Allows sorting of comments. - **pagination** (object) - Optional - Allows pagination of results. ### Response #### Success Response (200) - **data** (array) - A list of comment objects. - **meta** (object) - Contains pagination information. #### Response Example ```json { "data": [ { "// -- Comment Model fields --": "" }, { "// -- Comment Model fields --": "" } ], "meta": { "pagination": { "// payload based on Strapi REST Pagination specification": "" } } } ``` #### Error Response (400) - Bad Request. Requested list for not valid / not existing Content Type. ``` -------------------------------- ### Configure Plugin Initialization Order Source: https://github.com/virtuslab-open-source/strapi-plugin-comments/blob/master/README.md Ensure the 'comments' plugin initializes before the 'graphql' plugin by configuring the `config/plugins.js` or `config/plugins.ts` file. This is crucial for GraphQL schema injection. ```javascript module.exports = { comments: { enabled: true }, graphql: { enabled: true }, }; ``` -------------------------------- ### Post Admin Comment Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Submit a comment as an administrator. ```bash curl -X POST "http://localhost:1337/api/comments/moderate/thread/1/postComment" \ -H "Authorization: Bearer " \ -H "Content-Type: application/json" \ -d '{ "content": "This is an official response from the admin team.", "author": { "id": "admin-1", "name": "Site Administrator" } }' ``` -------------------------------- ### GET /api/comments/author/:authorId Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Retrieves all comments created by a specific author. ```APIDOC ## GET /api/comments/author/:authorId ### Description Retrieves all comments created by a specific author, supporting both Strapi users and generic authors. ### Method GET ### Endpoint /api/comments/author/:authorId ### Parameters #### Path Parameters - **authorId** (string/number) - Required - The ID of the author. #### Query Parameters - **omit[]** (array) - Optional - Fields to exclude from the response. ``` -------------------------------- ### PUT /api/comments/settings/config Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Update the plugin configuration at runtime. ```APIDOC ## PUT /api/comments/settings/config ### Description Update the plugin configuration at runtime. ### Method PUT ### Endpoint `/api/comments/settings/config` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **enabledCollections** (string[]) - List of enabled collection types. - **moderatorRoles** (string[]) - Roles with moderator privileges. - **approvalFlow** (string[]) - Collection types that require approval. - **badWords** (boolean) - Enable/disable bad word filtering. - **blockedAuthorProps** (string[]) - Properties of the author to hide. - **entryLabel** (object) - Configuration for entry labels. - `*` (string[]) - Default entry label fields. - `api::article.article` (string[]) - Specific entry label fields for `api::article.article`. ### Request Example ```json { "enabledCollections": ["api::page.page", "api::article.article"], "moderatorRoles": ["Authenticated", "Editor"], "approvalFlow": ["api::page.page"], "badWords": true, "blockedAuthorProps": ["email"], "entryLabel": { "*": ["Title", "title"], "api::article.article": ["headline"] } } ``` ### Response #### Success Response (200) Returns the updated plugin configuration object. #### Response Example (Example response structure would be detailed here if provided in source) ``` -------------------------------- ### GraphQL Configuration Source: https://github.com/virtuslab-open-source/strapi-plugin-comments/blob/master/README.md Configuration options for enabling and securing the GraphQL endpoint for the comments plugin. ```APIDOC ## Additional GQL Configuration To enable GraphQL for comments, install and enable `@strapi/plugin-graphql`. You can choose to make it publicly accessible or restricted to authenticated users. **Important:** If using `config/plugins.{js|ts}`, ensure the `comments` configuration precedes `graphql` to avoid schema issues. ### Configuration Example ```json { // ... "gql": { "auth": true // Default: false } // ... } ``` ### Properties - `auth` (boolean) - Determines if GraphQL queries require authentication. Defaults to `false`. ### Authentication Headers If `auth` is set to `true`, include the `Authorization` header with a bearer token for all requests: ```json { "Authorization": "Bearer " } ``` ``` -------------------------------- ### Retrieve Abuse Reports Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Fetch all abuse reports submitted for review. ```bash curl -X GET "http://localhost:1337/api/comments/moderate/reports" \ -H "Authorization: Bearer " ``` -------------------------------- ### Restore Default Plugin Configuration via API Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Reset the Strapi Comments plugin configuration to its default settings using a DELETE request. Requires an admin JWT token for authorization. ```bash curl -X DELETE "http://localhost:1337/api/comments/settings/config" \ -H "Authorization: Bearer " ``` -------------------------------- ### Get Comments GraphQL Query Source: https://github.com/virtuslab-open-source/strapi-plugin-comments/blob/master/README.md GraphQL query to retrieve a hierarchical list of comments for a specific relation. ```graphql query { findAllInHierarchy(relation: "api::page.page:njx99iv4p4txuqp307ye8625") { id content blocked children { id content } threadOf { id } author { id name } } } ``` -------------------------------- ### GET /api/comments Source: https://github.com/virtuslab-open-source/strapi-plugin-comments/blob/master/README.md Retrieves a hierarchical list of comments for a specified content type and entity document ID. ```APIDOC ## GET /api/comments ### Description Fetches comments for a specific content item, returned in a nested tree structure. ### Method GET ### Endpoint `/api/comments/api::.:` **Example URL**: `https://localhost:1337/api/comments/api::page.page:njx99iv4p4txuqp307ye8625` ### Request Body This endpoint does not accept a request body. ### Response #### Success Response (200) Returns an array of comment objects, where each object may contain a `children` array for nested comments. ```json [ { // -- Comment Model fields --, "children": [ { // -- Comment Model fields --, "children": [ // ... ] } // ... ] } // ... ] ``` #### Strapi REST API Properties Support - Field selection - Sorting - Pagination ``` -------------------------------- ### POST /graphql (createAbuseReport) Source: https://github.com/virtuslab-open-source/strapi-plugin-comments/blob/master/README.md This mutation allows users to report a comment for abuse by providing the comment ID, relation, reason, and additional content. ```APIDOC ## POST /graphql ### Description Creates an abuse report for a specific comment. ### Method POST ### Endpoint /graphql ### Request Body - **commentId** (Int) - Required - The ID of the comment being reported. - **relation** (String) - Required - The relation identifier for the content. - **reason** (Enum) - Required - The reason for the report. Available values: BAD_WORDS, OTHER, DISCRIMINATION. - **content** (String) - Optional - Additional details regarding the report. ### Request Example mutation createAbuseReport { createAbuseReport( input: { commentId: 34 relation: "api::page.page:njx99iv4p4txuqp307ye8625" reason: BAD_LANGUAGE content: "Rude language" } ) { id reason content related { id author { id name } } } } ### Response #### Success Response (200) - **id** (Int) - The ID of the created report. - **content** (String) - The content of the report. - **reason** (String) - The reason provided for the report. - **related** (Object) - The related comment and author information. #### Response Example { "data": { "createAbuseReport": { "id": 28, "content": "Rude language", "reason": "DISCRIMINATION", "related": { "id": 34, "author": { "id": "12345678", "name": "John Wick" } } } } } ``` -------------------------------- ### Configure GraphQL Authentication Source: https://github.com/virtuslab-open-source/strapi-plugin-comments/blob/master/README.md Set the auth property in your plugin configuration to toggle authentication requirements for GraphQL queries. ```json { // ... "gql": { "auth": true // Default: false } // ... } ``` -------------------------------- ### POST /api/comments/moderate/thread/:id/postComment Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Post a comment as an administrator. ```APIDOC ## POST /api/comments/moderate/thread/:id/postComment ### Description Post a comment as an administrator (marked as admin comment). ### Request Body - **content** (string) - Required - The comment text - **author** (object) - Required - Admin author details ``` -------------------------------- ### Create Comment (GraphQL) Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Add a new comment or a reply to an existing comment using a GraphQL mutation. Requires relation, content, and author details. ```graphql # Create comment mutation mutation CreateComment { createComment( input: { relation: "api::page.page:njx99iv4p4txuqp307ye8625" content: "This is my GraphQL comment!" threadOf: null author: { id: "guest-123" name: "Guest User" email: "guest@example.com" } } ) { id content createdAt author { id name } threadOf { id } } } # Create reply to existing comment mutation CreateReply { createComment( input: { relation: "api::page.page:njx99iv4p4txuqp307ye8625" content: "This is a reply!" threadOf: 1 author: { id: "guest-456" name: "Another Guest" email: "another@example.com" } } ) { id content threadOf { id } } } ``` -------------------------------- ### Post Comment as Generic User Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Use this endpoint to post a comment as a non-authenticated user. Requires author details in the request body. ```bash curl -X POST "http://localhost:1337/api/comments/api::page.page:njx99iv4p4txuqp307ye8625" \ -H "Content-Type: application/json" \ -d '{ "author": { "id": "guest-user-123", "name": "Guest User", "email": "guest@example.com", "avatar": "https://example.com/avatar.jpg" }, "content": "This is my comment on the article.", "threadOf": null }' ``` -------------------------------- ### GET /api/comments/:contentType:documentId Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Retrieves all comments for a specific Content Type entity in a nested tree structure with parent-child relationships. ```APIDOC ## GET /api/comments/:contentType:documentId ### Description Retrieves all comments for a specific Content Type entity in a nested tree structure with parent-child relationships. ### Method GET ### Endpoint `/api/comments/:contentType:documentId` ### Query Parameters - **sort** (string) - Optional - Sort order for comments (e.g., `createdAt:desc`). - **pagination[page]** (integer) - Optional - The page number for pagination. - **pagination[pageSize]** (integer) - Optional - The number of items per page. ### Response #### Success Response (200) - **id** (integer) - The unique identifier of the comment. - **documentId** (string) - The ID of the document the comment is associated with. - **content** (string) - The content of the comment. - **blocked** (boolean) - Indicates if the comment is blocked. - **blockedThread** (boolean) - Indicates if the entire thread is blocked. - **approvalStatus** (string) - The approval status of the comment (e.g., `APPROVED`). - **author** (object) - Information about the comment author. - **id** (string) - The author's unique identifier. - **name** (string) - The author's name. - **email** (string) - The author's email (if not blocked). - **avatar** (string) - URL to the author's avatar. - **createdAt** (string) - The date and time the comment was created. - **updatedAt** (string) - The date and time the comment was last updated. - **children** (array) - An array of nested replies to this comment. #### Response Example ```json [ { "id": 1, "documentId": "abc123", "content": "This is a great article!", "blocked": false, "blockedThread": false, "approvalStatus": "APPROVED", "author": { "id": "user-123", "name": "John Doe", "email": "john@example.com", "avatar": null }, "createdAt": "2024-01-15T10:30:00.000Z", "updatedAt": "2024-01-15T10:30:00.000Z", "children": [ { "id": 2, "content": "I agree with this comment!", "author": { "id": "user-456", "name": "Jane Smith" }, "children": [] } ] } ] ``` ### Request Example ```bash # Get hierarchical comments for a Page with documentId curl -X GET "http://localhost:1337/api/comments/api::page.page:njx99iv4p4txuqp307ye8625" \ -H "Content-Type: application/json" # With pagination and sorting curl -X GET "http://localhost:1337/api/comments/api::page.page:njx99iv4p4txuqp307ye8625?sort=createdAt:desc&pagination[page]=1&pagination[pageSize]=10" ``` ``` -------------------------------- ### Post a Comment Response Source: https://github.com/virtuslab-open-source/strapi-plugin-comments/blob/master/README.md The response body returned upon successfully creating a comment. ```json { // -- Comment Model fields --- } ``` -------------------------------- ### Get Hierarchical Comments Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Retrieve comments for a specific Content Type entity in a nested tree structure. Supports sorting and pagination. ```bash # Get hierarchical comments for a Page with documentId curl -X GET "http://localhost:1337/api/comments/api::page.page:njx99iv4p4txuqp307ye8625" \ -H "Content-Type: application/json" # Response [ { "id": 1, "documentId": "abc123", "content": "This is a great article!", "blocked": false, "blockedThread": false, "approvalStatus": "APPROVED", "author": { "id": "user-123", "name": "John Doe", "email": "john@example.com", "avatar": null }, "createdAt": "2024-01-15T10:30:00.000Z", "updatedAt": "2024-01-15T10:30:00.000Z", "children": [ { "id": 2, "content": "I agree with this comment!", "author": { "id": "user-456", "name": "Jane Smith" }, "children": [] } ] } ] # With pagination and sorting curl -X GET "http://localhost:1337/api/comments/api::page.page:njx99iv4p4txuqp307ye8625?sort=createdAt:desc&pagination[page]=1&pagination[pageSize]=10" ``` -------------------------------- ### Post Reply to Existing Comment Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Use this endpoint to post a reply to an existing comment, creating a threaded conversation. Specify the parent comment's ID in the `threadOf` field. ```bash curl -X POST "http://localhost:1337/api/comments/api::page.page:njx99iv4p4txuqp307ye8625" \ -H "Content-Type: application/json" \ -d '{ "author": { "id": "guest-user-456", "name": "Another User", "email": "another@example.com" }, "content": "I agree with your point!", "threadOf": 1 }' ``` -------------------------------- ### Query Comments by Author (GraphQL) Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Fetch all comments made by a specific author, supporting both Strapi and generic user types. Useful for user profile pages. ```graphql # Query comments by Strapi user query GetAuthorComments { findAllPerAuthor( authorId: 1 authorType: STRAPI pagination: { page: 1, pageSize: 20 } sort: ["createdAt:desc"] ) { data { id content blocked createdAt threadOf { id } } } } # Query comments by generic user query GetGenericAuthorComments { findAllPerAuthor( authorId: 123 authorType: GENERIC ) { data { id content } } } ``` -------------------------------- ### Get Comments (by Author) Source: https://github.com/virtuslab-open-source/strapi-plugin-comments/blob/master/README.md Retrieves comments posted by a specific author, optionally filtered by type. Supports filtering, field selection, sorting, and pagination. ```APIDOC ## GET /api/comments/author/:id/ ### Description Retrieves a flat structure of comments by a specified Author ID. An optional type parameter can be provided. ### Method GET ### Endpoint `/api/comments/author//` ### Path Parameters - **id** (string) - Required - The ID of the author. - **type** (string) - Optional - The type of user (e.g., 'generic'). ### Query Parameters - **omit** (array) - Optional - A list of Comment entity fields to omit from the response (e.g., `omit[]=author&omit[]=related`). `id` is always included. - **filtering** (object) - Optional - Allows filtering of comments. - **fields** (string) - Optional - Allows selection of specific fields. - **sort** (string) - Optional - Allows sorting of comments. - **pagination** (object) - Optional - Allows pagination of results. ### Response #### Success Response (200) - **data** (array) - A list of comment objects. - **meta** (object) - Contains pagination information. #### Response Example ```json { "data": [ { "// -- Comment Model fields --": "" }, { "// -- Comment Model fields --": "" } ], "meta": { "pagination": { "// payload based on Strapi REST Pagination specification": "" } } } ``` #### Error Response (400) - Bad Request. Requested list for not valid / not existing Content Type. ``` -------------------------------- ### Mutation CreateComment Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Creates a new comment or a reply to an existing comment. ```APIDOC ## GraphQL Mutation createComment ### Description Create a new comment or reply. ### Parameters #### Request Body - **input** (Object) - Required - The comment input object containing relation, content, threadOf, and author details. ### Request Example mutation CreateComment { createComment( input: { relation: "api::page.page:njx99iv4p4txuqp307ye8625" content: "This is my GraphQL comment!" threadOf: null author: { id: "guest-123" name: "Guest User" email: "guest@example.com" } } ) { id content } } ``` -------------------------------- ### Get Comments by Author with Field Omission Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Retrieves comments by a specific author and allows omitting certain fields from the response using the `omit[]` query parameter. ```bash curl -X GET "http://localhost:1337/api/comments/author/1?omit[]=author&omit[]=related" ``` -------------------------------- ### DELETE /api/comments/settings/config Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Reset plugin configuration to defaults. ```APIDOC ## DELETE /api/comments/settings/config ### Description Reset plugin configuration to defaults. ### Method DELETE ### Endpoint `/api/comments/settings/config` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```bash curl -X DELETE "http://localhost:1337/api/comments/settings/config" \ -H "Authorization: Bearer " ``` ### Response #### Success Response (200) Indicates successful reset of configuration. #### Response Example (Example response structure would be detailed here if provided in source) ``` -------------------------------- ### Configure Strapi Comments Plugin Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Configure the plugin in `config/plugins.ts` to enable features like profanity filtering, moderator roles, and content type specific settings. ```typescript // config/plugins.ts module.exports = ({ env }) => ({ comments: { enabled: true, config: { badWords: true, // Enable profanity filtering moderatorRoles: ["Authenticated"], approvalFlow: ["api::page.page"], // Content Types requiring approval entryLabel: { "*": ["Title", "title", "Name", "name", "Subject", "subject"], "api::page.page": ["MyField"], }, blockedAuthorProps: ["email"], // Hide author email from responses reportReasons: { BAD_LANGUAGE: "BAD_LANGUAGE", DISCRIMINATION: "DISCRIMINATION", OTHER: "OTHER", MY_CUSTOM_REASON: "MY_CUSTOM_REASON", }, gql: { auth: false, // Set to true to require authentication for GraphQL }, client: { url: "https://myapp.com", contactEmail: "contact@myapp.com", }, }, }, }); ``` -------------------------------- ### Post Comment for Multi-language Entity Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Use this endpoint to post a comment on a multi-language entity. Specify the desired locale in the request body. ```bash curl -X POST "http://localhost:1337/api/comments/api::page.page:njx99iv4p4txuqp307ye8625" \ -H "Content-Type: application/json" \ -d '{ "author": { "id": "user-123", "name": "User", "email": "user@example.com" }, "content": "Commentaire en français", "locale": "fr" }' ``` -------------------------------- ### Provide Authentication Header Source: https://github.com/virtuslab-open-source/strapi-plugin-comments/blob/master/README.md Include the Authorization header in requests when GraphQL authentication is enabled. ```json { "Authorization": "Bearer " } ``` -------------------------------- ### Register Custom Lifecycle Hooks Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Register lifecycle hooks for Comment and Report content types to execute custom logic on database events. ```APIDOC ## Register Custom Lifecycle Hooks ### Description Register lifecycle hooks for Comment and Report content types to execute custom logic on database events. ### Method Strapi Plugin API (Bootstrap/Register Function) ### Endpoint N/A (Internal Strapi function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript // In your Strapi bootstrap or register function export default { async bootstrap({ strapi }) { const commentsCommonService = strapi.plugin("comments").service("common"); // Hook for after comment creation commentsCommonService.registerLifecycleHook({ callback: async ({ action, result }) => { console.log(`Comment created with ID: ${result.id}`); // Send notification, update analytics, etc. await notifySlack(`New comment: ${result.content}`); }, contentTypeName: "comment", hookName: "afterCreate", }); // Hook for after report creation commentsCommonService.registerLifecycleHook({ callback: async ({ action, result }) => { console.log(`Abuse report created: ${result.reason}`); // Alert moderators, log to external system, etc. await logToAuditSystem(action, result); }, contentTypeName: "report", hookName: "afterCreate", }); // Hook for before comment update commentsCommonService.registerLifecycleHook({ callback: async ({ action, result }) => { // Validate content, check permissions, etc. console.log("Comment about to be updated"); }, contentTypeName: "comment", hookName: "beforeUpdate", }); }} ``` ### Response None (This is a registration function) ### Available Hooks `beforeCreate`, `afterCreate`, `beforeUpdate`, `afterUpdate`, `beforeDelete`, `afterDelete`, `beforeFindOne`, `afterFindOne`, `beforeFindMany`, `afterFindMany`, `beforeCount`, `afterCount`, and their "Many" variants. ``` -------------------------------- ### Update Plugin Configuration via API Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Update the Strapi Comments plugin configuration at runtime using a PUT request with a JSON payload. Requires an admin JWT token and specifies content types, roles, and other settings. ```bash curl -X PUT "http://localhost:1337/api/comments/settings/config" \ -H "Authorization: Bearer " \ -H "Content-Type: application/json" \ -d '{ "enabledCollections": ["api::page.page", "api::article.article"], "moderatorRoles": ["Authenticated", "Editor"], "approvalFlow": ["api::page.page"], "badWords": true, "blockedAuthorProps": ["email"], "entryLabel": { "*": ["Title", "title"], "api::article.article": ["headline"] } }' ``` -------------------------------- ### Report Abuse via GraphQL Source: https://context7.com/virtuslab-open-source/strapi-plugin-comments/llms.txt Submit an abuse report for a specific comment using a GraphQL mutation. ```graphql mutation ReportAbuse { createAbuseReport( input: { commentId: 5 relation: "api::page.page:njx99iv4p4txuqp307ye8625" reason: BAD_LANGUAGE content: "This comment uses inappropriate language" } ) { id reason content related { id content author { id name } } } } ```