Linework Developers
ES
Obtener acceso

Guía · comments:write

Responder a comentarios

Un pequeño bot que revisa los comentarios de tus últimos posts y responde a los nuevos, sin responder nunca dos veces.

Scopes: posts:read y comments:write (opcional: likes:write).

Los endpoints#

EndpointUso
GET /me/postsTus últimos posts.
GET /posts/{id}/commentsComentarios de un post (paginado).
POST /posts/{id}/commentsEscribe un comentario o una respuesta.
DELETE /comments/{id}Elimina tu comentario, o un comentario en tu post.
POST /posts/{id}/likeDa me gusta a un post.

1. Lee los comentarios#

curl "https://api.linework.app/open/v1/posts/1043/comments?limit=100" \
  -H "Authorization: Bearer $LINEWORK_API_KEY"
{
  "data": [
    {
      "id": "88121",
      "text": "Where is this?",
      "author": { "id": "5512", "username": "giulia" },
      "createdAt": "2026-10-14T09:30:00.000Z"
    }
  ],
  "next_cursor": null
}

2. Responde#

Para responder a un comentario concreto, pasa su id como parentId; sin él, el comentario se publica en el post.

curl https://api.linework.app/open/v1/posts/1043/comments \
  -H "Authorization: Bearer $LINEWORK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "text": "Lake Como, from Varenna 😊", "parentId": "88121" }'

3. Júntalo todo#

Recuerda a qué comentarios ya has respondido (aquí, en un archivo local) y omite tus propios comentarios.

import { readFile, writeFile } from "node:fs/promises";

const API = "https://api.linework.app/open/v1";
const headers = {
  Authorization: `Bearer ${process.env.LINEWORK_API_KEY}`,
  "Content-Type": "application/json",
};
const get = (p) => fetch(API + p, { headers }).then((r) => r.json());

const seen = new Set(JSON.parse(await readFile("seen.json", "utf8").catch(() => "[]")));
const me = await get("/me");
const posts = await get("/me/posts?limit=10");

for (const post of posts.data) {
  const comments = await get(`/posts/${post.id}/comments?limit=100`);
  for (const c of comments.data) {
    if (seen.has(c.id) || c.author.id === me.id) continue;
    const reply = answer(c.text);
    if (reply) {
      await fetch(`${API}/posts/${post.id}/comments`, {
        method: "POST",
        headers,
        body: JSON.stringify({ text: reply, parentId: c.id }),
      });
    }
    seen.add(c.id);
  }
}
await writeFile("seen.json", JSON.stringify([...seen]));

function answer(text) {
  if (/where|dove/i.test(text)) return "Lake Como, from Varenna 😊";
  return null; // no canned answer: leave it to a human
}
import json, os, re, requests

API = "https://api.linework.app/open/v1"
s = requests.Session()
s.headers["Authorization"] = f"Bearer {os.environ['LINEWORK_API_KEY']}"

try:
    seen = set(json.load(open("seen.json")))
except FileNotFoundError:
    seen = set()

def answer(text):
    if re.search(r"where|dove", text, re.I):
        return "Lake Como, from Varenna 😊"
    return None  # no canned answer: leave it to a human

me = s.get(API + "/me", timeout=30).json()
posts = s.get(API + "/me/posts", params={"limit": 10}, timeout=30).json()
for post in posts["data"]:
    comments = s.get(f"{API}/posts/{post['id']}/comments", params={"limit": 100}, timeout=30).json()
    for c in comments["data"]:
        if c["id"] in seen or c["author"]["id"] == me["id"]:
            continue
        reply = answer(c["text"])
        if reply:
            s.post(f"{API}/posts/{post['id']}/comments",
                   json={"text": reply, "parentId": c["id"]}, timeout=30)
        seen.add(c["id"])

json.dump(sorted(seen), open("seen.json", "w"))

Ejecútalo cada pocos minutos (cron, una tarea programada, un temporizador serverless). Cada ejecución hace unas pocas solicitudes, muy por debajo del límite de 120 por minuto.

Reglas para los bots de comentarios#

  • Cuota diaria: 300 comentarios y 500 me gusta por cuenta.
  • Responde solo donde la respuesta sea útil. No publiques el mismo texto una y otra vez, y no comentes en posts de personas que nunca han interactuado contigo.
  • Cuando el bot no esté seguro, que no diga nada y deje responder a una persona.