fb-messenger-cli icon indicating copy to clipboard operation
fb-messenger-cli copied to clipboard

Add the ability to send attachments both from filename and from the clipboard

Open justanironic opened this issue 7 years ago • 4 comments

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.

justanironic avatar Aug 06 '17 21:08 justanironic

Is there a Messenger API endpoint that exists for something like this? @SamBergeron @Alex-Rose this would be pretty fantastic.

sarangjo avatar Aug 17 '17 23:08 sarangjo

+1 for this. Not sure how we'd do it.

jackpetraitis avatar Jul 17 '18 23:07 jackpetraitis

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.

  1. bringing up uplpoad box: POST to https://www.messenger.com/ajax/bz
  2. after selecting file:
    • OPTIONS to https://upload.messenger.com/ajax/mercury/upload.php
    • POST to https://upload.messenger.com/ajax/mercury/upload.php
  3. 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/ with has_attachment set to true and parameter pointing to the id of the uploaded file

p1ho avatar May 24 '19 23:05 p1ho

@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.

p1ho avatar May 28 '19 02:05 p1ho