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.
- Creating an Activity Definition
- Creating Content
- Creating Endpoints
- Verify the Operation with Swagger UI
Prerequisites
Prepare users like the following in advance.
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].
Click [Add].
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].
Note the activity ID you created as you will use it later.
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.
Enter the following and click [Add].
Item | Value |
---|---|
Title | Kuroco Chat Support |
Note the content ID you added as you will use it later.
Creating Endpoints
Create two endpoints: one to display only comments addressed to the user (comments
) and one to send comments (comments/insert
).
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.
Item | Setting |
---|---|
Path | comments |
Category | Activity |
Model | Comment |
Operation | list |
id | 37 (ID of the created activity definition) |
module_id | 1144 (ID of the created content) |
my_list | Check |
to_me_list | Check |
comments/insert Endpoint
In the comments/insert
endpoint, set the id
parameter to the activity ID.
Item | Setting |
---|---|
Path | comments/insert |
Category | Activity |
Model | Comment |
Operation | insert |
id | 37 (ID of the created activity definition) |
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).
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.
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
]
}
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]
.
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.
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
]
}
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]
.
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.
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.
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.
Related documents
Support
If you have any other questions, please contact us or check out Our Slack Community.