Accept pasted images in inbox Other and Reply answers
This commit is contained in:
@@ -326,7 +326,11 @@ func (m *Manager) Deliver(ctx context.Context, sessionID string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
after, err := m.turn(ctx, sess, task, pending[0].Response.User, deliveryMessage(pending), nil)
|
||||
images := []string{}
|
||||
for _, p := range pending {
|
||||
images = append(images, p.Response.Images...)
|
||||
}
|
||||
after, err := m.turn(ctx, sess, task, pending[0].Response.User, deliveryMessage(pending), images)
|
||||
if errors.Is(err, ErrConflict) {
|
||||
slog.Info("deliver held: session changed state", "session", sessionID, "err", err, "responses", ids)
|
||||
return nil
|
||||
@@ -433,6 +437,12 @@ func (m *Manager) responsesMidTurn(ctx context.Context, l *live) (string, []stri
|
||||
return "", nil
|
||||
}
|
||||
ids := responseIDs(pending)
|
||||
for _, p := range pending {
|
||||
if len(p.Response.Images) > 0 {
|
||||
slog.Info("deliver held mid-turn: response has images", "session", l.id, "responses", ids)
|
||||
return "", nil
|
||||
}
|
||||
}
|
||||
|
||||
waiting, err := m.store.AwaitingHuman(ctx, l.id)
|
||||
if err != nil {
|
||||
@@ -498,14 +508,22 @@ func deliveryMessage(pending []store.Pending) string {
|
||||
fmt.Fprintf(b, "%s chose: %s\n", r.User, (*r.Options)[0])
|
||||
}
|
||||
case api.Other:
|
||||
text := ""
|
||||
if r.Text != nil {
|
||||
text = *r.Text
|
||||
}
|
||||
if p.Item.Kind == api.Question {
|
||||
fmt.Fprintf(b, "%s answered (none of your options): %s\n", r.User, *r.Text)
|
||||
fmt.Fprintf(b, "%s answered (none of your options): %s\n", r.User, text)
|
||||
fmt.Fprintf(b, "If this asks you something back, answer by calling ask_human with thread_id %q.\n", p.Item.ThreadId)
|
||||
} else {
|
||||
fmt.Fprintf(b, "%s replied: %s\n", r.User, *r.Text)
|
||||
fmt.Fprintf(b, "%s replied: %s\n", r.User, text)
|
||||
}
|
||||
}
|
||||
|
||||
if len(r.Images) > 0 {
|
||||
fmt.Fprintf(b, "%s attached %d image(s) to this response; they come with this message.\n", r.User, len(r.Images))
|
||||
}
|
||||
|
||||
for _, a := range r.Attachments {
|
||||
j, err := json.Marshal(a)
|
||||
if err != nil {
|
||||
|
||||
@@ -42,6 +42,10 @@ func (m *Manager) Respond(ctx context.Context, user string, creates []api.InboxR
|
||||
if create.Attachments != nil {
|
||||
attachments = *create.Attachments
|
||||
}
|
||||
images := []string{}
|
||||
if create.Images != nil {
|
||||
images = *create.Images
|
||||
}
|
||||
|
||||
resolutions = append(resolutions, store.Resolution{
|
||||
State: state,
|
||||
@@ -52,6 +56,7 @@ func (m *Manager) Respond(ctx context.Context, user string, creates []api.InboxR
|
||||
Type: create.Type,
|
||||
Options: create.Options,
|
||||
Text: create.Text,
|
||||
Images: images,
|
||||
Attachments: attachments,
|
||||
CreatedAt: time.Now().UTC(),
|
||||
},
|
||||
@@ -102,6 +107,7 @@ func CheckResponse(item api.InboxItem, c api.InboxResponseCreate) (api.InboxStat
|
||||
if c.Text != nil {
|
||||
text = strings.TrimSpace(*c.Text)
|
||||
}
|
||||
images := c.Images != nil && len(*c.Images) > 0
|
||||
question := item.Kind == api.Question
|
||||
bad := func(format string, args ...any) (api.InboxState, error) {
|
||||
return "", fmt.Errorf("%w: item %s: "+format, append([]any{ErrInvalid, item.Id}, args...)...)
|
||||
@@ -128,14 +134,14 @@ func CheckResponse(item api.InboxItem, c api.InboxResponseCreate) (api.InboxStat
|
||||
}
|
||||
seen[o] = true
|
||||
}
|
||||
if text != "" && item.Payload["multiple"] != true {
|
||||
return bad("a pick-one option takes no text; use other")
|
||||
if (text != "" || images) && item.Payload["multiple"] != true {
|
||||
return bad("a pick-one option takes no text or images; use other")
|
||||
}
|
||||
return api.Answered, nil
|
||||
|
||||
case api.Other:
|
||||
if text == "" {
|
||||
return bad("other needs text")
|
||||
if text == "" && !images {
|
||||
return bad("other needs text or images")
|
||||
}
|
||||
return api.Answered, nil
|
||||
|
||||
@@ -143,6 +149,9 @@ func CheckResponse(item api.InboxItem, c api.InboxResponseCreate) (api.InboxStat
|
||||
if question {
|
||||
return bad("questions need an option or other, not a dismissal")
|
||||
}
|
||||
if images {
|
||||
return bad("a dismissal takes no images")
|
||||
}
|
||||
return api.Dismissed, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user