Skip to content

Commit

Permalink
fix wenichats send media
Browse files Browse the repository at this point in the history
  • Loading branch information
rasoro committed Feb 1, 2023
1 parent 0e6e3a2 commit 304c03e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions services/tickets/wenichats/web.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package wenichats

import (
"bytes"
"context"
"encoding/json"
"io"
Expand Down Expand Up @@ -91,14 +92,14 @@ func handleEventCallback(ctx context.Context, rt *runtime.Runtime, r *http.Reque
maxBodyBytes = mb100
}
bodyReader := io.LimitReader(file.Body, int64(maxBodyBytes)+1)
_, err = io.ReadAll(bodyReader)
bodyBytes, err := io.ReadAll(bodyReader)
if err != nil {
return err, http.StatusBadRequest, nil
}
if bodyReader.(*io.LimitedReader).N <= 0 {
return errors.Wrapf(err, "unable to send media type %s because response body exceeds %d bytes limit", file.ContentType, maxBodyBytes), http.StatusBadRequest, nil
}

file.Body = io.NopCloser(bytes.NewReader(bodyBytes))
_, err = tickets.SendReply(ctx, rt, ticket, "", []*tickets.File{file})
if err != nil {
return errors.Wrapf(err, "error on send ticket reply with media '%s'", m.URL), http.StatusInternalServerError, nil
Expand Down

0 comments on commit 304c03e

Please sign in to comment.