Skip to content

Commit

Permalink
Fix issue with addFile in interaction replies
Browse files Browse the repository at this point in the history
  • Loading branch information
MinnDevelopment committed Jul 19, 2022
1 parent bef374a commit 2eb1341
Showing 1 changed file with 16 additions and 4 deletions.
Expand Up @@ -58,12 +58,24 @@ protected RequestBody finalizeData()
return getRequestBody(json);

MultipartBody.Builder body = AttachedFile.createMultipartBody(files, null);
DataArray attachments = DataArray.empty();

// Add the attachments array to the payload, as required since v10
DataObject data;
if (json.isNull("data"))
json.put("data", data = DataObject.empty());
else
data = json.getObject("data");

DataArray attachments;
if (data.isNull("attachments"))
data.put("attachments", attachments = DataArray.empty());
else
attachments = data.getArray("attachments");

for (int i = 0; i < files.size(); i++)
attachments.add(files.get(i).toAttachmentData(i));
if (json.isNull("data"))
json.put("data", DataObject.empty());
json.getObject("data").put("attachments", attachments);

body.addFormDataPart("payload_json", json.toString());
files.clear();
return body.build();
}
Expand Down

0 comments on commit 2eb1341

Please sign in to comment.