HTTP API: a chat's recent messages, and sending a message (closes #5)
check / check (push) Successful in 1m21s
check / check (push) Successful in 1m21s
GET /api/v1/chats/{id}/messages returns the messages among a chat's
last count items (default 20, at most 100), oldest first. POST sends a
text, waits for the chat client's answer and returns 201 with the
message as sent. A chat the bot does not have is 404, a contact who
deleted the chat is 409, a text too long for one message is 413, and
any other failure is 500 with a chosen sentence.
The chat client spells out a message's formatting in its answer, up to
26 times the text's length, so 100 items in one answer can pass the
16 MiB read limit and end the connection. Items are read five at a
time.
Model: opus-5-5
This commit is contained in:
@@ -60,9 +60,9 @@ const (
|
||||
)
|
||||
|
||||
// fakeChat stands in for the chat client's API. It answers each command
|
||||
// with the record in replies under the command's first word, stays
|
||||
// silent for a command it has no record for, and reports every command
|
||||
// it receives on got.
|
||||
// with the record in replies under the whole command or else under its
|
||||
// first word, stays silent for a command it has no record for, and
|
||||
// reports every command it receives on got.
|
||||
type fakeChat struct {
|
||||
replies map[string]string
|
||||
got chan string
|
||||
@@ -112,8 +112,13 @@ func (f *fakeChat) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
f.got <- cmd.Cmd
|
||||
|
||||
name, _, _ := strings.Cut(cmd.Cmd, " ")
|
||||
if resp, ok := f.replies[name]; ok {
|
||||
resp, ok := f.replies[cmd.Cmd]
|
||||
if !ok {
|
||||
name, _, _ := strings.Cut(cmd.Cmd, " ")
|
||||
resp, ok = f.replies[name]
|
||||
}
|
||||
|
||||
if ok {
|
||||
f.send(cmd.CorrID, resp)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user