HTTP API: a chat's recent messages, and sending a message #5

Open
opened 2026-09-28 11:10:25 +02:00 by clawbot · 0 comments

Part of #2. Builds on the API server of #4 and starts from next once that is merged.

What. Two endpoints: a chat's recent messages, and sending a message to a chat.

Decisions (reversible, taken by the repo-manager):

  • GET /api/v1/chats/{id}/messages?count=N returns 200 and {"messages":[...]}, oldest first. count defaults to 20 and must be a whole number from 1 to 100; anything else is 400. It uses the chat client's /_get chat @{id} count=N (response apiChat; the command is in the client's parser but not in bots/api/COMMANDS.md). Only message items (rcvMsgContent, sndMsgContent) are returned, so fewer than N may come back; the README says so.
  • A message is {"id":{itemId},"direction":"received"|"sent","type":"{msgContent type}","text":"...","time":"{RFC 3339}"}. The webhooks reuse this record, so define it once.
  • POST /api/v1/chats/{id}/messages with {"text":"..."} sends a text message and returns 201 and {"message":{...}}, the sent message. Body not JSON, or text empty, is 400. It waits for the chat client's answer (newChatItems), so it needs a new client method: the existing SendText does not wait, which is right for the event handler and wrong here.
  • A chat id that is not a number, or not one of the bot's contacts, is 404. Find out from the real chat client which error it returns for a missing contact, and map that one error; any other failure is 500 with a chosen sentence.
  • Check the wire format against the real simplex-chat v7.0.2 in the image, as the README's throwaway client does. Name every container and volume you create after this issue, never touch simplexcalc or simplexcalc-data, and remove what you created.

Done when:

  • Tests cover both endpoints against the stand-in chat client, including count bounds, 404, 400, and a send that the chat client refuses.
  • README: both endpoints in the API section with curl examples and the message record. docs/TODO.md Completed Steps gets a line.
  • make check is green.

Model: opus-5-5

Part of https://git.eeqj.de/sneak/simplexcalc/issues/2. Builds on the API server of https://git.eeqj.de/sneak/simplexcalc/issues/4 and starts from `next` once that is merged. **What.** Two endpoints: a chat's recent messages, and sending a message to a chat. **Decisions** (reversible, taken by the repo-manager): - `GET /api/v1/chats/{id}/messages?count=N` returns `200` and `{"messages":[...]}`, oldest first. `count` defaults to `20` and must be a whole number from 1 to 100; anything else is `400`. It uses the chat client's `/_get chat @{id} count=N` (response `apiChat`; the command is in the client's parser but not in `bots/api/COMMANDS.md`). Only message items (`rcvMsgContent`, `sndMsgContent`) are returned, so fewer than N may come back; the README says so. - A message is `{"id":{itemId},"direction":"received"|"sent","type":"{msgContent type}","text":"...","time":"{RFC 3339}"}`. The webhooks reuse this record, so define it once. - `POST /api/v1/chats/{id}/messages` with `{"text":"..."}` sends a text message and returns `201` and `{"message":{...}}`, the sent message. Body not JSON, or `text` empty, is `400`. It waits for the chat client's answer (`newChatItems`), so it needs a new client method: the existing `SendText` does not wait, which is right for the event handler and wrong here. - A chat id that is not a number, or not one of the bot's contacts, is `404`. Find out from the real chat client which error it returns for a missing contact, and map that one error; any other failure is `500` with a chosen sentence. - Check the wire format against the real `simplex-chat` v7.0.2 in the image, as the README's throwaway client does. Name every container and volume you create after this issue, never touch `simplexcalc` or `simplexcalc-data`, and remove what you created. **Done when:** - Tests cover both endpoints against the stand-in chat client, including `count` bounds, `404`, `400`, and a send that the chat client refuses. - README: both endpoints in the API section with `curl` examples and the message record. `docs/TODO.md` Completed Steps gets a line. - `make check` is green. Model: opus-5-5
clawbot added a new dependency 2026-09-28 11:10:29 +02:00
clawbot added a new dependency 2026-09-28 11:10:29 +02:00
clawbot self-assigned this 2026-09-28 11:10:30 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Reference: sneak/simplexcalc#5