forked from vynect/venom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-number-status.js
More file actions
82 lines (79 loc) · 1.97 KB
/
Copy pathcheck-number-status.js
File metadata and controls
82 lines (79 loc) · 1.97 KB
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
75
76
77
78
79
80
81
82
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
: undefined;
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;
}
}
if (WAPI.isBeta()) {
return await Store.checkNumberBeta
.queryExists(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
});
});
}
const result = await Store.checkNumber.queryExist(id);
if (result.status === 200) {
return {
status: result.status,
numberExists: true,
id: result.jid
};
}
return {
status: result.status,
numberExists: false,
text: `The number does not exist`
};
} catch (e) {
return {
status: e.error,
text: e.text,
numberExists: e.numberExists,
connection: e.connection
};
}
}