From 2f2c1dc25ee679753d95306523ac3c77cf14b756 Mon Sep 17 00:00:00 2001 From: Lucas Fochesatto Date: Sun, 7 Sep 2025 08:08:34 -0300 Subject: [PATCH] Feat: Allow creating, linking, and unlinking groups from a community (#1729) * feat: create group inside a community * feat: link and unlink groups to a community --- src/Socket/communities.ts | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/Socket/communities.ts b/src/Socket/communities.ts index 38b8a7e5..72009285 100644 --- a/src/Socket/communities.ts +++ b/src/Socket/communities.ts @@ -149,6 +149,26 @@ export const makeCommunitiesSocket = (config: SocketConfig) => { return await parseGroupResult(result) }, + communityCreateGroup: async (subject: string, participants: string[], parentCommunityJid: string) => { + const key = generateMessageIDV2() + const result = await communityQuery('@g.us', 'set', [ + { + tag: 'create', + attrs: { + subject, + key + }, + content: [ + ...participants.map(jid => ({ + tag: 'participant', + attrs: { jid } + })), + { tag: 'linked_parent', attrs: { jid: parentCommunityJid } } + ] + } + ]) + return await parseGroupResult(result) + }, communityLeave: async (id: string) => { await communityQuery('@g.us', 'set', [ { @@ -167,6 +187,30 @@ export const makeCommunitiesSocket = (config: SocketConfig) => { } ]) }, + communityLinkGroup: async (groupJid: string, parentCommunityJid: string) => { + await communityQuery(parentCommunityJid, 'set', [ + { + tag: 'links', + attrs: {}, + content: [ + { + tag: 'link', + attrs: { link_type: 'sub_group' }, + content: [{ tag: 'group', attrs: { jid: groupJid } }] + } + ] + } + ]) + }, + communityUnlinkGroup: async (groupJid: string, parentCommunityJid: string) => { + await communityQuery(parentCommunityJid, 'set', [ + { + tag: 'unlink', + attrs: { unlink_type: 'sub_group' }, + content: [{ tag: 'group', attrs: { jid: groupJid } }] + } + ]) + }, communityRequestParticipantsList: async (jid: string) => { const result = await communityQuery(jid, 'get', [ {