-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_news.html
225 lines (192 loc) · 7.54 KB
/
add_news.html
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Add news</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
<style>
body {
max-width: 900px;
margin: auto;
}
.container {
width: 90%;
margin: auto;
}
.jumbotron {
background-color: #87CEEB;
border-radius: 1rem;
color: white;
margin-top: 15px;
margin-bottom: 15px;
padding-top: 15px;
padding-bottom: 15px;
}
</style>
<script>
document.addEventListener("DOMContentLoaded", function(event) {
var form = document.getElementById('form');
var generate_button = document.getElementById('generate');
generate_button.addEventListener('click', function(e){
e.preventDefault();
generate(new FormData(form));
});
var send_button = document.getElementById('send');
send_button.addEventListener('click', function(e){
e.preventDefault();
send(new FormData(form));
});
});
function generate (formData) {
document.getElementById('generate').disabled = true;
document.getElementById('generate').innerHTML = "Please wait ...";
form_json = Object.fromEntries(formData);
console.log("formData is:");
console.log(JSON.stringify(form_json));
fetch('https://flows.pastorinsights.ai/webhook/ahg0lRP83barIc5if7N4/generate_message', {
method: 'POST',
credentials: "include",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(form_json),
}).then(function(response) {
return response.json();
}).then(function(data) {
console.log(data);
if (data['status']) {
document.getElementById("question").value = data['question'];
document.getElementById("subject").value = data['subject'];
document.getElementById("body").value = data['body'];
document.getElementById('generate').disabled = false;
document.getElementById('generate').innerHTML = "Generate again";
document.getElementById('send').disabled = false;
document.getElementById('send').innerHTML = "Send";
} else {
var em = document.getElementById("errorMsg");
em.innerHTML = data['message'];
em.style.display = "block";
}
}).catch(error => {
console.error('Error:', error);
var em = document.getElementById("errorMsg");
em.style.display = "block";
});
}
function send (formData) {
document.getElementById('send').disabled = true;
document.getElementById('send').innerHTML = "Please wait ...";
form_json = Object.fromEntries(formData);
console.log("formData is:");
console.log(JSON.stringify(form_json));
fetch('https://flows.pastorinsights.ai/webhook/ahg0lRP83barIc5if7N4/save_message/' + form_json['passcode'], {
method: 'POST',
credentials: "include",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(form_json),
}).then(function(response) {
return response.json();
}).then(function(data) {
console.log(data);
if (data['status']) {
console.log("Sending message now");
fetch('https://flows.pastorinsights.ai/webhook/ahg0lRP83barIc5if7N4/send_message/' + form_json['passcode'] + '/' + form_json['profile'], {
method: 'GET',
credentials: "include"
}).then(function(response2) {
return response2.json();
}).then(function(data2) {
console.log(data2);
if (data2['status']) {
document.getElementById('send').innerHTML = "Done!";
}
});
} else {
var em = document.getElementById("errorMsg");
em.innerHTML = data['message'];
em.style.display = "block";
}
}).catch(error => {
console.error('Error:', error);
var em = document.getElementById("errorMsg");
em.style.display = "block";
});
}
</script>
</head>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-T3YP6PHS4N"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-T3YP6PHS4N');
</script>
<body>
<div class="jumbotron text-center">
<h1>Add a news story</h1>
<p>The next email newsletter to subscribers will be based on this story</p>
</div>
<div id="errorMsg" class="alert alert-danger" role="alert" hidden>
Sorry, there is a problem with your story.
</div>
<div id="successMsg" class="alert alert-success" role="alert" hidden>
<h4 class="alert-heading">Well done!</h4>
</div>
<form id="form" class="container">
<div class="form-group">
<label for="passcode" class="form-label">Passcode</label>
<input type="text" class="form-control" id="passcode" name="passcode">
</div>
<div class="form-group">
<label for="profile" class="form-label">Generate a message for</label>
<select class="form-control" name="profile" id="profile">
<option value="traditional">traditional Christian, and prefer strict Bible interpretations.</option>
<option value="progressive">progressive Christian, and believe that beliefs evolve to reflect some cultural changes.</option>
</select>
</div>
<div class="form-group">
<label for="headline" class="form-label">News headline</label>
<input type="text" class="form-control" id="headline" name="headline">
</div>
<div class="form-group">
<label for="content" class="form-label">News story</label>
<textarea class="form-control" id="content" name="content" rows="12"></textarea>
</div>
<div class="form-group">
<label for="url" class="form-label">Link to news story</label>
<input type="text" class="form-control" id="url" name="url">
</div>
<div class="form-group">
<label for="bible_verse" class="form-label">Related Bible verses</label>
<textarea class="form-control" id="bible_verse" name="bible_verse" rows="8"></textarea>
</div>
<div class="form-group">
<label for="guide" class="form-label">Additional guidance to the generated message</label>
<textarea class="form-control" id="guide" name="guide" rows="3"></textarea>
</div>
<br>
<button type="submit" id="generate" class="btn btn-primary">Generate</button>
<hr>
<div class="form-group">
<label for="question" class="form-label">A question the content answers</label>
<textarea class="form-control" id="question" name="question" rows="2"></textarea>
</div>
<div class="form-group">
<label for="subject" class="form-label">Message subject</label>
<textarea class="form-control" id="subject" name="subject" rows="2"></textarea>
</div>
<div class="form-group">
<label for="body" class="form-label">Message body</label>
<textarea class="form-control" id="body" name="body" rows="8"></textarea>
</div>
<br>
<button type="submit" id="send" class="btn btn-primary">Send</button>
<hr>
</form>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
</body>
</html>