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
-
Receive and verify the Koil event from Subscribe to events.
-
Store the event
idfor dedupe, then read the identifiers from the event:context.profileIddata.kinddata.externalIddata.containerId, for a message or a mentioning comment
-
Check that the collection your reply goes to (by the rule below) supports
publish.GET /v1/profiles/{profileId}/capabilities -
Submit a reply Publish Request using the event's
context.profileId, built by the rule below. SendPrefer: wait=10to have the response carry the reply's outcome (Waiting for the outcome).POST /v1/publish-requests -
Store the returned publish request ID.
-
A
200response carries the reply's outcome:succeededwith the reply'sexternalId, or a failure with itserror. After a202, follow the request until it settles:succeeded,failed,cancelled, oroutcome_unknown. Read its status, or subscribe topublish_request.*.GET /v1/publish-requests/{publishRequestId}
Example
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 explains kind, containerId, target, and the
other fields every content payload shares.
- Content:
targetis the content the reply responds to, identified exactly as the event identified it — pass the event data'skindandexternalIdstraight 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'scontainerIdasargs.containerId). A reply to a Google Business Profile review goes togoogle_business_profile.locations.review_replies. - Conversations: a DM reply is the next message in the conversation, so
set
collectionto the message'skind(such asinstagram.dm.messages) andargs.containerIdto itscontainerId. The conversation's earlier messages list throughGET /v1/profiles/{profileId}/content/instagram.dm.messageswith the samecontainerId. A WhatsApp group chat is the same: its messages arrive aswhatsapp.groups.messageswith the group ascontainerId, so publishing towhatsapp.groups.messageswith thatcontainerIdreplies 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 optionaltarget. A message carries text or a file: send a file as oneargs.attachmentsitem (mediaIdorsourceUrl), 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'sfilename. On WhatsApp,textwith 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 threeargs.buttonsunder text of up to 640 characters (areplyorurlbutton; Messenger also takes aphonebutton), but not both. When the person taps a quick reply or areplybutton, the tap arrives as their message: itstextis the option's title andchoice.payloadthe payload you set, so match on the payload.choiceis on the message's event only: reading the message later returns itstextwithout it. Meta does not say which message offered the option, so such a message has notarget. On WhatsApp, a tapped template quick-reply button, reply button or list row arrives the same way, with the message that offered it astarget. - WhatsApp templates: outside the 24-hour customer service window, send
args.template(the approved template'snameandlanguage, and the values for itsheader,bodyandbuttons) with notextorattachments. A template can also start a conversation: address it byargs.recipientPhoneNumberinstead ofargs.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 withouttext.
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; addincludePlatformRaw=trueto 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}