Linework Developers
HI
एक्सेस पाएँ

गाइड · comments:write

कमेंट्स का जवाब दें

एक छोटा bot जो आपकी हाल की पोस्ट के कमेंट्स जाँचता है और नए कमेंट्स का जवाब देता है, कभी दो बार जवाब दिए बिना।

Scopes: posts:read और comments:write (वैकल्पिक: likes:write)।

Endpoints#

Endpointइस्तेमाल
GET /me/postsआपकी हाल की पोस्ट।
GET /posts/{id}/commentsकिसी पोस्ट के कमेंट्स (paginated)।
POST /posts/{id}/commentsकमेंट या जवाब लिखें।
DELETE /comments/{id}अपना कमेंट, या अपनी पोस्ट पर आया कमेंट डिलीट करें।
POST /posts/{id}/likeकिसी पोस्ट को लाइक करें।

1. कमेंट्स पढ़ें#

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. जवाब दें#

किसी ख़ास कमेंट का जवाब देने के लिए उसकी id को parentId के रूप में भेजें; इसके बिना कमेंट पोस्ट पर जाता है।

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. सब को एक साथ जोड़ें#

याद रखें कि आप किन कमेंट्स का पहले ही जवाब दे चुके हैं (यहाँ एक लोकल फ़ाइल में) और अपने ख़ुद के कमेंट्स को छोड़ दें।

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"))

इसे हर कुछ मिनट में चलाएँ (cron, कोई scheduled job, serverless timer)। हर run में कुछ ही requests होती हैं, जो प्रति मिनट 120 की सीमा से काफ़ी कम हैं।

कमेंट bots के नियम#

  • दैनिक quota: हर अकाउंट के लिए 300 कमेंट्स और 500 लाइक्स।
  • सिर्फ़ वहीं जवाब दें जहाँ जवाब उपयोगी हो। एक ही टेक्स्ट बार-बार पोस्ट न करें, और उन लोगों की पोस्ट पर कमेंट न करें जिन्होंने कभी आपसे बातचीत नहीं की।
  • जब bot को पक्का न पता हो, तो चुप रहें और किसी इंसान को जवाब देने दें।