-
-
Save fachryansyah/802c809e2b16b18338ebb562f76f9a79 to your computer and use it in GitHub Desktop.
BotWA.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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