mirror of
https://github.com/cheveguerra/whatsapp-api-tutorial.git
synced 2026-04-18 03:39:27 +00:00
Add clear message example
This commit is contained in:
43
app.js
43
app.js
@@ -266,6 +266,49 @@ app.post('/send-group-message', [
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Clearing message on spesific chat
|
||||||
|
app.post('/clear-message', [
|
||||||
|
body('number').notEmpty(),
|
||||||
|
], async (req, res) => {
|
||||||
|
const errors = validationResult(req).formatWith(({
|
||||||
|
msg
|
||||||
|
}) => {
|
||||||
|
return msg;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!errors.isEmpty()) {
|
||||||
|
return res.status(422).json({
|
||||||
|
status: false,
|
||||||
|
message: errors.mapped()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const number = phoneNumberFormatter(req.body.number);
|
||||||
|
|
||||||
|
const isRegisteredNumber = await checkRegisteredNumber(number);
|
||||||
|
|
||||||
|
if (!isRegisteredNumber) {
|
||||||
|
return res.status(422).json({
|
||||||
|
status: false,
|
||||||
|
message: 'The number is not registered'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const chat = await client.getChatById(number);
|
||||||
|
|
||||||
|
chat.clearMessages().then(status => {
|
||||||
|
res.status(200).json({
|
||||||
|
status: true,
|
||||||
|
response: status
|
||||||
|
});
|
||||||
|
}).catch(err => {
|
||||||
|
res.status(500).json({
|
||||||
|
status: false,
|
||||||
|
response: err
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
server.listen(port, function() {
|
server.listen(port, function() {
|
||||||
console.log('App running on *: ' + port);
|
console.log('App running on *: ' + port);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user