Turning on comments
- User authorization (log in and log out).
- List of comments returned by your API.
- Adding a comment.
Only an authorized user can add a new comment. To enable this feature, turn on authorization.
To add commenting, do the following:
Step 1. Create a resource that returns the list of comments
*.yandex.*
, *.turbopages.org
.- How it works
- The Turbo page sends a GET request to your resource to receive the list of comments. The page URL is passed in the
ORIGINAL_URL
query parameter. The resource should process the URL and return the list of comments for the page.Example of a request sent by a Turbo page:
GET https://my-domain.ru/api/comments?ORIGINAL_URL={page}&limit={limit}&offset={offset}
ORIGINAL_URL — Original URL of the page that has a Turbo page.
limit — Maximum number of items in the list. Used for implementing the Show more button.
offset — Offset in the list. Used for implementing the Show more button.
- What you need to do
- Create a resource that processes the received URL and returns a list of comments for the page in the JSON format. Allow Cross-Origin requests for the resource from
*.yandex.*
,*.turbopages.org
.Attention. The resource must be accessible over HTTPS. - Expected resource response
- HTTP response code: 200.JSON example:
{ "offset": 0, "limit": 50, "total": 140, "comments": [ { "name": "Homer", "avatar": "https://some-domain.ru/some-avatar-image.png", "date": 1536210000, "content": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", "id": "1111", "replies": [ { "name": "Moe", "avatar": "https://some-domain.ru/another-avatar-image.png", "date": 1536210000, "content": "Phasellus interdum feugiat dui id facilisis.", "id": "2222", "answer_to": "1111" }, { "name": "Barney", "avatar": "https://some-domain.ru/yet-another-avatar-image.png", "date": 1536210000, "content": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", "id": "3333", "answer_to": "2222" } ] }, { "name": "Homer", "avatar": "https://some-domain.ru/some-avatar-image.png", "date": 1536210000, "content": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", "id": "55556" } ] }
Copied to clipboardoffset
*Offset in the list. Used for implementing the Show more button.limit
*Maximum number of items in the list. Used for implementing the Show more button.total
*Total number of comments on the page.id
*Comment ID.name
*User name.avatar
URL of the user's avatar.date
*Comment date (timestamp in UNIX format).content
*Text of the comment as a string. Inline tags are not supported.replies
Array of responses.answer_to
ID of the root comment.* Required
Resource example is available on GitHub.
Step 2. Create a resource that adds a comment
*.yandex.*
, *.turbopages.org
.- How it works
- An authorized user fills in the comment form and submits it. The Turbo page sends a POST request to your resource. The resource must process the request and save the comment in the database.
Example of a request sent by a Turbo page:
POST https://my-domain.ru/api/comments?ORIGINAL_URL={page}&TURBO_ID={id}
ORIGINAL_URL — Original URL of the page that has a Turbo page.
TURBO_ID: ID of the user who sent the comment.
Example of a comment passed in the body of a POST request:
{ "answer_to": "2222", "text": "lorem ipsum" }
Copied to clipboardanswer_to
Comment ID.text
Text of the comment as a string. Inline tags are not supported.You can determine the user's login name by TURBO_ID or Cookie.
- What you need to do
- Create a resource that:
- Available for Cross-Origin requests from
*.yandex.*
,*.turbopages.org
. - Processes the received URL.
- Saves the comment to the database.
- Returns a response if the comment was processed successfully.
Attention. The resource must be accessible over HTTPS. - Expected resource response
If a request was processed successfully, the resource should return:
HTTP response code: 200.JSON example:{ "id": "101231", "date": 1536210020 }
Copied to clipboardid
Comment ID.date
Comment date (timestamp in UNIX format).
Resource example is available on GitHub.
Step 3. Add a commenting section
To enable commenting, do the following:
- In Yandex.Webmaster, go to the Other API for comments.page and choose
- Specify links to resources:
- URL of the comments list, for example, https://my-domain.ru/api/list-comments.
- URL for adding comments, for example, https://my-domain.ru/api/add-comments.Note. You can implement everything on the same resource, for example, https://my-domain.ru/api/comments.
- Save your changes.
- Check the comments display on the sample Turbo page.