Skip to content

Commit bb86639

Browse files
gustavorafaeldevcrazycodezombie
authored andcommitted
group: add methods for changing description, join approval mode and member add mode
1 parent 1b22e23 commit bb86639

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

group.go

+52
Original file line numberDiff line numberDiff line change
@@ -864,3 +864,55 @@ func (cli *Client) parseGroupNotification(node *waBinary.Node) (interface{}, err
864864
return groupChange, nil
865865
}
866866
}
867+
868+
// SetGroupJoinApprovalMode sets the group join approval mode to 'on' or 'off'.
869+
func (cli *Client) SetGroupJoinApprovalMode(jid types.JID, mode bool) error {
870+
modeStr := "off"
871+
if mode {
872+
modeStr = "on"
873+
}
874+
875+
content := waBinary.Node{
876+
Tag: "membership_approval_mode",
877+
Content: []waBinary.Node{
878+
{
879+
Tag: "group_join",
880+
Attrs: waBinary.Attrs{"state": modeStr},
881+
},
882+
},
883+
}
884+
885+
_, err := cli.sendGroupIQ(context.TODO(), iqSet, jid, content)
886+
return err
887+
}
888+
889+
// SetGroupMemberAddMode sets the group member add mode to 'admin_add' or 'all_member_add'.
890+
func (cli *Client) SetGroupMemberAddMode(jid types.JID, mode types.GroupMemberAddMode) error {
891+
if mode != types.GroupMemberAddModeAdmin && mode != types.GroupMemberAddModeAllMember {
892+
return errors.New("invalid mode, must be 'admin_add' or 'all_member_add'")
893+
}
894+
895+
content := waBinary.Node{
896+
Tag: "member_add_mode",
897+
Content: []byte(mode),
898+
}
899+
900+
_, err := cli.sendGroupIQ(context.TODO(), iqSet, jid, content)
901+
return err
902+
}
903+
904+
// SetGroupDescription updates the group description.
905+
func (cli *Client) SetGroupDescription(jid types.JID, description string) error {
906+
content := waBinary.Node{
907+
Tag: "description",
908+
Content: []waBinary.Node{
909+
{
910+
Tag: "body",
911+
Content: []byte(description),
912+
},
913+
},
914+
}
915+
916+
_, err := cli.sendGroupIQ(context.TODO(), iqSet, jid, content)
917+
return err
918+
}

types/group.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import (
1313
type GroupMemberAddMode string
1414

1515
const (
16-
GroupMemberAddModeAdmin GroupMemberAddMode = "admin_add"
16+
GroupMemberAddModeAdmin GroupMemberAddMode = "admin_add"
17+
GroupMemberAddModeAllMember GroupMemberAddMode = "all_member_add"
1718
)
1819

1920
// GroupInfo contains basic information about a group chat on WhatsApp.

0 commit comments

Comments
 (0)