0
  • I'm building a whatsapp chatbot wherein I have to scrape the content of a pdf sent by the user to the bot.
  • Whatsapp automatically downloads the file and uploads it to its the cloud and we get the url to access the pdf (but only with a USER-ACCESS-TOKEN)
  • We can download that pdf using a get request to the url and it returns a 'response' object wherein, 'response.data' has the content of the pdf.
  • But I'm getting the output in this format and I need to convert it to the text/binary format.

Here's the output image :

Here's the code :

const express = require("express");
const app = express();
const pdfParse = require("pdf-parse");


var axios = require('axios');
var data = '';

var config = {
  method: 'get',
  url: 'https://lookaside.fbsbx.com/whatsapp_business/attachments/?mid=915538742783704&ext=1675024946&hash=ATukNLxGTZLE0ouRUk7BehJGM57FuckuOi2fMwBGE4eHdA',
  headers: { 
    'Authorization': `Bearer ${process.env.TOKEN}`
  },
  data : data
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});




const port = 8000;

app.listen(port,()=>{
    console.log(`\n\nApp is running at port ${port}\n\n`);
})

PS : Get request through Postman is giving the output as preview to the pdf with an option to download.

0 Answers0