Skip to content

Commit

Permalink
fix: Fixed WPP.blocklist.blockContact function for WhatsApp >= 2.2323…
Browse files Browse the repository at this point in the history
….4 (fix #1210)
  • Loading branch information
edgardmessias committed Jul 5, 2023
1 parent 620d6da commit 5e8c31e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/blocklist/functions/blockContact.ts
Expand Up @@ -14,8 +14,11 @@
* limitations under the License.
*/

import { compare } from 'compare-versions';

import { assertWid } from '../../assert';
import { ContactModel, ContactStore, Wid } from '../../whatsapp';
import { SANITIZED_VERSION_STR } from '../../whatsapp/contants';
import * as wa_functions from '../../whatsapp/functions';
import { BlocklistResult } from '../types';

Expand All @@ -26,7 +29,15 @@ export async function blockContact(

const contact = ContactStore.get(wid) || new ContactModel({ id: wid });

await wa_functions.blockContact(contact);
if (compare(SANITIZED_VERSION_STR, '2.2323.4', '>=')) {
await wa_functions.blockContact({
contact,
blockEntryPoint: 'block_list',
bizOptOutArgs: null,
});
} else {
await wa_functions.blockContact(contact);
}

return {
wid,
Expand Down
30 changes: 30 additions & 0 deletions src/whatsapp/contants/SANITIZED_VERSION_STR.ts
@@ -0,0 +1,30 @@
/*!
* Copyright 2021 WPPConnect Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { exportModule } from '../exportModule';

/**
* @whatsapp 831914
*/
export declare const SANITIZED_VERSION_STR: string;

exportModule(
exports,
{
SANITIZED_VERSION_STR: ['SANITIZED_VERSION_STR'],
},
(m) => m.SANITIZED_VERSION_STR
);
1 change: 1 addition & 0 deletions src/whatsapp/contants/index.ts
Expand Up @@ -15,3 +15,4 @@
*/

export * from './DROP_ATTR';
export * from './SANITIZED_VERSION_STR';
10 changes: 9 additions & 1 deletion src/whatsapp/functions/blockContact.ts
Expand Up @@ -21,7 +21,15 @@ import { ContactModel } from '../models';
* @whatsapp 780140 >= 2.2222.8
* @whatsapp 48826 >= 2.2228.4
*/
export declare function blockContact(contact: ContactModel): Promise<void>;
export declare function blockContact(
contact:
| ContactModel
| {
contact: ContactModel;
blockEntryPoint: string;
bizOptOutArgs: any | null;
}
): Promise<void>;

/** @whatsapp 80140
* @whatsapp 780140 >= 2.2222.8
Expand Down

0 comments on commit 5e8c31e

Please sign in to comment.