forked from Iku/Google-Forms-to-Discord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
google script.js
58 lines (51 loc) · 1.58 KB
/
google 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
57
58
const POST_URL = "WEBBHOOK URL";
function onSubmit(e) {
const response = e.response.getItemResponses();
let items = [];
for (const responseAnswer of response) {
const question = responseAnswer.getItem().getTitle();
const answer = responseAnswer.getResponse();
let parts = []
try {
parts = answer.match(/[\s\S]{1,1024}/g) || [];
} catch (e) {
parts = answer;
}
if (!answer) {
continue;
}
for (const [index, part] of Object.entries(parts)) {
if (index == 0) {
items.push({
"name": question,
"value": part,
"inline": false
});
} else {
items.push({
"name": question.concat(" (cont.)"),
"value": part,
"inline": false
});
}
}
}
const options = {
"method": "post",
"headers": {
"Content-Type": "application/json",
},
"payload": JSON.stringify({
"content": "",
"embeds": [{
"title": "Some nice title here",
"color": 33023, // This is optional, you can look for decimal colour codes at https://www.webtoolkitonline.com/hexadecimal-decimal-color-converter.html
"fields": items,
"footer": {
"text": "Some footer here"
}
}]
})
};
UrlFetchApp.fetch(POST_URL, options);
};