pusher / chatkit-server-go

Chatkit server SDK for Golang
https://pusher.com/chatkit
MIT License
13 stars 4 forks source link

SendMultipartData #22

Closed frankegoesdown closed 4 years ago

frankegoesdown commented 5 years ago

Hello I have struct for marshaling json-request

type MultiPartMessage struct {
    RoomID   string            `json:"room_id"`
    SenderID string            `json:"sender_id"`
    Parts    []chatkit.NewPart `json:"parts"`
}

And then I sending json like:

{
    "room_id": "ololo_room",
    "sender_id": "first",
    "parts": [
        { "type": "text/plain", "content": "😍" },
                {
                     "type": "image/gif",
                     "url": "https://gfycat.com/failingforkedheterodontosaurus"
               }
         ]
}

it decoded into {ololo_room first [<nil> <nil>]} decoding:

err := json.NewDecoder(r.Body).Decode(&message)
        if err != nil {
            log.Println(err)
        }

and I got error:

Error response: 422, map[error:services/chatkit/unprocessable_entity/validation_failed error_description:One of `content`, `url` or `attachment` field must be present error_uri:https://docs.pusher.com/errors/services/chatkit/unprocessable_entity/validation_failed]

When I'm trying parse reguest-json to chatkit.SendMultipartMessageOptions

var message chatkit.SendMultipartMessageOptions
        err := json.NewDecoder(r.Body).Decode(&message)
        log.Println(message)

it prints:

2019/07/14 20:13:42 {  [<nil> <nil>]}
2019/07/14 20:13:42 json: cannot unmarshal object into Go struct field SendMultipartMessageOptions.Parts of type core.NewPart

Please tell me how can I marshal request json in SendMultipartMessageOptions struct correctly?

BenPope commented 4 years ago

Closing as stale. Please re-open with more details if this is still an issue on the latest version.