fb-messenger-cli
fb-messenger-cli copied to clipboard
Add the ability to send attachments both from filename and from the clipboard
I often screenshot things to send to my friends, and I usually just use lightshot to copy a portion of my screen into a picture. Adding a /send clipboard
command would be very useful, as well as /send attachment {filepath}
command would be very useful.
Is there a Messenger API endpoint that exists for something like this? @SamBergeron @Alex-Rose this would be pretty fantastic.
+1 for this. Not sure how we'd do it.
There is this Attachment Upload API, not sure if this will work.
I can play around with it, and add my updates here.
UPDATE: I made this comment before having taken a deeper look at the source code. I see that the messenger essentially tries to emulate the actions that would have been done in the browser, instead of using the Messenger Platform API.
In this case, I looked at the requests that are sent when uploading an attachment.
- bringing up uplpoad box: POST to
https://www.messenger.com/ajax/bz
- after selecting file:
- OPTIONS to
https://upload.messenger.com/ajax/mercury/upload.php
- POST to
https://upload.messenger.com/ajax/mercury/upload.php
- OPTIONS to
- after sending:
- OPTIONS to
https://upload.messenger.com/ajax/mercury/upload.php
- POST to
https://upload.messenger.com/ajax/mercury/upload.php
which will have a response with the fbid of the uploaded file. - POST to
https://www.messenger.com/messaging/send/
withhas_attachment
set to true and parameter pointing to the id of the uploaded file
- OPTIONS to
@justanironic @sarangjo @jackpetraitis I got it working!! Here's the gist of the function.
Essentially what happens is you must first upload (POST) the resource to the endpoint https://upload.messenger.com/ajax/mercury/upload.php
and create a binary stream of your file using fs.createReadStream(path)
.
Inside the response body from the endpoint exists the imageId
that points to the uploaded resource.
You then send a second POST to the normal endpoint https://www.messenger.com/messaging/send/
but include "has_attachment": "true"
and "image_ids[0]": imageId
in the form data. (I'm still testing different file types)
However, there existed a bug where if someone uploads a resource, you have to do /r
to get that information, it doesn't automatically get updated, but if you have your messenger opened in the web browser, you should see this file uploaded correctly. (Someone should be on it though)
UPDATE:
I've made a PR using my fork
You're able to now go to a thread and type /a path-to-file
and it will upload the file.
The bug mentioned above will prevent you from seeing it working in the commandline, so I'd have the messenger webpage pulled up as well.