Search code examples
google-apps-scriptgoogle-groupsgoogle-groups-apigoogle-groups-settings

How to set Google Groups moderation and posting permissions


I have got the below script working for me.... (Script auto creates a google group with data from a spreadsheet that is auto populated with data from a form...)

function onFormSubmit() {
 var sheet = SpreadsheetApp.openById("17KZXpWHipISZSqgD9w255VrirzITrks0fLaBpXp7Ybk")
 var email = sheet.getRange("B"+sheet.getLastRow()).getValue()
 var name = sheet.getRange("C"+sheet.getLastRow()).getValue()
 var user = sheet.getRange("AH"+sheet.getLastRow()).getValue()
 try{
   AdminDirectory.Groups.insert(
     {
       "email": email,
       "name": name,
     }
   )
   AdminDirectory.Members.insert(
     {
       "email": user,
       "role": "OWNER",
     }
     , email)
   GmailApp.sendEmail("[email protected]",email + "  Group creation | Success", " address has been created for " + name)
 } catch(e){}
}

Could someone help me finish it as the remaining steps that i cannot get working are:

Set Group Moderation settings to: Skip Moderation queue and Post messages to group

Set Posting permissions to: public

function onFormSubmit() {
 var sheet = SpreadsheetApp.openById("17KZXpWHipISZSqgD9w255VrirzITrks0fLaBpXp7Ybk")
 var email = sheet.getRange("B"+sheet.getLastRow()).getValue()
 var name = sheet.getRange("C"+sheet.getLastRow()).getValue()
 var user = sheet.getRange("AH"+sheet.getLastRow()).getValue()
 try{
   AdminDirectory.Groups.insert(
     {
       "email": email,
       "name": name,
     }
   )
   AdminDirectory.Members.insert(
     {
       "email": user,
       "role": "OWNER",
     }
    )
   AdminDirectory.Groups.update(
     {
       "whoCanJoin": "CAN_REQUEST_TO_JOIN",
       "whoCanViewMembership": "ALL_IN_DOMAIN_CAN_VIEW",
       "whoCanViewGroup": "ALL_IN_DOMAIN_CAN_VIEW",
       "whoCanInvite": "ALL_MANAGERS_CAN_INVITE",
       "allowExternalMembers": "false",
       "whoCanPostMessage": "PUBLIC",
     }
    )
   AdminDirectory.Groups.moderation(
     {
      "Spammessages": "Skip_the_moderation_queue_and_post_to_the_group"
     }
     , email)
   GmailApp.sendEmail("[email protected]",email + "  Group creation | Success", " address has been created for " + name)
 } catch(e){}
}

I tried this but either I'm tired or I'm missing something silly...?


Solution

  • Based from this documentation, possible values for whoCanPostMessage property are:

    • ALL_IN_DOMAIN_CAN_POST — Anyone in the account can post a message.
    • ALL_MANAGERS_CAN_POST — Managers, including group owners, can post messages.
    • ALL_MEMBERS_CAN_POST — Any group member can post a message.
    • ANYONE_CAN_POST — Any Google Apps user outside your account can access your Google Groups service and post a message.
      Tip: When the whoCanPostMessage is set to ANYONE_CAN_POST, we recommend the messageModerationLevel property be set to MODERATE_NON_MEMBERS to protect the group from possible spam.
    • NONE_CAN_POST — The group is disabled and archived. No one can post a message to this group.
      • When archiveOnly value="false", updating the whoCanPostMessage property to NONE_CAN_POST, results in an error.
      • If archiveOnly is reverted from "true" to "false", the whoCanPostMessages property is set to ALL_MANAGERS_CAN_POST.

    Also, I don't see any references regarding AdminDirectory.Groups.moderation and Spammessages. You may want to check the documentation given and see if messageModerationLevel and spamModerationLevel help.