mirror of
https://github.com/cheveguerra/whatsapp-api-tutorial.git
synced 2026-04-17 19:36:59 +00:00
Add new middleware to handle form-data request
This commit is contained in:
@@ -5,6 +5,7 @@ const qrcode = require('qrcode');
|
||||
const http = require('http');
|
||||
const fs = require('fs');
|
||||
const { phoneNumberFormatter } = require('./helpers/formatter');
|
||||
const fileUpload = require('express-fileupload');
|
||||
const axios = require('axios');
|
||||
const port = process.env.PORT || 8000;
|
||||
|
||||
@@ -17,6 +18,18 @@ app.use(express.urlencoded({
|
||||
extended: true
|
||||
}));
|
||||
|
||||
/**
|
||||
* BASED ON MANY QUESTIONS
|
||||
* Actually ready mentioned on the tutorials
|
||||
*
|
||||
* The two middlewares above only handle for data json & urlencode (x-www-form-urlencoded)
|
||||
* So, we need to add extra middleware to handle form-data
|
||||
* Here we can use express-fileupload
|
||||
*/
|
||||
app.use(fileUpload({
|
||||
debug: false
|
||||
}));
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.sendFile('index-multiple-account.html', {
|
||||
root: __dirname
|
||||
@@ -165,6 +178,8 @@ io.on('connection', function(socket) {
|
||||
|
||||
// Send message
|
||||
app.post('/send-message', async (req, res) => {
|
||||
console.log(req);
|
||||
|
||||
const sender = req.body.sender;
|
||||
const number = phoneNumberFormatter(req.body.number);
|
||||
const message = req.body.message;
|
||||
|
||||
Reference in New Issue
Block a user