-
Notifications
You must be signed in to change notification settings - Fork 3
/
form_google_app_script.js
56 lines (48 loc) · 1.72 KB
/
form_google_app_script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* Uses the Forms API to create a simple quiz.
* For more information on using the Forms API, see
* https://developers.google.com/apps-script/reference/forms
*/
function sendInvite(e) {
// INPUT YOUR INFORMATION HERE
var adminEmail = 'YOUR_EMAIL'
var url = 'YOUR_APP_ENGINE_SERVER';
var formResponse = e.response;
var itemResponses = formResponse.getItemResponses();
var fname = itemResponses[0].getResponse();
var lname = itemResponses[1].getResponse();
var email = itemResponses[2].getResponse();
var payload = {
"fname": fname,
"lname": lname,
"email": email
};
var headers = {
// gets around App Engine bug with parsing url-encoded forms
"Content-Type": "application/octet-stream"
};
var options = {
'method': 'post',
'headers': headers,
'payload': payload
};
var response = UrlFetchApp.fetch(url, options);
var responseCode = response.getResponseCode();
if (responseCode != 200) {
if (MailApp.getRemainingDailyQuota() > 0) {
var message = "Response code was " + responseCode + ". URL was " + url + " and payload was " + JSON.stringify(payload) + ".";
MailApp.sendEmail(adminEmail,
'Error with HTTP request to Gophers Slack',
message);
}
}
var jsonResponse = Utilities.jsonParse(response.getContentText());
if (jsonResponse.ok != true) {
if (MailApp.getRemainingDailyQuota() > 0) {
var message = "Response was: " + response.getContentText() + ". Payload was: " + JSON.stringify(payload) + ". URL was: " + url + ".";
MailApp.sendEmail(adminEmail,
'Error with HTTP request to Gophers Slack.',
message);
}
}
}