HTTP API: register, list and remove webhooks, kept across restarts (closes #6)
check / check (push) Successful in 1m2s

POST, GET and DELETE under /api/v1/chats/{id}/webhooks, for the chats
that GET /api/v1/chats lists. The webhooks are kept in
$DATA_DIR/webhooks.json, mode 0600, which each change replaces whole
through a temporary file in the same directory and a rename. bot.Run
reads the file before it starts the chat client: absent means none, and
a file that cannot be read aborts startup. Reading a JSON request body
moved into decodeBody, which the messages endpoint now shares. Nothing
is posted to a webhook yet.

Model: opus-5-5
This commit is contained in:
2026-09-29 06:08:04 +00:00
parent f53b666119
commit cbcae80260
11 changed files with 1018 additions and 47 deletions
+1 -16
View File
@@ -1,9 +1,7 @@
package api
import (
"encoding/json"
"errors"
"io"
"net/http"
"net/url"
"strconv"
@@ -124,21 +122,8 @@ func (h *handlers) handleSend() http.HandlerFunc {
return
}
body, err := io.ReadAll(r.Body)
var tooLarge *http.MaxBytesError
if errors.As(err, &tooLarge) {
h.respondError(w, http.StatusRequestEntityTooLarge, "the body is too large")
return
}
var req request
if err != nil || json.Unmarshal(body, &req) != nil {
h.respondError(w, http.StatusBadRequest,
`the body must be JSON such as {"text":"hello"}`)
if !h.decodeBody(w, r, &req, `{"text":"hello"}`) {
return
}