How can I send a file to Facebook Send API using npm's Request without uploading the file?
<p>I'm implementing a bot that uses Facebook's Send API. According to the <a href="https://developers.facebook.com/docs/messenger-platform/send-api-reference/file-attachment" rel="nofollow noreferrer">documentation</a> it is possible to send files using a request. The documentation offers two methods, one sending a URL to the file and the other uploading the file. I don't want to upload the file and give it a URL as this is an open source library that doesn't want to assume anything about the implementation. </p>

<p>I do want to upload the file directly. The documentation for uploading the file uses <code>cURL</code> for the example and looks as follows:</p>

<pre><code>curl  \
  -F recipient='{"id":"USER_ID"}' \
  -F message='{"attachment":{"type":"file", "payload":{}}}' \
  -F filedata=@/tmp/receipt.pdf \
  "https://graph.facebook.com/v2.6/me/messages?access_token=PAGE_ACCESS_TOKEN"    
</code></pre>

<p>My current take is that it should look something like this:</p>

<pre class="lang-js prettyprint-override"><code>facebook_message.access_token = configuration.access_token;
var fileReaderStream = fs.createReadStream('./sampleData.json')
var formData = {
                "recipient": JSON.stringify({
                  "id":message.channel
               }),
               "attachment": JSON.stringify({
                  "type":"file", 
                  "payload":{}
               }),
               "filedata": fileReaderStream
               }

request({
         "method": 'POST',
         "json": true,
         "formData": formData,
         "uri": 'https://graph.facebook.com/v2.6/me/messages?access_token=' + configuration.access_token
        },
        function(err, res, body) {
               //***
        });
</code></pre>

<p>When I run this I receive the following response:</p>

<pre><code>{ 
  message: '(#100) Must send either message or state',
  type: 'OAuthException',
  code: 100,
  error_subcode: 2018015,
  fbtrace_id: '***' 
 }
</code></pre>