Turning on comments

Note. If your site uses the Wordpress CMS, look at our example of enabling comments.
For Turbo pages, you can enable:
  • 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:

  1. Step 1. Create a resource that returns the list of comments
  2. Step 2. Create a resource that adds a comment
  3. Step 3. Add a commenting section

Step 1. Create a resource that returns the list of comments

Attention. For Turbo pages to interact with the comments API, allow Cross-Origin requests for *.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 clipboard
offset *
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

Attention. For Turbo pages to interact with the comments API, allow Cross-Origin requests for *.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 clipboard
answer_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:
  1. Available for Cross-Origin requests from *.yandex.*, *.turbopages.org.
  2. Processes the received URL.
  3. Saves the comment to the database.
  4. 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 clipboard
id
Comment ID.
date
Comment date (timestamp in UNIX format).

Resource example is available on GitHub.

Step 3. Add a commenting section

Note. If you sent comments using the comment block, you don't have to delete it from your RSS feed. It will be automatically replaced.

To enable commenting, do the following:

  1. In Yandex.Webmaster, go to the Turbo pages for content sites → Settings → Comments page and choose Other API for comments.
  2. 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.
  3. Save your changes.
  4. Check the comments display on the sample Turbo page.