Possible to create event using Google CalendarApp and send to somebody else? - google-apps-script

I have written a script that queues reminders, and emails them a delegated user. I would like to send calendar events to the person, instead of emails.
My question is: Is it possible to create an event using the CalendarApp and send it to another gCalendar user? I see API's for querying ownership, but not for setting it. An event with anonymous ownership would also be useful.

There are two approaches here.
You can setup your script so that it is runs as the user who will want the calendar invite. You can see this under the Publish menu option
OR you can add the person as a guest using the addGuest API.
There are no other ways to access another person's calendar and adding an event owned by them. Sounds the given the current setup #2 would be the simplest.

Related

How to identify onChange event source/author in the google sheets via google apps script

I need to determine if the onChange event in Google sheets is triggered by a Google service account or by a person, because I want to process the changed data only if the trigger source was human-made direct editing, otherwise stop processing.
I tried to identify it with Session.getActiverUser(), but, although the change is through the service account, shows my own email address.
I can not find anything on the Internet, nor in the Google documentation.
PS: to be more clear, I did bidirectional syncing from Firebase Realtime Database to Sheets and vice versa. Therefore, to avoid redundant update cycle, I want to stop processing as soon as change/update happens on behalf of the Service Account.
Or maybe there is some other way to avoid loop problem. I will be glad of any help
So, basically it is a bit a hacky way, but it works.
As #TheMaster suggested onChange event parameter e contains user node, which in case of Service Account is empty, thus could be used to distinguish change event sources.

Track "copy to my calendar" of shared google calendar events using Apps Scripts

I own a calendar which is shared with a certain number of people (subscribers). I would like to keep track of which events the subscribers add/copy to their personal calendars. The calendar is created by a spreadsheet using Apps Scripts and I have full access on anything needed. The emails of the subscribers are known but I can't access info on their side.
I would be happy with a boolean of a kind showing if an event has been copied, but if that's possible then I believe I'll be able to also count which and how many subscribers copied which events.
No, the Calendar API doesn't have any way to obtain if and event was copied. In any case, the event copy option is just a template from the original event that can be completely modified before being created.

Communicating between Google Calendar, Google Forms and Google Spreadsheets

Consider a Google Calendar scenario with various rooms that can be booked. Users will be browsing the different rooms and can create an entry in one of the free slots. The basic default properties provided by the Google Calendar are not sufficient for the business scenario but I haven't found a way to add more fields: the default new event form does seem to be customisable. Is this so?
My idea was to provide a Google Form to cover the rest of the details.
The process would look as below:
The user browses the different rooms and finds an available slot. The calendar entry is created with the basic details. The entry is added into the calendar and the details are recorded into a Google spreadsheet.
The user receives an email with another google form: the ID of the appointment would need to somehow be passed as parameter. The google form will be used to insert the "advanced details" into the spreadsheet.
An interface will be created to view the spreadsheet data in a more structured and user friendly manner.
Can something like this be done using Google Calendars, Google Forms and App Script? Any pointers where to start from? Or if not, how the process could be changed to be actually possible. The only starting points I found were Add ins which create calendar entries directly from Google forms, but this would require the user to start from a form, rather from the calendar, which I would not rather go for, not at least until I know there's no other way.

Gmail auto populate bcc field

Using Gmail, can I create a script that allows me to key off of an address in the To/Cc field to add an address to the BCC field using some browser-side code?
Ex:
Whenever an email with example#example.com is created in the TO/CC field (or created via a reply/reply-all etc) I want for the email address otherName#myCRM.com to be added to the BCC field.
I don't want this for a single address (or this would be much easier) I want to have a dictionary with many To/CC addresses that maps to many BCC addresses. I would also like to update the dictionary on a regular basis.
Here is a link to the API that I was planning on using to create this Google Apps Script: https://developers.google.com/apps-script/reference/gmail/
Is this possible? If so is there an example of doing it? I haven't been able to find one!
Because Google Apps Script runs server side, not client side, you can't do this in the way you have described.
While you can use Apps Script to access messages in the Drafts or Sent labels, it doesn't appear you can set the BCC value of those messages, only retrieve it.
One approach that might work is to poll the Draft or Sent messages folder on a fixed schedule, identify emails meeting your criteria, and then forward them to a given address (the one you wish to BCC). There are a number of challenges to this approach, such as determining how to avoid forwarding a given message multiple times, but it could be made to work.
See the docs on how to run your script on a schedule here:
https://developers.google.com/apps-script/guides/triggers/installable#time-driven_triggers
Edit, additional details in response to comment:
Setting up the triggers is very simple, I've used them many times in the past. You simply write a function that takes the actions you want, and once you have finished testing it manually, you can create the trigger via the "Resources" -> "Current Script's Triggers" menu options in the Script Editor.
You can't simply store processed id's in a variable, state is not shared between instances of the script. So you'll need to track them elsewhere, depending on volume you might want to look at the Properties Service, storing them in a spreadsheet, or my favorite would be to apply a label to processed emails and cross check the label in your script.
The label approach also lets you easily see which messages have been processed in the gmail interface.
If what you want is sending a copy of sent mail automatically to some address, that can be done with filters. I found the solution here:
http://markmail.org/message/nj46fcwlccd6asoj
"Configure the filter like this:
From: your email address
Forward: your email address
Enable never send to spam (IMPORTANT!)
"

Google Apps Script - communication between script

HiMy problem is following: I would like to create small web page, on which it will be possible to create event in Google Calendar, but with some restrictions. In my case this calendar could be edited by my flatmates to reserve washing machine. This reservation cannot overlap and also all of us has limited number of days when we can use it. I have created private calendar, and I have created script which validate requests, and if everything is ok add event to calendar. This script is executed as me (because only I have permission to edit this calendar).
But I have problem with fetching information which user execute this script (me or one of my flatmate). Class Session contains 2 methods getActiveUser() and getEffectiveUser() but active user does not work (I guess because privacy protection policy). But if I create another script which is executed as user accessing the web I can get active user.
Does anybody know if is it possible to communicate somehow between this 2 scripts embedeed on the same site? I want to pass email of active user from one script to another. Or maybe do you know better solution how to solve this problem?
Regards
Adam
As you noticed, you need to set the script to run as the user accessing it to get his email. Then, instead of accessing the calendar directly (which you obviously can't) you can call another script published, but running as yourself allowing anonymous access that will receive this request from the "viewing" script and create the calendar events for it.
After you publish this "background" script, get its url and use it on a UrlfetchApp.fetch call to it. Then pass the parameters as url paremeters (or on payload if you prefer to use post instead of get).
The background script may even use ContentService to give nice return values to the calling script.
Sure, you can do so, but it's not as simple as you'd like. Make your admin level script run a web service that responds to the other script. It can probably be hacked as you can't authenticate the users, but comon, this is a washing macine!