Subbu1304 commited on
Commit
0c30862
·
verified ·
1 Parent(s): 0023f40

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +76 -28
templates/index.html CHANGED
@@ -179,58 +179,106 @@
179
  let mobileField = document.getElementById('mobile');
180
  let infoMessage = document.getElementById('infoMessage');
181
 
182
- function startListeningForName() {
183
  recognition.start();
184
  recognition.onresult = function(event) {
185
- const name = event.results[0][0].transcript.trim();
186
- nameField.value = name;
187
  recognition.stop();
188
- infoMessage.textContent = "Listening for your email...";
189
- setTimeout(startListeningForEmail, 500); // Wait a moment before listening for email
190
  };
191
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
 
193
  function startListeningForEmail() {
194
  recognition.start();
195
  recognition.onresult = function(event) {
196
- const email = event.results[0][0].transcript.trim();
197
- emailField.value = email;
198
  recognition.stop();
199
- infoMessage.textContent = "Listening for your mobile number...";
200
- setTimeout(startListeningForMobile, 500); // Wait a moment before listening for mobile
 
 
 
 
 
 
 
 
 
 
201
  };
202
  }
203
 
204
  function startListeningForMobile() {
205
  recognition.start();
206
  recognition.onresult = function(event) {
207
- const mobile = event.results[0][0].transcript.trim();
208
- mobileField.value = mobile;
209
  recognition.stop();
210
- infoMessage.textContent = "Almost done...";
211
- showConfirmation();
 
 
 
 
 
 
 
 
 
 
 
 
212
  };
213
  }
214
 
215
- function showConfirmation() {
216
- document.getElementById('confirmName').textContent = nameField.value;
217
- document.getElementById('confirmEmail').textContent = emailField.value;
218
- document.getElementById('confirmPhone').textContent = mobileField.value;
219
  document.getElementById('confirmation').style.display = 'block';
 
220
  }
221
-
222
  function autoSubmit() {
223
- const name = nameField.value;
224
- const email = emailField.value;
225
- const phone = mobileField.value;
226
- // You can submit this data to your backend or Salesforce here
227
- alert(`Registration successful for ${name}`);
228
- // For demo purposes, reload the page after 5 seconds
229
- setTimeout(() => location.reload(), 5000);
 
 
 
 
 
 
 
 
 
 
 
 
 
230
  }
231
-
232
- // Start the process by asking for registration or login
233
- window.onload = askLoginOrRegister;
234
  </script>
235
  </body>
236
  </html>
 
179
  let mobileField = document.getElementById('mobile');
180
  let infoMessage = document.getElementById('infoMessage');
181
 
182
+ function startListeningForName() {
183
  recognition.start();
184
  recognition.onresult = function(event) {
185
+ nameCaptured = event.results[0][0].transcript.trim();
186
+ document.getElementById('name').value = nameCaptured;
187
  recognition.stop();
188
+ setTimeout(confirmName, 500);
 
189
  };
190
  }
191
+ function confirmName() {
192
+ speak("You said " + nameCaptured + ". Is it okay, or do you want to change it?", function() {
193
+ recognition.start();
194
+ recognition.onresult = function(event) {
195
+ let confirmation = event.results[0][0].transcript.trim().toLowerCase();
196
+ recognition.stop();
197
+ if (confirmation.includes("ok") || confirmation.includes("yes")) {
198
+ setTimeout(() => speak("Great! Now, tell me your email.", startListeningForEmail), 500);
199
+ } else {
200
+ setTimeout(() => speak("Let's try again. Tell me your name.", startListeningForName), 500);
201
+ }
202
+ };
203
+ });
204
+ }
205
 
206
  function startListeningForEmail() {
207
  recognition.start();
208
  recognition.onresult = function(event) {
209
+ emailCaptured = event.results[0][0].transcript.trim().replace(/\bat\b/g, '@').replace(/\s+/g, '');
210
+ document.getElementById('email').value = emailCaptured;
211
  recognition.stop();
212
+ speak("You said " + emailCaptured + ". Is it correct?", function() {
213
+ recognition.start();
214
+ recognition.onresult = function(event) {
215
+ let confirmation = event.results[0][0].transcript.trim().toLowerCase();
216
+ recognition.stop();
217
+ if (confirmation.includes("ok") || confirmation.includes("yes")) {
218
+ setTimeout(() => speak("Great! Now, tell me your mobile number.", startListeningForMobile), 500);
219
+ } else {
220
+ speak("Let's try again. Tell me your email.", startListeningForEmail);
221
+ }
222
+ };
223
+ });
224
  };
225
  }
226
 
227
  function startListeningForMobile() {
228
  recognition.start();
229
  recognition.onresult = function(event) {
230
+ mobileCaptured = event.results[0][0].transcript.trim().replace(/\s+/g, '');
231
+ document.getElementById('mobile').value = mobileCaptured;
232
  recognition.stop();
233
+ speak("You said " + mobileCaptured + ". Is it correct?", function() {
234
+ recognition.start();
235
+ recognition.onresult = function(event) {
236
+ let confirmation = event.results[0][0].transcript.trim().toLowerCase();
237
+ recognition.stop();
238
+ if (confirmation.includes("ok") || confirmation.includes("yes")) {
239
+ speak("All details are captured. Confirming your registration.", function() {
240
+ autoConfirm();
241
+ });
242
+ } else {
243
+ speak("Let's try again. Tell me your mobile number.", startListeningForMobile);
244
+ }
245
+ };
246
+ });
247
  };
248
  }
249
 
250
+ function autoConfirm() {
251
+ document.getElementById('confirmName').textContent = document.getElementById('name').value;
252
+ document.getElementById('confirmEmail').textContent = document.getElementById('email').value;
253
+ document.getElementById('confirmPhone').textContent = document.getElementById('mobile').value;
254
  document.getElementById('confirmation').style.display = 'block';
255
+ setTimeout(autoSubmit, 3000);
256
  }
 
257
  function autoSubmit() {
258
+ var name = document.getElementById('name').value;
259
+ var email = document.getElementById('email').value;
260
+ var phone = document.getElementById('mobile').value;
261
+ fetch('/submit', {
262
+ method: 'POST',
263
+ headers: { 'Content-Type': 'application/json' },
264
+ body: JSON.stringify({ name: name, email: email, phone: phone })
265
+ })
266
+ .then(response => response.json())
267
+ .then(data => {
268
+ if (data.success) {
269
+ document.getElementById('status').textContent = 'Your details were submitted successfully!';
270
+ document.getElementById('confirmation').style.display = 'none';
271
+ speak("Your registration is complete. Thank you for registering.");
272
+ setTimeout(() => location.reload(), 5000);
273
+ } else {
274
+ document.getElementById('status').textContent = 'There was an error submitting your details.';
275
+ speak("There was an error submitting your details. Please try again.");
276
+ }
277
+ });
278
  }
279
+ window.onload = function () {
280
+ setTimeout(startListeningForName, 4000);
281
+ };
282
  </script>
283
  </body>
284
  </html>