-
Notifications
You must be signed in to change notification settings - Fork 8
/
utils.js
41 lines (37 loc) · 1.04 KB
/
utils.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
29
30
31
32
33
34
35
36
37
38
39
40
41
import { env } from 'process';
import { readFileSync } from 'fs';
export function loadSettings(){
try{
return JSON.parse(readFileSync('settings.json'));
}
catch(e){
return {
'TOKEN': env.TOKEN,
'PIPES': JSON.parse(env.PIPES),
'ADD_DEFAULT_HEADER': env.ADD_DEFAULT_HEADER !== "false",
'CUSTOM_HEADER': env.CUSTOM_HEADER
};
}
}
export function parseContacts(vCard){
try{
const nameRegex = /FN:(.+)/
const phoneRegex = /TEL;waid=(\d+):/;
const altPhoneRegex = /TEL:\+([\d ]+)/
let firstName = vCard.match(nameRegex)[1];
let phoneNo = vCard.match(phoneRegex);
if(phoneNo === null)
// If contact has no whatsapp
phoneNo = vCard.match(altPhoneRegex)[1].replace(/ /g, '');
else
phoneNo = phoneNo[1];
return{
"firstName": firstName,
"phoneNo": phoneNo
}
}
catch(err){
console.log(err);
return null;
}
}