Skip to content

Commit

Permalink
fix: Fixed WPP.group.create function for WhatsApp >= 2.2301.5
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Jan 11, 2023
1 parent d87367b commit aad5d3b
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/whatsapp/functions/createGroup.ts
@@ -0,0 +1,44 @@
/*!
* 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 { Wid } from '..';
import { exportModule } from '../exportModule';

/**
* @whatsapp 247355
*/
export declare function createGroup(
groupName: string,
participants: Wid[],
ephemeral?: number,
dogfooding?: boolean
): Promise<{
wid: Wid;
participants: {
wid: Wid;
error: string;
invite_code: string | null;
invite_code_exp: string | null;
}[];
}>;

exportModule(
exports,
{
createGroup: 'createGroup',
},
(m) => m.createGroup && !m.sendForNeededAddRequest
);
1 change: 1 addition & 0 deletions src/whatsapp/functions/index.ts
Expand Up @@ -20,6 +20,7 @@ export * from './calculateFilehashFromBlob';
export * from './canEditMessage';
export * from './canReplyMsg';
export * from './collections';
export * from './createGroup';
export * from './createMsgProtobuf';
export * from './createOrUpdateReactions';
export * from './editBusinessProfile';
Expand Down
29 changes: 29 additions & 0 deletions src/whatsapp/functions/sendCreateGroup.ts
Expand Up @@ -14,8 +14,10 @@
* limitations under the License.
*/

import * as webpack from '../../webpack';
import { Wid } from '..';
import { exportModule } from '../exportModule';
import { createGroup } from './createGroup';

/** @whatsapp 79583 */
export declare function sendCreateGroup(
Expand Down Expand Up @@ -49,3 +51,30 @@ exportModule(
},
(m) => m.sendCreateGroup
);

/**
* @whatsapp >= 2.2301.5
*/
webpack.injectFallbackModule('sendCreateGroup', {
sendCreateGroup: async (
groupName: string,
participants: Wid[],
ephemeral?: number,
dogfooding?: boolean
) => {
return await createGroup(
groupName,
participants,
ephemeral,
dogfooding
).then((e) => ({
gid: e.wid,
participants: e.participants.map((e) => ({
userWid: e.wid,
code: null != e.error ? e.error.toString() : '200',
invite_code: e.invite_code,
invite_code_exp: e.invite_code_exp,
})),
}));
},
});

0 comments on commit aad5d3b

Please sign in to comment.