-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
So I finished the other end of the file-sending, which is sending att…
…achment-ids back, as well as tried to implement a secondary option of sending files directly. Netiher works atm, and my desire to get in touch with Facebook support is increasing. For example, when sending the file with attachment_id, it now gives the error of "wrong number of files sent", even though it doesn't make sense. Such an error should already appear earlier and has. The other method also doesn't work and is telling me that the recipient parameter is required, again, it's there. This leads me to believe that I don't either 1) understand how the Facebook curl examples work or 2) how using the JsonRestRequest in the xatkit rest platform package works.
- Loading branch information
Showing
7 changed files
with
171 additions
and
7 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
runtime/src/main/java/com/xatkit/plugins/messenger/platform/FileStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.xatkit.plugins.messenger.platform; | ||
|
||
import com.xatkit.execution.StateContext; | ||
import com.xatkit.plugins.messenger.platform.entity.Attachment; | ||
import com.xatkit.plugins.messenger.platform.entity.File; | ||
import com.xatkit.plugins.messenger.platform.entity.ReusableFile; | ||
import com.xatkit.plugins.messenger.platform.entity.payloads.AttachmentIDPayload; | ||
|
||
import java.util.HashMap; | ||
|
||
public class FileStorage { | ||
MessengerPlatform platform; | ||
HashMap<String, ReusableFile> files; | ||
|
||
public FileStorage(MessengerPlatform platform) { | ||
this.platform = platform; | ||
this.files = new HashMap<>(); | ||
} | ||
|
||
public Attachment LazyAttachment(String filepath, StateContext context) { | ||
CreateAttachment(null, filepath, Attachment.AttachmentType.file, null, context); | ||
return RetrieveAttachment(filepath); | ||
} | ||
|
||
public Attachment RetrieveAttachment(String name) { | ||
if (!files.containsKey(name)) return null; | ||
|
||
ReusableFile file = files.get(name); | ||
Attachment.AttachmentType type = file.getFile().getAttachment().getType(); | ||
AttachmentIDPayload payload = new AttachmentIDPayload(file.getAttachmentId()); | ||
Attachment attachment = new Attachment(type,payload); | ||
|
||
return attachment; | ||
} | ||
|
||
public void CreateAttachment(String name, String filepath, Attachment.AttachmentType type, String extension, StateContext context) { | ||
if (files.containsKey(name)) return; | ||
|
||
File file = new File(type,new java.io.File(filepath),extension); | ||
ReusableFile reusableFile = new ReusableFile(file); | ||
if (name == null) name = filepath; | ||
files.put(name,reusableFile); | ||
|
||
platform.sendFile(context,reusableFile); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
runtime/src/main/java/com/xatkit/plugins/messenger/platform/action/FileReply.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.xatkit.plugins.messenger.platform.action; | ||
|
||
import com.google.gson.Gson; | ||
import com.xatkit.execution.StateContext; | ||
import com.xatkit.plugins.messenger.platform.MessengerPlatform; | ||
import com.xatkit.plugins.messenger.platform.MessengerUtils; | ||
import com.xatkit.plugins.messenger.platform.entity.DirectFile; | ||
import com.xatkit.plugins.rest.platform.action.PostJsonRequestWithFormData; | ||
import lombok.val; | ||
import org.apache.http.HttpHeaders; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class FileReply extends PostJsonRequestWithFormData { | ||
private static final Gson gson = new Gson(); | ||
|
||
/** | ||
* Constructs a POST Json request with form data parameters | ||
* | ||
* @param platform the {@link MessengerPlatform} containing this action | ||
* @param context the {@link StateContext} associated to this action | ||
* @param file the information related to the file to be sent; | ||
*/ | ||
public FileReply(MessengerPlatform platform, StateContext context, DirectFile file) { | ||
super(platform, context, MessengerUtils.SEND_API_URL, null, null, generateHeaders(platform), file.getParams()); | ||
} | ||
|
||
private static Map<String, String> generateHeaders(MessengerPlatform platform) { | ||
val headers = new HashMap<String, String>(); | ||
headers.put(HttpHeaders.AUTHORIZATION, "Bearer " + platform.getAccessToken()); | ||
headers.put(HttpHeaders.CONTENT_TYPE, "application/json"); | ||
return headers; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
runtime/src/main/java/com/xatkit/plugins/messenger/platform/entity/DirectFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.xatkit.plugins.messenger.platform.entity; | ||
import com.google.gson.Gson; | ||
import com.xatkit.plugins.messenger.platform.entity.payloads.FilePayload; | ||
import fr.inria.atlanmod.commons.log.Log; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
public class DirectFile extends File { | ||
private static final Gson gson = new Gson(); | ||
|
||
private Recipient recipient; | ||
|
||
public DirectFile(String recipientId, File file) { | ||
super(file); | ||
this.recipient = new Recipient(recipientId); | ||
} | ||
|
||
public DirectFile(String recipientId, Attachment.AttachmentType attachmentType, java.io.File file, String fileExtension) { | ||
super(attachmentType,file,fileExtension); | ||
this.recipient = new Recipient(recipientId); | ||
} | ||
|
||
public Map<String, Object> getParams() { | ||
Map<String,Object> params = new LinkedHashMap<>(); | ||
params.put("recipient",gson.toJsonTree(new Messaging(recipient))); | ||
params.putAll(super.getParams()); | ||
return params; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
runtime/src/main/java/com/xatkit/plugins/messenger/platform/entity/ReusableFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.xatkit.plugins.messenger.platform.entity; | ||
|
||
public class ReusableFile { | ||
private String attachmentId; | ||
private String filePath; | ||
private File file; | ||
|
||
public ReusableFile(File file) { this.file = file; } | ||
public String getAttachmentId() { return attachmentId; } | ||
public void setAttachmentId(String attachmentId) { this.attachmentId = attachmentId; } | ||
public String getFilePath() { return filePath; } | ||
public void setFilePath(String filePath) { this.filePath = filePath; } | ||
public File getFile() { return file; } | ||
public void setFile(File file) { this.file = file; } | ||
} |
1c0ca59
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yea #20