Apps Script get User's Work Week Settings - google-apps-script

I'm working on a script to automatically schedule certain tasks for some users at my company. When the tasks get scheduled will be based on the user's workweek and workday, which can be customized in Google Calendar. Most of us have a M-F work week, but we have flexible schedules so for some of us, their work day may be 7-3, others 8-4, or 9-5. Some may work 4 days a week, 10 hours a day so they work Mon-Thur, 7-5, 8-6, or 9-7. That's not counting second shift, third shift, etc. I don't want the tasks to be scheduled outside of their workdays.
How can I access these settings from Apps Script?

Unfortunately, it is currently not possible to get Working Hours information through Calendar API.
Although you can query whether there are conflicting events for a given calendar/time-frame using Freebusy.query(), this method will not return a “busy” response when querying for a time-frame out of working hours.
Additionally, there is currently a new Google API in alpha called Calendar User Availability API but it currently only exposes Working Location queries not Working Hours.
More information about Calendar User Availability API on this blog post
Alternatively, you can file a new Feature Request with Google using this template

Related

How to create Firebase Cloud messaging recurring notifications without console?

From FCM console I can not set up much more than 10 recurring notifications.
You can have up to 10 unique recurring notifications active per
project
I want to aim targeting audiences, user properties, last user engagement also. For example, you can set up a recurring notification that sends a push notification to a user who has been inactive for 2 days. From FCM console it is possible but I want to set it up manually since FCM console does not allow me to create recurring notifications much more than 10.
There is no API to create recurring notifications in Firebase Cloud Messaging. Since you already tagged your question with google-cloud-functions, you seem to know that you can create scheduled tasks with that.
To create a scheduled, recurring notification you can:
either run a function on a PubSub schedule or enqueue functions with Cloud Tasks, and
combine that with notifying the user when something interesting happens
From this documentation and the examples in it, you should be able to get the use-case working. If not, post another question with the minimal, complete code that any of us can run to reproduce where you got stuck.

Programmatically fetch user's last login date to G Suite

On a user's page on the G Suite admin console, an admin can see the last login of a user. For example, one user I can see has a "last login" date of two years ago.
I'm trying to pull this date programatically. However, the Reports API that provides information on login events only goes back 180 days. How is Google getting this login date, and can it be fetched via API?
Google has this information because they are logging the event when it happens and storing that to present in the admin console. If you start to build an application now and start storing those events as time passes you too will have a date that goes back years. G Suite Enterprise customers can seamlessly do this if they Set up BigQuery logs in the Admin console.
You should be able to get this information now though. Look at the following APIs used in GAMADV-XTD you can get this info with this command for example.
gam report users parameters accounts:last_login_time filters "accounts:last_login_time<#filtertime#" filtertime -5y
https://developers.google.com/admin-sdk/reports/v1/reference/activities
https://developers.google.com/admin-sdk/reports/v1/reference/customerUsageReports
https://developers.google.com/admin-sdk/reports/v1/reference/userUsageReport
I somehow missed this before, but you can get the last login date/time with the User Usage Report (rather than the Login Activity report).
API docs are here and the App Script example I'm using is here. I realized that if GAM was pulling the information there had to be an API for it.

Sharepoint Online scripting similar to Google Apps Script?

For several years we've had a Google Site setup on a non-profit G-Suite domain. This site is used once a year for a conference we hold with about 200 deleagates. The site is used by delegates for some simple stuff like reading documents, but there is a much more complex part of it too.
I've used Google apps script to write a system where users can do voting, speaker queueing, elections, and a daily checkin/rollcall. How it looks to users is they goto a page, and they see a "Vote Yes", "Vote No", and "Abstain" button. These are embedded Google apps script applets on the Google site page. Similar for the speaker queue and other functions.
On the backend, when a user clicks "Yes" or "No", the script submits a Google form on their behalf, with that answer. The form is tied to a Google sheet. Originally we had it directly append a line to a google sheet, but found with 200 people voting at the same time, we ran into performance issues and limitations with Google sheets.
The script then does stuff like de-deuplicate the results (incase someone voted multiple times), tabulates the results, and displays the results. This is all done on another page on the site that the officers running the conference can see.
For speaker queue, users basically click a button to say "I want to speak", and their names get added to a google sheet. The officers running the conference then call them up when it's their turn to speak. Users can also click a button to see where they are in the queue, and they'll get a response on the page like "You are currently number 3 of 27 users in the queue". They can also click a different button to remove themselves from the queue.
With that all explained, we're looking at potentially switching away from Google Sites, and considering Microsoft Sharepoint Online. The reason for this is we're using "old" Google sites, which Google has said will be shutdown at some point. "New" google sites currently does not support any scripting or API's at all, so it's impossible to redo our site in that system currently. They say API's are coming, but no details on what will and won't be available.
We have access to a free non-profits domain on Office365 (E1 tier) which gives us sharepoint online, active directory online, and $5k for free Azure credits.
So I'm asking you all here if there is some similar system available with O365/Sharepoint online. I'd want to change where all the data is stored to an SQL database, as storing stuff in sheets isn't ideal from any viewpoint, it's just the best option we had at the time. Ideally, the code for this would all live in the cloud like it does with Google. If I have to write code in Visual studio and upload it then I'm OK with that, but for maintenance purposes it would be really nice to have it all stored in the cloud and not need to install a thick app to work on it.
Basically we need the ability for users to login to a sharepoint site with their o365 account (we issue them the account), be able to interact with the site to send and receive data from SQL (which is running in Azure on same domain).
Can anyone point me in the right direction? It seems much more complex on the MS side, with way more potential methods for doing it (Graph, Sharepoint Addons, etc).
A couple photos:
Thanks!
I would like to provide a no coding solution here. If we want to code, then we can use SharePoint Add-in to do almost everything, such as collect user input and display data.
I've used Google apps script to write a system where users can do voting, speaker queueing, elections, and a daily checkin/rollcall. How it looks to users is they goto a page, and they see a "Vote Yes", "Vote No", and "Abstain" button. These are embedded Google apps script applets on the Google site page. Similar for the speaker queue and other functions.
On the backend, when a user clicks "Yes" or "No", the script submits a Google form on their behalf, with that answer. The form is tied to a Google sheet. Originally we had it directly append a line to a google sheet, but found with 200 people voting at the same time, we ran into performance issues and limitations with Google sheets.
I think we can create a Microsoft Form or Microsoft PowerApps to get user response. And then Store the data to a SharePoint list.
The script then does stuff like de-deuplicate the results (incase someone voted multiple times), tabulates the results, and displays the results. This is all done on another page on the site that the officers running the conference can see.
We can use Microsoft Flow to process the data, such as remove duplicated data. On the other hand, we can display results in PowerApps.
For speaker queue, users basically click a button to say "I want to speak", and their names get added to a google sheet. The officers running the conference then call them up when it's their turn to speak. Users can also click a button to see where they are in the queue, and they'll get a response on the page like "You are currently number 3 of 27 users in the queue". They can also click a different button to remove themselves from the queue.
We can do it in PowerApps.

How to find which app scripts are running?

I have a spreadsheet on which I have applied immediate notification on any changes. From few days I am continuously receiving notification of changes 3 to 4 times an hour with the following message:
See the changes in the Google Document "Paper-Teacher Database":
Click here
A user made changes from 5/23/18 5:39 AM to 5:28 AM (Pacific Daylight
Time)
Also the mails are at fairly regular interval, for example I received mail at
6:09 PM, 7:44 PM, 7:59PM, 8:20PM, 8:44PM, 8:58PM, 9:20PM, 9:28PM, 9:58PM, 10:20PM. 10:28PM
Since the user name is not specified, I believe the changes are being made at the owners end (thats me). Also since I am manually not making any changes, I believe some script is doing it. To the best of my knowledge I do not have any script which is time triggered 3-4 times an hour.
Is there a way to find out the erroneous script and stop it?
While signed in go to https://script.google.com/ Open the hamburger menu in the upper left corner and select “My executions” to see the list of the recently executed functions and associated projects.

Access to Google Calendar and Group Attendees for historical events via API

This question is a bit different from the average "How do I access the members of a group invited to a calendar event". I have been using the AdminSDK/Directory API to do that and it works well.
My scenario is this:
I have 2 different calendar items 6 months apart (one in the past and one in the future).
The same google group has been invited to these calendar events.
In the past 3 months, membership of that group has changed.
When I look at the 2 events in GCal and I click the arrow next to the group name, the members are listed correctly, in that it knows a different set of group members were invited to the event in the past than the one in the future.
If I change the group members, it will be reflected on the calendar item in the future but not the one in the past. (as I would expect)
My question is, how do I access the historical attendee information of the past calendar event via the API (short of scouring everyone's personal calendars).
This is accessible through the Calendar API, check on the get method of the Event resource (available in this link). The resource will expose the information of all attendees.