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("Manager@test.co.uk",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("r.hershey@onemotion.co.uk",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:

    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.