forked from orkestral/venom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-number-status.js
74 lines (72 loc) · 1.79 KB
/
check-number-status.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
export async function checkNumberStatus(id, conn = false) {
try {
const err = { error: 404 };
const connection =
window.Store &&
window.Store.State &&
window.Store.State.Socket &&
window.Store.State.Socket.state
? window.Store.State.Socket.state
: '';
const checkType = WAPI.sendCheckType(id);
if (!!checkType && checkType.status === 404) {
Object.assign(err, {
text: checkType.text,
numberExists: null
});
throw err;
}
if (conn === true) {
if (connection !== 'CONNECTED') {
Object.assign(err, {
text: 'No connection with WhatsApp',
connection: connection,
numberExists: null
});
throw err;
}
}
const lid = await WAPI.getChat(id);
if (lid) {
return await Store.checkNumber
.queryWidExists(lid.id)
.then((result) => {
if (!!result && typeof result === 'object') {
const data = {
status: 200,
numberExists: true,
id: result.wid
};
return data;
}
throw Object.assign(err, {
connection: connection,
numberExists: false,
text: `The number does not exist`
});
})
.catch((err) => {
if (err.text) {
throw err;
}
throw Object.assign(err, {
connection: connection,
numberExists: false,
text: err
});
});
} else {
throw Object.assign(err, {
connection: connection,
numberExists: false
});
}
} catch (e) {
return {
status: e.error,
text: e.text,
numberExists: e.numberExists,
connection: e.connection
};
}
}