Add clear message example

This commit is contained in:
Nur Muhammad
2021-03-31 09:23:26 +08:00
parent 615d5b31a1
commit 4bfd9118fc

43
app.js
View File

@@ -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() {
console.log('App running on *: ' + port);
});