-
Notifications
You must be signed in to change notification settings - Fork 18
/
kurir.js
28 lines (23 loc) · 807 Bytes
/
kurir.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const Config = require('./config.json')
const fetch = require('node-fetch')
class Kurir {
constructor (clientWa) {
this.clientWa = clientWa
}
async kirim (url, msg) {
let number = msg.from.split('@')[0];
let urlWebService = Config.webserviceUrl + url + '?sender=' + number + '&message=' + encodeURIComponent(msg.body);
console.log(urlWebService)
fetch(urlWebService).then(response => response.json()).then(pesan => this.clientWa.sendMessage(msg.from, pesan['pesan']) ).catch(error => console.log(error))
}
saveInbox(msg){
this.kirim('receive',msg);
}
register(msg){
this.kirim('register',msg);
}
chat(msg){
this.kirim('chat',msg);
}
}
module.exports = Kurir;