Skip to content
Chatwise
Skip to Content
Developer docs

Delivery and retries

What Chatwise does with each answer, when it tries again, and how to handle an event more than once.

View as Markdown

Answer quickly

Answer with any 2xx status within 10 seconds. Only the status counts: Chatwise doesn't read the body.

Save the event or put it in a queue, answer, and do the work afterwards. An endpoint that does slow work before it answers times out, and gets the same event again.

What each answer does

Your answerWhat happens
2xxDelivered.
408, 425, 429 or 5xxRetried.
No answer in 10 seconds, or a connection errorRetried.
410 GoneFailed, and the endpoint is disabled.
Any other status, redirects includedFailed, without a retry.

So answer 4xx only for a request you will never accept, such as one whose signature is wrong. Make sure nothing in front of your code does it for you: a framework or proxy that limits bodies to less than 256 KiB answers 413 to large events, and those aren't retried. If a mistake of yours refused good events, fix it and redeliver them.

Retry schedule

A delivery is tried 8 times. After a failed attempt the next one comes after:

AttemptWaits after the one before
1The first attempt
210 seconds
31 minute
45 minutes
530 minutes
62 hours
76 hours
816 hours

Each wait can be up to 20% shorter, so that many retries don't arrive together. When all 8 attempts failed, the delivery fails with retry_exhausted, and lastStatusCode has the last answer's status.

Every attempt sends the same event with the same webhook-id. The webhook-timestamp and the signature are new each time.

Handle an event more than once

Delivery is at least once. The same event can arrive again, for example when your answer got lost on the way or someone redelivers it. Keep the webhook-id of every event you handled, and skip one you already have. If two endpoints lead to the same receiver, an event they both receive arrives twice with the same id:

CREATE TABLE handled_webhooks (id text PRIMARY KEY, handled_at timestamptz NOT NULL DEFAULT now());

-- In the transaction that does the work. No row inserted: it was already handled.
INSERT INTO handled_webhooks (id) VALUES ($1) ON CONFLICT DO NOTHING;

Keep the ids for at least 30 days, as long as an event can be redelivered.

Don't rely on the order

Events can arrive in another order than they happened, above all after a retry. Sort by data.message.sentAt where the order matters, or read the conversation's messages.

410 Gone

Answer 410 to say that a URL doesn't want events any more. Chatwise then:

  • marks the delivery as failed, without a retry;
  • sets the endpoint's status to DISABLED, with the reason in health.disabledReason.

A disabled endpoint receives nothing. To turn it on again, set its status to ACTIVE. Its deliveries that were still waiting are then sent, but events that happened in between aren't.

Nothing else disables an endpoint.

What isn't sent

  • Events from before the endpoint was created, or from while it was paused or disabled.
  • A message that was unsent, deleted or hidden before its delivery went out. The delivery fails with message_removed, which doesn't count against the endpoint. If the event wasn't prepared yet, there is no delivery.
  • An event larger than 256 KiB. The delivery fails with payload_too_large.
  • An event whose payload can't be built. There is no delivery.

Slow endpoints

Chatwise sends an endpoint only a few requests at a time, so one that answers slowly delays its own events, and can delay those of the workspace's other endpoints.

Get the endpoint to see how it is doing: health has its last success, its last failure and how many attempts failed in a row.

On this page