New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MediaAttachment in Send API should work without URL or ResuseId #1062
Comments
Here is some workaround and the information for the documentation: First we need a simple new import com.restfb.Facebook;
import com.restfb.types.send.MediaAttachment.Type;
import com.restfb.types.send.MessageAttachment;
public class UploadMessageAttachment extends MessageAttachment {
@Facebook
private Object payload = new Object();
// payload is important, without publishing will not work
private static final long serialVersionUID = 1L;
public UploadMessageAttachment(Type type) {
setType(type.toString().toLowerCase());
}
} Now we have the code in the application. We need a recipient, an attachment and the we can publish the answer. This will look like: IdMessageRecipient recipient = new IdMessageRecipient("receiving user id");
BinaryAttachment attachment = BinaryAttachment.with("filename", getIs());
// we have to tell FB what kind of attachment we are going to publish,
// in this example it is an image, but you can use file, video and audio, too
UploadMessageAttachment messageAttachment = new UploadMessageAttachment(Type.IMAGE);
// the message can only contain text OR an attachment
Message message = new Message(messageAttachment);
//Now, we publish this stuff
SendResponse resp = client.publish("me/messages", SendResponse.class, attachment,
Parameter.with("recipient", recipient),
Parameter.with("message", message));
// in the resp object you find some useful information |
There is no way to send more than 1 attachment or to include a text, right? So we will have publish each attachment and the text individually. |
Yes, this is how the Facebook API works... |
According to the Facebook docs it is possible to send an attachment without providing an URL or a ReuseId. The binary data is directly send to the me/messages endpoint.
We have to support this, too.
https://developers.facebook.com/docs/messenger-platform/send-messages#file
The text was updated successfully, but these errors were encountered: