Skip to content

Commit

Permalink
feat: Added option to create a subgroup for community
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Jul 7, 2023
1 parent 590c9ce commit 445bc79
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
15 changes: 13 additions & 2 deletions src/group/functions/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@ import * as wa_functions from '../../whatsapp/functions';
* // How to send a custom invite link
* const link = 'https://chat.whatsapp.com/' + result['number@c.us'].invite_code;
* console.log(link);
*
* // Create a Subgroup for a community
* const result = await WPP.group.create('Test Group', ['number@c.us'], 'communit@g.us');
* ```
*
* @category Group
*/
export async function create(
groupName: string,
participantsIds: (string | Wid) | (string | Wid)[]
participantsIds: (string | Wid) | (string | Wid)[],
parentGroup: string | Wid
): Promise<{
gid: Wid;
participants: {
Expand Down Expand Up @@ -99,7 +103,14 @@ export async function create(
wids.push(info.wid);
}

const result = await wa_functions.sendCreateGroup(groupName, wids);
const parentWid = parentGroup ? assertWid(parentGroup) : undefined;

const result = await wa_functions.sendCreateGroup(
groupName,
wids,
undefined,
parentWid
);

if (result.gid) {
const chatGroup = await Chat.find(result.gid);
Expand Down
2 changes: 1 addition & 1 deletion src/whatsapp/functions/createGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export declare function createGroup(
groupName: string,
participants: Wid[],
ephemeral?: number,
dogfooding?: boolean
parentGroup?: Wid
): Promise<{
wid: Wid;
participants: {
Expand Down
6 changes: 3 additions & 3 deletions src/whatsapp/functions/sendCreateGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export declare function sendCreateGroup(
groupName: string,
participants: Wid[],
ephemeral?: number,
dogfooding?: boolean
parentGroup?: Wid
): Promise<{
gid: Wid;
participants: (
Expand Down Expand Up @@ -60,13 +60,13 @@ webpack.injectFallbackModule('sendCreateGroup', {
groupName: string,
participants: Wid[],
ephemeral?: number,
dogfooding?: boolean
parentGroup?: Wid
) => {
return await createGroup(
groupName,
participants,
ephemeral,
dogfooding
parentGroup
).then((e) => ({
gid: e.wid,
participants: e.participants.map((e) => ({
Expand Down

0 comments on commit 445bc79

Please sign in to comment.