Skip to content

Commit

Permalink
Allow checkNumberStatus to verify WhatsApp group ID
Browse files Browse the repository at this point in the history
  • Loading branch information
limshengli committed Sep 11, 2023
1 parent f692f0e commit 71478a4
Showing 1 changed file with 38 additions and 13 deletions.
51 changes: 38 additions & 13 deletions src/lib/wapi/functions/check-number-status.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
/* eslint-disable no-undef */
export async function checkNumberStatus(id, conn = false) {
try {
const err = { error: 404 };
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') {
Expand All @@ -27,13 +23,42 @@ export async function checkNumberStatus(id, conn = false) {
throw err;
}
}

const lid = await WAPI.getChat(id);
if (lid) {
return await Store.checkNumber
.queryWidExists(lid.id)
if (id.endsWith('@g.us')) {
return await WPP.group
.ensureGroup(lid.id)
.then((result) => {
if (!!result && typeof result === 'object') {
const data = {
status: 200,
numberExists: true,
id: result.id,
};
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
});
});;
}

return await WPP.contact
.queryExists(lid.id)
.then((result) => {
if (!!result && typeof result === 'object') {
if (typeof result === 'object') {
const data = {
status: 200,
numberExists: true,
Expand Down

0 comments on commit 71478a4

Please sign in to comment.