Turning on comments

The following features are now available on Turbo pages:
  • User authorization and logout.
  • 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. Enable commenting

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

Note. For the 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 — The original URL of the page that has a Turbo page.

limit — Maximum number of items in the list. Is used to implement the Show more button.

offset — Offset in the list. Is used to implement 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.
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",
      "date": 1536210000,
      "content": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
      "id": "1111",
      "replies": [
        {
          "name": "Moe",
          "date": 1536210000,
          "content": "Phasellus interdum feugiat dui id facilisis.",
          "id": "2222",
          "answer_to": "1111"
        },
        {
          "name": "Barney",
          "date": 1536210000,
          "content": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
          "id": "3333",
          "answer_to": "2222"
        }
      ]
    },
    {
      "name": "Homer",
      "date": 1536210000,
      "content": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
      "id": "55556"
    }
  ]
}
Copied to clipboard
offset *
Offset in the list. Used to implement the Show more button.
limit *
Maximum number of items in the list. Used to implement the Show more button.
total *
Total number of comments on the page.
id *
Comment ID.
name *
User name.
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

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 — The 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. Processes the received URL.
  2. Saves the comment to the database.
  3. 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. Enable commenting

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 → Settings → Comments page.
  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 changes.
  4. Check how comments are displayed on the example Turbo page.