Skip to main content

Adding Comments Only Visible to Specific Users with Activity Function

Overview

Here, we explain how to add comments for specific users using the endpoint (Comment::insert) to leave comments in the activity function.
Comments for specific users will only be displayed to the target user.
As an example, we assume the creation of a space where support and private chat can be done on the HP, and perform confirmation of operation with SwaggerUI.

What you can learn

We will perform the following steps to confirm the operation within the Kuroco management screen.

Prerequisites

Prepare users like the following in advance. Image from Gyazo

Diverta Taro and Diverta Support leave comments for each other, and confirm that comments are displayed to Diverta Taro but not to Diverta Jiro.

Creating an Activity Definition

First, create an activity definition.
Click [Activity Definition].

Image from Gyazo

Click [Add].

Image from Gyazo

Set the permissions for the "All members who have not logged in." to "Not allowed", and set the permissions for other groups to "Allowed", then click [Add].

Image from Gyazo

Note the activity ID you created as you will use it later.

Image from Gyazo

Creating Content

Next, create the content that will be the target of the comments to be added.

Select any content definition and click [Add] on the Content List screen.

Image from Gyazo

Enter the following and click [Add].

ItemValue
TitleKuroco Chat Support

Image from Gyazo Image from Gyazo

Note the content ID you added as you will use it later.

Image from Gyazo

Creating Endpoints

Create two endpoints: one to display only comments addressed to the user (comments) and one to send comments (comments/insert).

Image from Gyazo

Comments Endpoint

In the comments endpoint, set the id parameter to the activity ID and check the to_me_list and my_list parameters.
Checking the to_me_list parameter will return comments targeting the user who sent the request to the endpoint.
Also, checking the my_list parameter will return comments sent by the user.

ItemSetting
Pathcomments
CategoryActivity
ModelComment
Operationlist
id37 (ID of the created activity definition)
module_id1144 (ID of the created content)
my_listCheck
to_me_listCheck

Image from Gyazo
Image from Gyazo
Image from Gyazo

comments/insert Endpoint

In the comments/insert endpoint, set the id parameter to the activity ID.

ItemSetting
Pathcomments/insert
CategoryActivity
ModelComment
Operationinsert
id37 (ID of the created activity definition)

Image from Gyazo

Verify the Operation with Swagger UI

Leave a Comment

Once you are ready, verify the operation with Swagger UI.

First, log in with the account of Diverta Taro (27).

tip

If you set the API security to Cookie, you can create a session in a logged-in state by entering the member ID.
You can also create a login endpoint and log in with ID and password.

Image from Gyazo

Next, open the comments/insert endpoint, click on [Try it out], paste the following code into the response body, and execute it.

{
"module_id": 1144,
"name": "Diverta Taro",
"note": "Please tell me about Kuroco.",
"delkey": "",
"to_member_ids": [
30
]
}
caution

Specify the ID of the created content in "module_id": 1144. Specify the member ID of the comment destination (Diverta Support in this case) in "to_member_ids": [30].

tip

to_member_ids can also specify multiple users as follows:

{
"to_member_ids": [
1,
2,
3
]
}

When a response code of 200 and the message "Comment writing was successful." are displayed, the addition of the comment is complete.
Image from Gyazo

Leave a Reply Comment

Similarly, log in with the account of Diverta Support (30) and leave the following comment.

{
"module_id": 1144,
"name": "Diverta Support",
"note": "Kuroco is an API-first headless CMS.",
"delkey": "",
"to_member_ids": [
27
]
}
caution

Specify the ID of the created content in "module_id": 1144. Specify the member ID of the comment destination (Diverta Taro in this case) in "to_member_ids": [27].

Image from Gyazo

Check the Comments

Log in with Diverta Taro (member ID = 27) and send a request to the comments endpoint to get the above two comments in the response.

Image from Gyazo

Image from Gyazo

Image from Gyazo

Image from Gyazo

info

For simplicity of display items, the output permission list was set for the endpoint post-processing in the above captures.

However, even if another user (Diverta Jiro, member ID = 22) logs in and sends a request to the comments endpoint, no response will be obtained.

Image from Gyazo

Image from Gyazo

Image from Gyazo

Image from Gyazo

The confirmation of the operation is complete. By implementing the functionality tested in SwaggerUI on the front end, you can create a space on the website where users can have support and private chats.

When logging in with Diverta Support(30), the chat history with Diverta Jiro(22) will also be displayed, so please adjust the display on the company side as needed.


Support

If you have any other questions, please contact us or check out Our Slack Community.