diff --git a/src/community/functions/create.ts b/src/community/functions/create.ts new file mode 100644 index 0000000000..368a0ba6bd --- /dev/null +++ b/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 { + const community = await sendCreateCommunity({ + name: name, + desc: desc, + closed: false, + }); + console.log(community); + return await sendLinkSubgroups(community.wid, subGroupsIds); +} diff --git a/src/community/functions/getCommunityParticipants.ts b/src/community/functions/getCommunityParticipants.ts new file mode 100644 index 0000000000..96725665a1 --- /dev/null +++ b/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 { + return GetCommunityParticipants(communityId); +} diff --git a/src/community/functions/index.ts b/src/community/functions/index.ts new file mode 100644 index 0000000000..a807e50054 --- /dev/null +++ b/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'; diff --git a/src/community/functions/sendLinkSubgroups.ts b/src/community/functions/sendLinkSubgroups.ts new file mode 100644 index 0000000000..dac813ce53 --- /dev/null +++ b/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 { + return SendLinkSubgroups({ + parentGroupId: parentGroupId, + subgroupIds: subgroupIds, + }); +} diff --git a/src/community/functions/sendUnlinkSubgroups.ts b/src/community/functions/sendUnlinkSubgroups.ts new file mode 100644 index 0000000000..187acbd949 --- /dev/null +++ b/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 { + return SendUnlinkSubgroups({ + parentGroupId: parentGroupId, + subgroupIds: subgroupIds, + }); +} diff --git a/src/community/index.ts b/src/community/index.ts new file mode 100644 index 0000000000..15b554f601 --- /dev/null +++ b/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'; diff --git a/src/index.ts b/src/index.ts index ed15811368..6c782f7d17 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'; diff --git a/src/whatsapp/functions/getCommunityParticipants.ts b/src/whatsapp/functions/getCommunityParticipants.ts new file mode 100644 index 0000000000..80532f9f5d --- /dev/null +++ b/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; + +exportModule( + exports, + { + getCommunityParticipants: 'getCommunityParticipants', + }, + (m) => m.getCommunityParticipants +); diff --git a/src/whatsapp/functions/groupParticipants.ts b/src/whatsapp/functions/groupParticipants.ts index 6aed03c407..1e8ac29e06 100644 --- a/src/whatsapp/functions/groupParticipants.ts +++ b/src/whatsapp/functions/groupParticipants.ts @@ -53,18 +53,36 @@ export declare function demoteParticipants( participants: ParticipantModel[] ): Promise; +/** @whatsapp 688460 + */ +export declare function promoteCommunityParticipants( + group: ChatModel, + participants: ParticipantModel[] +): Promise; + +/** @whatsapp 688460 + */ +export declare function demoteCommunityParticipants( + group: ChatModel, + participants: ParticipantModel[] +): Promise; + 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 ); diff --git a/src/whatsapp/functions/index.ts b/src/whatsapp/functions/index.ts index 1ad2bd87ad..e23e2d4a17 100644 --- a/src/whatsapp/functions/index.ts +++ b/src/whatsapp/functions/index.ts @@ -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'; @@ -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'; diff --git a/src/whatsapp/functions/sendCreateCommunity.ts b/src/whatsapp/functions/sendCreateCommunity.ts new file mode 100644 index 0000000000..79519f9eb4 --- /dev/null +++ b/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; + +/** + * @whatsapp 650348 + */ +export declare function sendDeactivateCommunity(e: { + parentGroupId: Wid; +}): Promise; + +/** + * @whatsapp 650348 + */ +export declare function sendLinkSubgroups(e: { + parentGroupId: Wid; + subgroupIds: Wid | Wid[]; +}): Promise; + +/** + * @whatsapp 650348 + */ +export declare function sendRemoveFromCommunityCommunity(e: any): Promise; + +/** + * @whatsapp 650348 + */ +export declare function sendUnlinkSubgroups(e: { + parentGroupId: Wid; + subgroupIds: Wid | Wid[]; +}): Promise; + +exportModule( + exports, + { + sendCreateCommunity: 'sendCreateCommunity', + sendDeactivateCommunity: 'sendDeactivateCommunity', + sendLinkSubgroups: 'sendLinkSubgroups', + sendRemoveFromCommunityCommunity: 'sendRemoveFromCommunityCommunity', + sendUnlinkSubgroups: 'sendUnlinkSubgroups', + }, + (m) => + m.sendCreateCommunity && + m.sendDeactivateCommunity && + m.sendLinkSubgroups && + m.sendRemoveFromCommunityCommunity && + m.sendUnlinkSubgroups +);