{"id":30943,"date":"2021-05-14T12:41:58","date_gmt":"2021-05-14T10:41:58","guid":{"rendered":"https:\/\/www.sms77.io\/docs\/drittanbieter\/google-apps-script\/"},"modified":"2021-12-10T11:00:48","modified_gmt":"2021-12-10T10:00:48","slug":"google-apps-script","status":"publish","type":"docs","link":"https:\/\/www.seven.io\/de\/docs\/drittanbieter\/google-apps-script\/","title":{"rendered":"Google Apps Script"},"content":{"rendered":"

\n Dies ist eine Sammlung von Code-Snippets, die innerhalb von Google Apps
\n Script<\/a> ausgef\u00fchrt werden k\u00f6nnen. Die Snippets sind in hohem Ma\u00dfe anpassbar und
\n k\u00f6nnen in F\u00e4llen, in denen keine eigene Serverinfrastruktur vorhanden ist, sehr
\n n\u00fctzlich sein.\n<\/p>\n

\n

Google Calendar<\/h2>\n

F\u00fcr jede Funktion kann die Zeitspanne durch \u00c4ndern der Variable
\n Stunden<\/code> ge\u00e4ndert werden. Der Standardwert ist 96.<\/p>\n

SMS<\/h3>\n

Die Funktion Sms77CalendarSMS<\/code> sendet eine SMS f\u00fcr jedes Ereignis, das
\n in dem angegebenen Zeitrahmen eintritt.<\/p>\n

\r\nfunction Sms77CalendarSMS() {\r\n    const apiKey = 'IHR_SMS77_SCHNITTSTELLENSCHL\u00dcSSEL';\r\n    const to = 'DIE_GEW\u00dcNSCHTE_EMPF\u00c4NGERNUMMER';\r\n\r\n    const zuPlatzhalter = key => `:${key}:`;\r\n    const platzhalter_id = zuPlatzhalter('ID');\r\n    const platzhalter_zeit = zuPlatzhalter('TIME');\r\n    const platzhalter_titel = zuPlatzhalter('TITLE');\r\n    const jetzt = new Date();\r\n    const statusTagKey = 'sms77_status_sms';\r\n    const statusTagValue = 'ok';\r\n\r\n    const textVorlage = `Google Kalendar: Anstehendes Ereignis: ${platzhalter_titel} mit ID ${platzhalter_id} beginnt ${platzhalter_zeit}.`;\r\n\r\n    const kalendarName = '';\r\n    const debug = false;\r\n    const delay = '';\r\n    const flash = false;\r\n    const foreign_id = '';\r\n    const absender = 'GoogleApps';\r\n    const stunden = 96; \/\/ Stunden ab jetzt bis Enddatum\r\n    const label = '';\r\n    const performance_tracking = false;\r\n\r\n    for (const event of ('' === kalendarName ? CalendarApp.getDefaultCalendar()\r\n        : CalendarApp.getCalendarsByName(kalendarName)).getEvents(\r\n        jetzt, new Date(jetzt.getTime() + (stunden * 60 * 60 * 1000)))) {\r\n        if (statusTagValue === event.getTag(statusTagKey)) continue;\r\n\r\n        let text = textVorlage;\r\n        Object.entries({\r\n            [platzhalter_id]: () => event.getId(),\r\n            [platzhalter_zeit]: () => event.getStartTime(),\r\n            [platzhalter_titel]: () => event.getTitle(),\r\n        }).forEach(([k, v]) => text = text.replace(k, v()));\r\n\r\n        const payload = {\r\n            from: absender,\r\n            text,\r\n            to,\r\n        };\r\n        Object.entries({\r\n            debug,\r\n            delay,\r\n            flash,\r\n            foreign_id,\r\n            from: absender,\r\n            label,\r\n            performance_tracking\r\n        }).forEach(([k, v]) => {\r\n            if (false !== v) {\r\n                if (true === v) payload[k] = '1';\r\n                else if ('' !== v) payload[k] = v;\r\n            }\r\n        });\r\n\r\n        const antwort = UrlFetchApp.fetch('https:\/\/gateway.sms77.io\/api\/sms', {\r\n            headers: {\r\n                SentWith: 'Google-Apps',\r\n                'X-Api-Key': apiKey,\r\n            },\r\n            method: 'post',\r\n            payload,\r\n        }).getContentText();\r\n\r\n        if (100 !== Number.parseInt(antwort)) throw new Error(`Unexpected status code \"${antwort}\".`);\r\n\r\n        Logger.log(antwort);\r\n\r\n        event.setTag(statusTagKey, statusTagValue);\r\n    }\r\n}\r\n<\/pre>\n

Sprachnachricht<\/h3>\n

Die Funktion Sms77CalendarVoice<\/code> gibt f\u00fcr jedes Ereignis, das im
\n angegebenen Zeitraum eintritt, einen Text-to-Speech-Aufruf aus.<\/p>\n

\r\nfunction Sms77CalendarVoice() {\r\n    const apiKey = 'IHR_SMS77_SCHNITTSTELLENSCHL\u00dcSSEL';\r\n    const to = 'DIE_GEW\u00dcNSCHTE_EMPF\u00c4NGERNUMMER';\r\n\r\n    const zuPlatzhalter = key => `:${key}:`;\r\n    const platzhalter_id = zuPlatzhalter('ID');\r\n    const platzhalter_zeit = zuPlatzhalter('TIME');\r\n    const platzhalter_titel = zuPlatzhalter('TITLE');\r\n    const jetzt = new Date();\r\n    const statusTagKey = 'sms77_status_voice';\r\n    const statusTagValue = 'ok';\r\n\r\n    const textVorlage = `Google Kalendar informiert \u00fcber anstehendes Ereignis ${platzhalter_titel} mit Beginn ${platzhalter_zeit}.`;\r\n\r\n    const kalendarName = '';\r\n    const absender = '+491771783130';\r\n    const stunden = 96; \/\/ Stunden ab jetzt bis Enddatum\r\n    const xml = false;\r\n\r\n    for (const event of ('' === kalendarName ? CalendarApp.getDefaultCalendar()\r\n        : CalendarApp.getCalendarsByName(kalendarName)).getEvents(\r\n        jetzt, new Date(jetzt.getTime() + (stunden * 60 * 60 * 1000)))) {\r\n        if (statusTagValue === event.getTag(statusTagKey)) continue;\r\n\r\n        let text = textVorlage;\r\n        Object.entries({\r\n            [platzhalter_id]: () => event.getId(),\r\n            [platzhalter_zeit]: () => event.getStartTime(),\r\n            [platzhalter_titel]: () => event.getTitle(),\r\n        }).forEach(([k, v]) => text = text.replace(k, v()));\r\n\r\n        const payload = {\r\n            from: absender,\r\n            text,\r\n            to,\r\n        };\r\n\r\n        if (xml) payload.xml = '1';\r\n\r\n        const antwort = UrlFetchApp.fetch('https:\/\/gateway.sms77.io\/api\/voice', {\r\n            headers: {\r\n                SentWith: 'Google-Apps',\r\n                'X-Api-Key': apiKey,\r\n            },\r\n            method: 'post',\r\n            payload,\r\n        }).getContentText();\r\n\r\n        Logger.log(antwort);\r\n\r\n        const code = antwort.split('\\n')[0];\r\n        if ('100' !== code) throw new Error(`Unerwarteter Statuscode \"${code}\".`);\r\n\r\n        event.setTag(statusTagKey, statusTagValue);\r\n    }\r\n}\r\n<\/pre>\n<\/section>\n
\n
\n

Google Kontakte<\/h2>\n

SMS<\/h3>\n

Die Funktion Sms77ContactsSMS<\/code> sendet eine SMS an alle Ihre Kontakte.\n <\/p>\n

\r\nfunction Sms77ContactsSMS() {\r\n    const apiKey = 'IHR_SMS77_SCHNITTSTELLENSCHL\u00dcSSEL';\r\n\r\n    const zuPlatzhalter = key => `:${key}:`;\r\n    const platzhalter_id = zuPlatzhalter('ID');\r\n    const platzhalter_name = zuPlatzhalter('FULL_NAME');\r\n    const placeholder_notizen = zuPlatzhalter('NOTES');\r\n\r\n    const textVorlage = `Liebste(r) ${platzhalter_name}, unsere neue Rufnummer lautet +4901234567890. Beste Gr\u00fc\u00dfe von Phil von sms77!`;\r\n\r\n    const debug = false;\r\n    const delay = '';\r\n    const flash = false;\r\n    const foreign_id = '';\r\n    const absender = 'GoogleApps';\r\n    const label = '';\r\n    const performance_tracking = false;\r\n\r\n    for (const contact of ContactsApp.getContacts()) {\r\n        const phones = contact.getPhones();\r\n        if (!phones.length) continue;\r\n\r\n        let text = textVorlage;\r\n        Object.entries({\r\n            [platzhalter_id]: () => contact.getId(),\r\n            [platzhalter_name]: () => contact.getFullName(),\r\n            [placeholder_notizen]: () => contact.getNotes(),\r\n        }).forEach(([k, v]) => text = text.replace(k, v()));\r\n\r\n        const payload = {\r\n            from: absender,\r\n            text,\r\n            to: (phones.find(p => p.isPrimary()) || phones.shift()).getPhoneNumber(),\r\n        };\r\n        Object.entries({\r\n            debug,\r\n            delay,\r\n            flash,\r\n            foreign_id,\r\n            from: absender,\r\n            label,\r\n            performance_tracking\r\n        }).forEach(([k, v]) => {\r\n            if (false !== v) {\r\n                if (true === v) payload[k] = '1';\r\n                else if ('' !== v) payload[k] = v;\r\n            }\r\n        });\r\n\r\n        const antwort = UrlFetchApp.fetch('https:\/\/gateway.sms77.io\/api\/sms', {\r\n            headers: {\r\n                SentWith: 'Google-Apps',\r\n                'X-Api-Key': apiKey,\r\n            },\r\n            method: 'post',\r\n            payload,\r\n        }).getContentText();\r\n\r\n        if (100 !== Number.parseInt(antwort)) throw new Error(`Unexpected status code \"${antwort}\".`);\r\n\r\n        Logger.log(antwort);\r\n    }\r\n}\r\n<\/pre>\n

Sprachnachrichten<\/h3>\n

Die Funktion Sms77ContactsVoice<\/code> gibt einen Text-to-Speech-Anruf an
\n alle Ihre Kontakte aus.<\/p>\n

\r\nfunction Sms77ContactsVoice() {\r\n    const apiKey = 'IHR_SMS77_SCHNITTSTELLENSCHL\u00dcSSEL';\r\n\r\n    const zuPlatzhalter = key => `:${key}:`;\r\n    const platzhalter_id = zuPlatzhalter('ID');\r\n    const platzhalter_name = zuPlatzhalter('FULL_NAME');\r\n    const placeholder_notizen = zuPlatzhalter('NOTES');\r\n\r\n    const textVorlage = `Liebste(r) ${platzhalter_name} unsere neue Rufnummer lautet +4901234567890. Beste Gr\u00fc\u00dfe Phil von sms77!`;\r\n\r\n    const absender = '+491771783130';\r\n    const xml = false;\r\n\r\n    for (const contact of ContactsApp.getContacts()) {\r\n        const phones = contact.getPhones();\r\n        if (!phones.length) continue;\r\n\r\n        let text = textVorlage;\r\n        Object.entries({\r\n            [platzhalter_id]: () => contact.getId(),\r\n            [platzhalter_name]: () => contact.getFullName(),\r\n            [placeholder_notizen]: () => contact.getNotes(),\r\n        }).forEach(([k, v]) => text = text.replace(k, v()));\r\n\r\n        const payload = {\r\n            from: absender,\r\n            text,\r\n            to: (phones.find(p => p.isPrimary()) || phones.shift()).getPhoneNumber(),\r\n        };\r\n\r\n        if (xml) payload.xml = '1';\r\n\r\n        const antwort = UrlFetchApp.fetch('https:\/\/gateway.sms77.io\/api\/voice', {\r\n            headers: {\r\n                SentWith: 'Google-Apps',\r\n                'X-Api-Key': apiKey,\r\n            },\r\n            method: 'post',\r\n            payload,\r\n        }).getContentText();\r\n\r\n        Logger.log(antwort);\r\n\r\n        const code = antwort.split('\\n')[0];\r\n        if ('100' !== code) throw new Error(`Unerwarteter Statuscode \"${code}\".`);\r\n    }\r\n}\r\n<\/pre>\n<\/section>\n","protected":false},"featured_media":0,"parent":17825,"menu_order":18,"comment_status":"open","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-30943","docs","type-docs","status-publish","hentry"],"comment_count":0,"_links":{"self":[{"href":"https:\/\/www.seven.io\/de\/wp-json\/wp\/v2\/docs\/30943","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.seven.io\/de\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/www.seven.io\/de\/wp-json\/wp\/v2\/types\/docs"}],"replies":[{"embeddable":true,"href":"https:\/\/www.seven.io\/de\/wp-json\/wp\/v2\/comments?post=30943"}],"version-history":[{"count":2,"href":"https:\/\/www.seven.io\/de\/wp-json\/wp\/v2\/docs\/30943\/revisions"}],"predecessor-version":[{"id":30948,"href":"https:\/\/www.seven.io\/de\/wp-json\/wp\/v2\/docs\/30943\/revisions\/30948"}],"up":[{"embeddable":true,"href":"https:\/\/www.seven.io\/de\/wp-json\/wp\/v2\/docs\/17825"}],"next":[{"title":"GitHub Actions","link":"https:\/\/www.seven.io\/de\/docs\/drittanbieter\/github-actions\/","href":"https:\/\/www.seven.io\/de\/wp-json\/wp\/v2\/docs\/26881"}],"prev":[{"title":"Firefox Add-On","link":"https:\/\/www.seven.io\/de\/docs\/drittanbieter\/firefox\/","href":"https:\/\/www.seven.io\/de\/wp-json\/wp\/v2\/docs\/17853"}],"wp:attachment":[{"href":"https:\/\/www.seven.io\/de\/wp-json\/wp\/v2\/media?parent=30943"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/www.seven.io\/de\/wp-json\/wp\/v2\/doc_tag?post=30943"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}