Comment reply manager

From oyi77/1ai-skills · View interactive version

Comment reply manager is an AI agent skill from the GitHub repository oyi77/1ai-skills. Use when monitoring TikTok/Instagram comments — classify intent, auto-reply to FAQs, and DM high-intent commenters with LYNK affiliate links. Converts comment engagement into tracked affiliate sales.

How to use this skill

Skill file

Comment Reply Manager

Monitor TikTok/Instagram comments, classify intent, auto-reply to FAQs, and DM high-intent commenters with LYNK affiliate links.

Purpose: close the gap between comment engagement and affiliate sales. (Prior state: 196 clicks → 0 sales — engagement existed, the reply/DM funnel did not.)

When to Use

Trigger phrases:

Use cases:

When NOT to Use

Scope Honesty

The classification logic, reply templates, funnel logging, and rate-limit caps below are the substance of this skill and hold regardless of backend. The network calls are illustrative adapters, not verified contracts:

Intent Classification

Every comment is bucketed into exactly one class. This drives the action.

| Class | Signal | Action |

|---|---|---|

| faq_price | "how much", "price", "berapa", "$" | Auto-reply with price + LYNK link |

| faq_where | "where to buy", "link", "dimana", "mana" | Auto-reply "link in bio → [product]" |

| faq_size | "size", "ukuran", "fit", "M/L" | Auto-reply size guide link |

| faq_ship | "ship", "cod", "kirim", "delivery" | Auto-reply shipping policy |

| high_intent_dm | "buy", "want", "checkout", "pm", "dm me" | DM the LYNK link directly |

| objection | "scam", "fake", "trust", "review" | Reply with social proof + DM offer |

| spam | Bot patterns, repeated, off-topic | Ignore (no reply, no DM) |

| positive | Emoji, "love", compliments | Like / heart; no reply needed |

| question_other | Genuine question, not in FAQ | Queue for human reply |

Confidence threshold: 0.75. Below that → question_other (human).

Workflow

1. Fetch new comments

import requests, os, time

def fetch_comments(post_id: str, since_ts: int) -> list[dict]:
    # TikTok Business API — GET /business/comment/list/
    # UNVERIFIED PATH — confirm against the Business API docs before use
    r = requests.get(
        "https://business-api.tiktok.com/open_api/v1.3/business/comment/list/",
        headers={"Authorization": f"Bearer {os.environ['TIKTOK_ACCESS_TOKEN']}"},
        params={"post_id": post_id, "start_time": since_ts, "page_size": 100},
    )
    r.raise_for_status()
    return r.json()["data"]["comments"]

# Instagram: GET /{post_id}/comments via Graph API
def fetch_ig_comments(post_id: str) -> list[dict]:
    r = requests.get(
        f"https://graph.facebook.com/v18.0/{post_id}/comments",
        params={"access_token": os.environ["IG_ACCESS_TOKEN"],
                "fields": "id,text,from,timestamp"},
    )
    r.raise_for_status()
    return r.json()["data"]

2. Classify each comment

FAQ = [
    ("faq_price", ["berapa", "price", "how much", "$", "harga"]),
    ("faq_where", ["link", "where to buy", "dimana", "mana beli", "in bio"]),
    ("faq_size",  ["size", "ukuran", "fit", "xl", "m/l"]),
    ("faq_ship",  ["cod", "ship", "kirim", "delivery", "ongkir"]),
]

def classify(text: str, score: float = 1.0) -> tuple[str, float]:
    t = text.lower()
    # High-intent DM signals take precedence
    if any(k in t for k in ["want", "buy", "checkout", "pm", "dm me", "beli"]):
        return "high_intent_dm", 0.95
    if any(k in t for k in ["scam", "fake", "trust", "review"]):
        return "objection", 0.85
    for cls, keys in FAQ:
        if any(k in t for k in keys):
            return cls, 0.9
    # ...emoji-only, generic praise → positive
    if any(c in t for c in ["❤", "🔥", "😍", "love"]):
        return "positive", 0.8
    return "question_other", 0.4

For higher accuracy than keyword rules, swap classify for an LLM call (few-shot prompt with the table above as examples). Keep the keyword version as fallback when the API is down.

3. Auto-reply per class

REPLIES = {
    "faq_price": "Harga {price} — bisa langsung cek di bio ya! 🛒",
    "faq_where": "Link lengkapnya ada di bio (klik @handle). Stok terbatas! ✨",
    "faq_size":  "Size chart lengkap ada di link bio ya. Kalau ragu, ambil 1 size lebih besar. 📏",
    "faq_ship":  "Kirim dari {city}, COD tersedia. Estimasi {days} hari. 📦",
    "objection": "100% original — cek review di bio. Kalau ada ragu, DM aku ya! 🤝",
}

def reply(comment_id: str, cls: str) -> str | None:
    text = REPLIES.get(cls)
    if not text:
        return None
    r = requests.post(
        "https://business-api.tiktok.com/open_api/v1.3/business/comment/reply/create/",
        headers={"Authorization": f"Bearer {os.environ['TIKTOK_ACCESS_TOKEN']}"},
        json={"comment_id": comment_id, "content": text},
    )
    r.raise_for_status()
    return r.json()["data"]["reply_id"]

4. DM high-intent commenters with the LYNK link

def dm_lyk(user_id: str, product_slug: str) -> str:
    link = f"https://lynk.id/{os.environ['LYNK_HANDLE']}/{product_slug}"
    r = requests.post(
        f"https://business-api.tiktok.com/open_api/v1.3/business/direct_message/send/",
        headers={"Authorization": f"Bearer {os.environ['TIKTOK_ACCESS_TOKEN']}"},
        json={
            "user_id": user_id,
            "content": f"Hai! Ini link produknya ya: {link}\nKalau ada pertanyaan, reply di sini. 🙌",
        },
    )
    r.raise_for_status()
    return r.json()["data"]["message_id"]

Rate limit: max 20 DMs/hour per account. Exceeding it risks a platform flag — see §Rate Limits.

5. Track the funnel

import csv, datetime

def log_event(cls: str, comment_id: str, action: str, extra: str = ""):
    with open("funnel.csv", "a", newline="") as f:
        csv.writer(f).writerow([
            datetime.datetime.utcnow().isoformat(),
            cls, comment_id, action, extra,   # action: reply | dm | human_queue | skip
        ])

The metric that matters: DMs sent → link clicks → sales. If clicks stay flat while DMs rise, the DM copy is the problem, not the volume.

Rate Limits (avoid flags)

| Action | Cap | Window |

|---|---|---|

| Public replies | 30 | hour |

| DMs | 20 | hour |

| Comment fetches | 1 | 5 min per post |

Jitter every request by 1–3 s. Never loop faster than the caps. A single flagged account costs more than a day of slower replies.

Anti-Rationalization Table

| Rationalization | Reality |

|---|---|

| "More DMs = more sales" | Over DM'ing triggers spam flags and kills the account. Cap it. |

| "Reply to everything" | Spam comments replied-to train the algorithm wrong. Skip spam and positive. |

| "Keyword rules are enough" | Keywords miss context ("not for me but how much?"). Use an LLM classifier when volume justifies it. |

| "I'll check conversion later" | Without the funnel log you can't tell if the problem is reply, DM, or product. Log every event. |

Verification

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.