-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
96 lines (88 loc) · 2.33 KB
/
app.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const fetch = require("node-fetch");
const PERSONAL_ACCESS_TOKEN = "";
const max = 100;
const min = 1;
const headers = {
Authorization: `Bearer ${PERSONAL_ACCESS_TOKEN}`,
"Content-Type": "application/json",
};
const makePayload = (index = max, nextForm) => ({
title: `Question ${index}`,
type: "form",
settings: {
language: "en",
is_public: true,
progress_bar: "percentage",
show_progress_bar: false,
show_typeform_branding: true,
show_time_to_complete: false,
meta: {
allow_indexing: false,
},
},
theme: {
href: "https://api.typeform.com/themes/ioH8Hm",
},
workspace: {
href: "https://api.typeform.com/workspaces/xr5597",
},
hidden: ["ticketreference", "teamname"],
welcome_screens: [
{
title: `Question ${index}`,
properties: {
description: "{{hidden:teamname}}",
show_button: true,
button_text: "Start",
},
attachment: {
type: "image",
href: "https://images.typeform.com/images/mbdN6ARMrY4P",
},
},
],
thankyou_screens: [
{
title: nextForm
? "On to the next question!"
: "Thanks for completing the pub quiz.",
properties: nextForm
? {
show_button: true,
button_text: "Continue",
button_mode: "redirect",
redirect_url: `https://hacksoc.typeform.com/to/${nextForm}?teamname={{hidden:teamname}}&ticketreference={{hidden:ticketreference}}`,
share_icons: false,
}
: {
show_button: false,
},
attachment: {
type: "image",
href: "https://images.typeform.com/images/mbdN6ARMrY4P",
},
},
],
fields: [
{
title: "Enter your answer",
type: "short_text",
validations: {
required: false,
},
},
],
});
const makeForms = async (nextForm = null, index = max, minIndex = min) => {
const form = await fetch("https://api.typeform.com/forms", {
method: "POST",
body: JSON.stringify(makePayload(index, nextForm)),
headers,
}).then((res) => res.json());
console.log(`Made form ${index}`, form._links.display);
if (index === min) {
return;
}
return makeForms(form.id, index - 1, minIndex);
};
makeForms();