{"action":"created","issue":{"url":"https://api.github.com/repos/Aurasphere/facebot/issues/2","repository_url":"https://api.github.com/repos/Aurasphere/facebot","labels_url":"https://api.github.com/repos/Aurasphere/facebot/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/Aurasphere/facebot/issues/2/comments","events_url":"https://api.github.com/repos/Aurasphere/facebot/issues/2/events","html_url":"https://github.com/Aurasphere/facebot/issues/2","id":190941039,"number":2,"title":"Possibility of attaching files instead of using URLS","user":{"login":"Aurasphere","id":14991778,"avatar_url":"https://avatars.githubusercontent.com/u/14991778?v=3","gravatar_id":"","url":"https://api.github.com/users/Aurasphere","html_url":"https://github.com/Aurasphere","followers_url":"https://api.github.com/users/Aurasphere/followers","following_url":"https://api.github.com/users/Aurasphere/following{/other_user}","gists_url":"https://api.github.com/users/Aurasphere/gists{/gist_id}","starred_url":"https://api.github.com/users/Aurasphere/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Aurasphere/subscriptions","organizations_url":"https://api.github.com/users/Aurasphere/orgs","repos_url":"https://api.github.com/users/Aurasphere/repos","events_url":"https://api.github.com/users/Aurasphere/events{/privacy}","received_events_url":"https://api.github.com/users/Aurasphere/received_events","type":"User","site_admin":false},"labels":[{"id":421588982,"url":"https://api.github.com/repos/Aurasphere/facebot/labels/help%20wanted","name":"help wanted","color":"128A0C","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-11-22T08:58:26Z","updated_at":"2016-11-26T21:32:46Z","closed_at":null,"body":"Currently the reply factory object will allow only to attach files using URLS (audio, video, images and generic files attachments).  Facebook API's also allows to upload a file directly. It would be nice to add this feature to the framework. Here's an instance of how to do it with cURL: https://developers.facebook.com/docs/messenger-platform/send-api-reference/audio-attachment.\r\nIn order to do this with FaceBot, we should add a method that makes a POST with multipart/data. \r\nI've made some tests with Postman and the API works even if you don't specify the extension of file you are attaching, so we don't need to add that."},"comment":{"url":"https://api.github.com/repos/Aurasphere/facebot/issues/comments/263087176","html_url":"https://github.com/Aurasphere/facebot/issues/2#issuecomment-263087176","issue_url":"https://api.github.com/repos/Aurasphere/facebot/issues/2","id":263087176,"user":{"login":"Aurasphere","id":14991778,"avatar_url":"https://avatars.githubusercontent.com/u/14991778?v=3","gravatar_id":"","url":"https://api.github.com/users/Aurasphere","html_url":"https://github.com/Aurasphere","followers_url":"https://api.github.com/users/Aurasphere/followers","following_url":"https://api.github.com/users/Aurasphere/following{/other_user}","gists_url":"https://api.github.com/users/Aurasphere/gists{/gist_id}","starred_url":"https://api.github.com/users/Aurasphere/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Aurasphere/subscriptions","organizations_url":"https://api.github.com/users/Aurasphere/orgs","repos_url":"https://api.github.com/users/Aurasphere/repos","events_url":"https://api.github.com/users/Aurasphere/events{/privacy}","received_events_url":"https://api.github.com/users/Aurasphere/received_events","type":"User","site_admin":false},"created_at":"2016-11-26T21:32:46Z","updated_at":"2016-11-26T21:32:46Z","body":"I'm having some troubles on this. I've tried this:\r\n\r\n`public static void postFormDataMessage(String recipient,\r\n\t\t\tAttachmentType type, File file) {\r\n\t\tString pageToken = FaceBotContext.getInstance().getPageToken();\r\n\t\t// If the page token is invalid, returns.\r\n\t\tif (!validatePageToken(pageToken)) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\t// TODO: add checks for valid attachmentTypes (FILE, AUDIO or VIDEO)\r\n\t\tHttpPost post = new HttpPost(FaceBotConstants.FACEBOOK_BASE_URL\r\n\t\t\t\t+ FaceBotConstants.FACEBOOK_MESSAGES_URL + pageToken);\r\n\r\n\t\tFileBody filedata = new FileBody(file);\r\n\t\tStringBody recipientPart = new StringBody(\"{\\\"id\\\":\\\"\" + recipient\r\n\t\t\t\t+ \"\\\"}\", ContentType.MULTIPART_FORM_DATA);\r\n\t\tStringBody messagePart = new StringBody(\"{\\\"attachment\\\":{\\\"type\\\":\\\"\"\r\n\t\t\t\t+ type.name().toLowerCase() + \"\\\", \\\"payload\\\":{}}}\",\r\n\t\t\t\tContentType.MULTIPART_FORM_DATA);\r\n\t\tMultipartEntityBuilder builder = MultipartEntityBuilder.create();\r\n\t\tbuilder.addPart(\"recipient\", recipientPart);\r\n\t\tbuilder.addPart(\"message\", messagePart);\r\n\t\tbuilder.addBinaryBody(\"filedata\", file);\r\n\t\tbuilder.setContentType(ContentType.MULTIPART_FORM_DATA);\r\n\r\n\t\tHttpEntity entity = builder.build();\r\n\t\tpost.setEntity(entity);\r\n\t\t\r\n\t\tsend(post);\r\n\t}`\r\n\r\nBut I'm getting an error about the attached file not supported. If I do the same request from postman it works though. I think the problem is related to the headers. This is the request generated by postman:\r\n\r\n`HTTP/1.1\r\nHost: graph.facebook.com\r\nCache-Control: no-cache\r\nPostman-Token: 6469ec4e-4622-7a93-7a9c-f428db6f4fcd\r\nContent-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"recipient\"\r\n\r\n{\"id\":\"1545768135449437\"}\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"message\"\r\n\r\n{\"attachment\":{\"type\":\"audio\", \"payload\":{}}}\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"filedata\"; filename=\"\"\r\nContent-Type: \r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--`\r\n\r\nAs you can see the Content-Type of the file data (the last part) is empty here, meanwhile the one generated with Apache Http is application/octet-stream and I don't really know how to leave it empty.\r\n\r\nAny help is appreciated.\r\n\r\n"}}
{"actor":{"display_login":"Aurasphere"}}