Skip to content

Instantly share code, notes, and snippets.

@christophstrasen
Created October 12, 2018 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christophstrasen/65461f921b5e8a8be23de98f71b1568e to your computer and use it in GitHub Desktop.
Save christophstrasen/65461f921b5e8a8be23de98f71b1568e to your computer and use it in GitHub Desktop.
function myFunction() {
var now = new Date();
//grab events within the next 7 days only
var future = new Date(now.getTime() + (7 * 24 * 60 * 60 * 1000));
var events = CalendarApp.getDefaultCalendar().getEvents(now, future);
events.forEach(function(event) {
hasgoal = false;
hasagenda = false;
mystatus = event.getMyStatus().toString();
Logger.log(event.getTitle());
// only non-recurring events where I am not the organiser and I didnt RSVP yet.
// the INVITED also serves as a way to make sure we don't loop multiple times over the same event and spam the owner.
if(!event.isRecurringEvent() && mystatus == 'INVITED') {
Logger.log(event.getTitle(),mystatus);
if(event.getDescription().match(/goal/gi) != null) {
hasgoal = true;
}
if(event.getDescription().match(/agenda/gi) != null) {
hasagenda = true;
}
if (hasagenda && hasgoal) {
Logger.log("Has Agenda and goal. All good.");
return;
}
messagebeg = "Dear valued coworker,\n\nThis is an automated message intended to politely ask, that you give meeting guests the opportunity to come prepared and leave your meetings with a result.\nWith that in mind, I would appreciate if you added ";
messageend = "to your meeting \"" + event.getTitle() + "\".\n\nPlease let me know when you made the changes or if you want to discuss beforehand so I can review and change my status from \"tentative\" to a firm \"yes\" or \"no\".\n\nThank you so very much and see you soon.\n\n\nCheers\nChristoph's communication automation";
if (!hasagenda) {
messagemid = "an agenda ";
subject = event.getTitle() + " - please add agenda";
}
if (!hasgoal) {
messagemid = "a meeting goal ";
subject = event.getTitle() + " - please add meeting goal";
}
if (!hasgoal && !hasagenda) {
messagemid = "an agenda & meeting goal(s) ";
subject = event.getTitle() + " - please add agenda & meeting goal";
}
message = messagebeg + messagemid + messageend;
emailAddress = event.getCreators()[0];
if(emailAddress.match(/yourdomain/gi) != null) {
Logger.log("matches");
MailApp.sendEmail(emailAddress, subject, message);
event.setMyStatus(CalendarApp.GuestStatus.MAYBE);
Logger.log(emailAddress + subject + message);
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment