I have a webview
that opens from a messenger bot
.
From the webview
I want to send image data to the conversation (no URL - data coming from the canvas).
I tried to use Messenger SDK
beginShareFlow with file data attachment:
function uploadImage(data) {
let message = {
"attachment": {
"type": "image",
"payload": {
"is_reusable": true
},
"filedata": data
}
};
MessengerExtensions.beginShareFlow(function (share_response) {
// User dismissed without error
if (share_response.is_sent) {
// The user actually did share.
//close the webview
MessengerExtensions.requestCloseBrowser(function success() {
// webview closed
}, function error(err) {
console.log(err);
});
}
},
function (errorCode, errorMessage) {
// An error occurred in the process
console.log(errorMessage);
},
message, "current_thread");
}
But I get an error:
Messenger Extensions unexpected error.
Would appreciate help =]
EDIT:
I found out that filedata
is used to transfer a file location (which I do not have).
So I tried other solutions:
blob
, and tried to pass it in filedata
- did not work
blob
file (by adding name and date) and tried to move the location - did not work
blob
and tried to move it as a url (not as filedata) - and got an error: Invalid image URL provided in message content
When I go to the blob url from the browser I see the image =[
You probably already know that you can share photos, videos, and GIFs in Facebook Messenger, but you can even send files, too, including PDFs. This method of sharing is handy if you don't have a recipient's email address readily available or if you're only connected with them through Facebook.
To Insert text or HTML files into a message:Select the file and expand the Insert button. Select Insert as text. If the file contains HTML tags, it will render in the message as HTML.
The Messenger Profile API allows you to set, update, retrieve, and delete properties from the Page Messenger Profile.
Per the SDK's section on sending attachments:
There are three ways to attach an asset to a message:
- URL
- File
- attachment_id
The attachment_id
refers to previously uploaded URL/File attachments. Sending raw file data is not an option. You must either upload the image to a URL or save it to a file. Blob URLs do not work because they refer only to data stored in the local system's memory. You need to move that data to an image or file on a server.
Your first option is to upload the image to a URL. Depending on how private the contents of the image are, you could use a public image hosting service like imgur, or you could upload the image to a public location on your server. If you want to keep the image hidden, you could save the image at a URL containing a randomly generated hash and delete that file as soon as the attachment has been uploaded to Messenger. However, you could keep the image totally private with the second option:
Your second option is to upload the image according to a file location. By uploading the image to a file on your server, you could avoid the image ever becoming visible to the public. To avoid filling up server space, you could manually delete the file once the attachment has uploaded, or you could use a temp file. In fact, the SDK's example for sending a file demonstrates sending a temporary file saved in the /tmp
folder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With