Skip to content

Instantly share code, notes, and snippets.

@fachryansyah
Last active November 10, 2021 14:32
Show Gist options
  • Save fachryansyah/802c809e2b16b18338ebb562f76f9a79 to your computer and use it in GitHub Desktop.
Save fachryansyah/802c809e2b16b18338ebb562f76f9a79 to your computer and use it in GitHub Desktop.
BotWA.js
const express = require('express')
const axios = require('axios');
const bodyParser = require('body-parser')
const app = express()
const port = 5000;
app.use(bodyParser.json())
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.post('/webhook', async (req, res) => {
console.log(req.body);
const msg = req.body.message;
const format = msg.split(' ')[0];
const data = msg.split(' ')[1];
let response = '';
switch (format.toLowerCase()) {
case "telpon":
response = `Nomor telpon anda adalah: ${data}`
break;
case "email":
response = `Email anda adalah: ${data}`
default:
response = 'Maaf format pesan tidak dikenal';
break;
}
try {
await axios.post('http://103.107.205.14:4000/api/v1/send-text', {
device: 1,
phone: req.body.from,
message: response
}, {
headers: {
'Authorization': 'Bearer <apikey>'
}
});
return res.send('oke');
} catch (e) {
console.log(e);
return res.send('oke');
}
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment