Skip to content

Commit

Permalink
feat: Created community functions
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta authored and edgardmessias committed Jan 28, 2023
1 parent 77a91fe commit d52137b
Show file tree
Hide file tree
Showing 11 changed files with 309 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/community/functions/create.ts
@@ -0,0 +1,41 @@
/*!
* 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 '../../whatsapp';
import { sendCreateCommunity } from '../../whatsapp/functions';
import { sendLinkSubgroups } from './sendLinkSubgroups';

/**
* Create community
*
* @example
* ```javascript
* await WPP.community.create('Name for community', 'description for community', ['120363048977606406@g.us', ''120363048977606406@g.us']);
* ```
*/
export async function create(
name: string,
desc: string,
subGroupsIds: Wid[]
): Promise<any> {
const community = await sendCreateCommunity({
name: name,
desc: desc,
closed: false,
});
console.log(community);
return await sendLinkSubgroups(community.wid, subGroupsIds);
}
31 changes: 31 additions & 0 deletions src/community/functions/getCommunityParticipants.ts
@@ -0,0 +1,31 @@
/*!
* Copyright 2023 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 '../../whatsapp';
import { getCommunityParticipants as GetCommunityParticipants } from '../../whatsapp/functions';

/**
* Add groups do tommunity
*
* @example
* ```javascript
* await WPP.community.getCommunityParticipants('<>@g.us');
* ```
*/

export async function getCommunityParticipants(communityId: Wid): Promise<any> {
return GetCommunityParticipants(communityId);
}
20 changes: 20 additions & 0 deletions src/community/functions/index.ts
@@ -0,0 +1,20 @@
/*!
* Copyright 2023 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.
*/

export { create } from './create';
export { getCommunityParticipants } from './getCommunityParticipants';
export { sendLinkSubgroups } from './sendLinkSubgroups';
export { sendUnlinkSubgroups } from './sendUnlinkSubgroups';
37 changes: 37 additions & 0 deletions src/community/functions/sendLinkSubgroups.ts
@@ -0,0 +1,37 @@
/*!
* Copyright 2023 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 '../../whatsapp';
import { sendLinkSubgroups as SendLinkSubgroups } from '../../whatsapp/functions';

/**
* Add groups do tommunity
*
* @example
* ```javascript
* await WPP.community.sendLinkSubgroups('<>@g.us', ['<>@g.us', '<>@g.us']);
* ```
*/

export async function sendLinkSubgroups(
parentGroupId: Wid,
subgroupIds: Wid | Wid[]
): Promise<any> {
return SendLinkSubgroups({
parentGroupId: parentGroupId,
subgroupIds: subgroupIds,
});
}
37 changes: 37 additions & 0 deletions src/community/functions/sendUnlinkSubgroups.ts
@@ -0,0 +1,37 @@
/*!
* Copyright 2023 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 '../../whatsapp';
import { sendUnlinkSubgroups as SendUnlinkSubgroups } from '../../whatsapp/functions';

/**
* Remove groups from community
*
* @example
* ```javascript
* await WPP.community.sendUnlinkSubgroups('<>@g.us', ['<>@g.us', '<>@g.us']);
* ```
*/

export async function sendUnlinkSubgroups(
parentGroupId: Wid,
subgroupIds: Wid | Wid[]
): Promise<any> {
return SendUnlinkSubgroups({
parentGroupId: parentGroupId,
subgroupIds: subgroupIds,
});
}
17 changes: 17 additions & 0 deletions src/community/index.ts
@@ -0,0 +1,17 @@
/*!
* Copyright 2023 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.
*/

export * from './functions';
1 change: 1 addition & 0 deletions src/index.ts
Expand Up @@ -34,6 +34,7 @@ export * as chat from './chat';
export * as conn from './conn';
export * as contact from './contact';
export * as ev from './eventEmitter';
export * as community from './community';
export * as group from './group';
export * as labels from './labels';
export * as profile from './profile';
Expand Down
33 changes: 33 additions & 0 deletions src/whatsapp/functions/getCommunityParticipants.ts
@@ -0,0 +1,33 @@
/*!
* Copyright 2023 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';
import { Wid } from '../misc';

/**
* @whatsapp 673427
*/
export declare function getCommunityParticipants(
communityId: Wid
): Promise<any>;

exportModule(
exports,
{
getCommunityParticipants: 'getCommunityParticipants',
},
(m) => m.getCommunityParticipants
);
18 changes: 18 additions & 0 deletions src/whatsapp/functions/groupParticipants.ts
Expand Up @@ -53,18 +53,36 @@ export declare function demoteParticipants(
participants: ParticipantModel[]
): Promise<void>;

/** @whatsapp 688460
*/
export declare function promoteCommunityParticipants(
group: ChatModel,
participants: ParticipantModel[]
): Promise<void>;

/** @whatsapp 688460
*/
export declare function demoteCommunityParticipants(
group: ChatModel,
participants: ParticipantModel[]
): Promise<void>;

exportModule(
exports,
{
addParticipants: 'addParticipants',
removeParticipants: 'removeParticipants',
promoteCommunityParticipants: 'promoteCommunityParticipants',
promoteParticipants: 'promoteParticipants',
demoteCommunityParticipants: 'demoteCommunityParticipants',
demoteParticipants: 'demoteParticipants',
},
(m) =>
m.addParticipants &&
m.removeParticipants &&
m.promoteCommunityParticipants &&
m.promoteParticipants &&
m.demoteCommunityParticipants &&
m.demoteParticipants &&
!m.updateParticipants
);
2 changes: 2 additions & 0 deletions src/whatsapp/functions/index.ts
Expand Up @@ -32,6 +32,7 @@ export * from './findChat';
export * from './findFirstWebLink';
export * from './generateVideoThumbsAndDuration';
export * from './genMinimalLinkPreview';
export * from './getCommunityParticipants';
export * from './getFanOutList';
export * from './getGroupSenderKeyList';
export * from './getGroupSizeLimit';
Expand Down Expand Up @@ -61,6 +62,7 @@ export * from './randomId';
export * from './resetGroupInviteCode';
export * from './sendCallSignalingMsg';
export * from './sendClear';
export * from './sendCreateCommunity';
export * from './sendCreateGroup';
export * from './sendDelete';
export * from './sendExitGroup';
Expand Down
72 changes: 72 additions & 0 deletions src/whatsapp/functions/sendCreateCommunity.ts
@@ -0,0 +1,72 @@
/*!
* Copyright 2023 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';
import { Wid } from '../misc';

/**
* @whatsapp 650348
*/
export declare function sendCreateCommunity(e: {
name: string;
desc: string;
closed: boolean;
}): Promise<any>;

/**
* @whatsapp 650348
*/
export declare function sendDeactivateCommunity(e: {
parentGroupId: Wid;
}): Promise<any>;

/**
* @whatsapp 650348
*/
export declare function sendLinkSubgroups(e: {
parentGroupId: Wid;
subgroupIds: Wid | Wid[];
}): Promise<any>;

/**
* @whatsapp 650348
*/
export declare function sendRemoveFromCommunityCommunity(e: any): Promise<any>;

/**
* @whatsapp 650348
*/
export declare function sendUnlinkSubgroups(e: {
parentGroupId: Wid;
subgroupIds: Wid | Wid[];
}): Promise<any>;

exportModule(
exports,
{
sendCreateCommunity: 'sendCreateCommunity',
sendDeactivateCommunity: 'sendDeactivateCommunity',
sendLinkSubgroups: 'sendLinkSubgroups',
sendRemoveFromCommunityCommunity: 'sendRemoveFromCommunityCommunity',
sendUnlinkSubgroups: 'sendUnlinkSubgroups',
},
(m) =>
m.sendCreateCommunity &&
m.sendDeactivateCommunity &&
m.sendLinkSubgroups &&
m.sendRemoveFromCommunityCommunity &&
m.sendUnlinkSubgroups
);

0 comments on commit d52137b

Please sign in to comment.