# Reply to content

> Send a platform reply from a Koil content event.

Use replies when your application receives a `content.*` event and needs to respond on the platform, such as replying to a comment or message.

## How it works

1.  Receive and verify the Koil event from [Subscribe to events](https://docs.koil.co/guides/subscribe-to-events).
    
2.  Store the event `id` for dedupe, then read the identifiers from the event:
    
    -   `context.profileId`
    -   `data.kind`
    -   `data.externalId`
    -   `data.containerId`, for a message or a mentioning comment
3.  Check that the collection your reply goes to (by the rule below) supports `publish`. `GET /v1/profiles/{profileId}/capabilities`
    
4.  Submit a reply Publish Request using the event's `context.profileId`, built by the rule below. Send `Prefer: wait=10` to have the response carry the reply's outcome ([Waiting for the outcome](https://docs.koil.co/guides/publishing#waiting-for-the-outcome)). `POST /v1/publish-requests`
    
5.  Store the returned publish request ID.
    
6.  A `200` response carries the reply's outcome: `succeeded` with the reply's `externalId`, or a failure with its `error`. After a `202`, follow the request until it settles: `succeeded`, `failed`, `cancelled`, or `outcome_unknown`. Read its status, or subscribe to `publish_request.*`. `GET /v1/publish-requests/{publishRequestId}`
    

## Example

```bash
curl -X POST "https://api.koil.co/v1/publish-requests" \
  -H "Authorization: Bearer $KOIL_API_KEY" \
  -H "Koil-Version: 2026-12-08" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
  "publishRequests": [
    {
      "collection": "instagram.media.comments",
      "profileId": "prof_123",
      "args": {
        "target": {
          "kind": "instagram.media.comments",
          "externalId": "comment_456"
        },
        "text": "Thanks for reaching out."
      }
    }
  ]
}'
```

Derive the `Idempotency-Key` from the event `id` (for example `reply-{id}`) rather than generating a fresh one, so a redelivered event produces the same reply request instead of a second reply.

One rule covers every platform: **publish to the collection of what your reply creates, with `target` to reply to content or `containerId` to reply in a conversation.** [Content](https://docs.koil.co/concepts/content) explains `kind`, `containerId`, `target`, and the other fields every content payload shares.

-   **Content:** `target` is the content the reply responds to, identified exactly as the event identified it — pass the event data's `kind` and `externalId` straight through. A reply to a comment, a post or a mention is a comment, so it goes to that platform's comments collection: targeting a comment publishes a reply, a post a top-level comment, and a mention a comment on the mentioning post or under the mentioning comment (pass a mentioning comment's `containerId` as `args.containerId`). A reply to a Google Business Profile review goes to `google_business_profile.locations.review_replies`.
-   **Conversations:** a DM reply is the next message in the conversation, so set `collection` to the message's `kind` (such as `instagram.dm.messages`) and `args.containerId` to its `containerId`. The conversation's earlier messages list through `GET /v1/profiles/{profileId}/content/instagram.dm.messages` with the same `containerId`. A WhatsApp group chat is the same: its messages arrive as `whatsapp.groups.messages` with the group as `containerId`, so publishing to `whatsapp.groups.messages` with that `containerId` replies in the group. Most message platforms have no reply-to-message concept on their send APIs, so Koil does not invent one; where the platform can quote a message, as WhatsApp and TikTok can, the send also accepts an optional `target`. A message carries text or a file: send a file as one `args.attachments` item (`mediaId` or `sourceUrl`), where the collection takes one. Instagram and Messenger send text and a file as separate messages, so a request carries one or the other, and they do not apply a file's `filename`. On WhatsApp, `text` with a file is its caption (audio takes none).
-   **Quick replies and buttons:** on Instagram and Messenger, a text message can offer up to 13 `args.quickReplies`, or carry up to three `args.buttons` under text of up to 640 characters (a `reply` or `url` button; Messenger also takes a `phone` button), but not both. When the person taps a quick reply or a `reply` button, the tap arrives as their message: its `text` is the option's title and `choice.payload` the payload you set, so match on the payload. `choice` is on the message's event only: reading the message later returns its `text` without it. Meta does not say which message offered the option, so such a message has no `target`. On WhatsApp, a tapped template quick-reply button, reply button or list row arrives the same way, with the message that offered it as `target`.
-   **WhatsApp templates:** outside the 24-hour customer service window, send `args.template` (the approved template's `name` and `language`, and the values for its `header`, `body` and `buttons`) with no `text` or `attachments`. A template can also start a conversation: address it by `args.recipientPhoneNumber` instead of `args.containerId`, and the person's replies arrive under their BSUID.
-   **Photo comments:** a Facebook or TikTok comment takes one image as `args.attachments`, with or without `text`.

## Edit or delete a reply

Once published, a reply is ordinary content: its succeeded publish request names its `externalId`, and it also arrives as an event with `data.ownerAuthored: true`.

-   Edit its text with `PATCH /v1/profiles/{profileId}/content/{collection}/{externalId}` and a body of `{ "text": "…" }`. The response is the edited item, as a read returns it; add `includePlatformRaw=true` to the query string, as on a read, to include the platform's payload.
-   Delete it with `DELETE /v1/profiles/{profileId}/content/{collection}/{externalId}`.

The platform decides what can change. Facebook, LinkedIn, and YouTube let the profile edit the text of a comment it wrote, and a Google Business Profile reply is edited the same way; Instagram, TikTok, and direct messages cannot be edited. The capabilities endpoint reports `update` for each collection that supports it.

## Dedupe and retries

Use the `profileId` from the event unless your product intentionally lets an operator choose another eligible Profile.

Events can be retried or replayed. Dedupe inbound events on the event `id` (also sent beside the event as `event-id`, the `webhook-id` header on a webhook), and send an `Idempotency-Key` header when submitting the reply so customer-side retries do not create duplicate replies.

Koil delivers both sides of a conversation: content the profile itself authored — an agent replying from the platform's app, or a reply you published through Koil — arrives as a normal `content.*` event. It is identifiable in-event: the profile's own comments and messages have `data.ownerAuthored: true`. Inbox products should render these; automations that respond to events must skip them so a bot never replies to its own replies. `ownerAuthored` is absent when Koil cannot tell (TikTok's comment webhook does not say), so also skip an item whose `data.externalId` is the `externalId` of a reply you published (`publish_request.succeeded` carries it).

If your reply UI needs fresh platform state, fetch the content before replying: `GET /v1/profiles/{profileId}/content/{collection}/{externalId}`
