lokesh341 commited on
Commit
77ef342
·
verified ·
1 Parent(s): 44553b9

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +203 -109
templates/index.html CHANGED
@@ -120,16 +120,14 @@
120
  alert("Speech Recognition API is not supported in this browser.");
121
  }
122
 
123
- // Speak function to read out messages
124
  function speak(text, callback) {
125
  const speech = new SpeechSynthesisUtterance(text);
126
  speech.onend = callback;
127
  window.speechSynthesis.speak(speech);
128
  }
129
 
130
- // Ask if the user is new or existing
131
  function askLoginOrRegister() {
132
- speak("Welcome to Biryani Hub. Are you a new customer or an existing customer? Say 'new' to register or 'existing' to login.", function () {
133
  recognition.start();
134
  recognition.onresult = function (event) {
135
  let response = event.results[0][0].transcript.trim().toLowerCase();
@@ -147,176 +145,272 @@
147
  });
148
  }
149
 
150
- // Show Registration form
151
  function showRegistrationForm() {
152
  document.getElementById('welcomePage').style.display = 'none';
153
  document.getElementById('registrationForm').style.display = 'block';
154
  document.getElementById('loginForm').style.display = 'none';
155
  }
156
 
157
- // Show Login form
158
  function showLoginForm() {
159
  document.getElementById('welcomePage').style.display = 'none';
160
  document.getElementById('registrationForm').style.display = 'none';
161
  document.getElementById('loginForm').style.display = 'block';
162
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
163
 
164
- // Capture Name
165
- function captureName() {
166
- speak("Please say your name.", function () {
167
- recognition.start();
168
- recognition.onresult = function (event) {
169
- let nameCaptured = event.results[0][0].transcript.trim();
170
- document.getElementById('name').value = nameCaptured;
171
- recognition.stop();
172
- speak("You said " + nameCaptured + ". Is it correct?", function () {
173
- confirmName(nameCaptured);
174
- });
175
- };
 
 
 
 
 
 
 
 
 
 
176
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
177
  }
 
 
178
 
179
- // Confirm Name
180
- function confirmName(nameCaptured) {
181
- recognition.start();
182
- recognition.onresult = function (event) {
183
- let confirmation = event.results[0][0].transcript.trim().toLowerCase();
184
- recognition.stop();
185
- if (isConfirmation(confirmation)) {
186
- captureEmail();
187
- } else {
188
- captureName();
189
- }
190
- };
 
 
 
 
 
 
 
 
 
 
 
191
  }
 
 
 
 
 
 
 
192
 
193
- // Capture Email
194
- function captureEmail() {
195
- speak("Now, say your email.", function () {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
  recognition.start();
197
  recognition.onresult = function (event) {
198
  let emailCaptured = event.results[0][0].transcript.trim().replace(/\bat\b/g, '@').replace(/\s+/g, '');
199
- document.getElementById('email').value = emailCaptured;
200
  recognition.stop();
201
  speak("You said " + emailCaptured + ". Is it correct?", function () {
202
- confirmEmail(emailCaptured);
203
  });
204
  };
205
  });
206
  }
207
 
208
- // Confirm Email
209
- function confirmEmail(emailCaptured) {
210
  recognition.start();
211
  recognition.onresult = function (event) {
212
  let confirmation = event.results[0][0].transcript.trim().toLowerCase();
213
  recognition.stop();
214
  if (isConfirmation(confirmation)) {
215
- captureMobile();
216
  } else {
217
- captureEmail();
218
  }
219
  };
220
  }
221
 
222
- // Capture Mobile
223
- function captureMobile() {
224
  speak("Now, say your mobile number.", function () {
225
  recognition.start();
226
  recognition.onresult = function (event) {
227
  let mobileCaptured = event.results[0][0].transcript.trim().replace(/\s+/g, '');
228
- document.getElementById('mobile').value = mobileCaptured;
229
  recognition.stop();
230
  speak("You said " + mobileCaptured + ". Is it correct?", function () {
231
- confirmMobile(mobileCaptured);
232
  });
233
  };
234
  });
235
  }
236
 
237
- // Confirm Mobile
238
- function confirmMobile(mobileCaptured) {
239
  recognition.start();
240
  recognition.onresult = function (event) {
241
  let confirmation = event.results[0][0].transcript.trim().toLowerCase();
242
  recognition.stop();
243
  if (isConfirmation(confirmation)) {
244
- submitRegistration();
245
  } else {
246
- captureMobile();
247
  }
248
  };
249
  }
250
 
251
- // Check for confirmation responses
252
- function isConfirmation(confirmation) {
253
- const validResponses = ["yes", "ok", "yeah", "correct", "yep"];
254
- return validResponses.some(response => confirmation.includes(response));
255
- }
256
 
257
- // Submit Registration details
258
- function submitRegistration() {
259
- const name = document.getElementById('name')?.value.trim();
260
- const email = document.getElementById('email')?.value.trim();
261
- const phone = document.getElementById('mobile')?.value.trim();
 
 
 
 
 
262
 
263
- if (!name || !email || !phone) {
264
- alert("Please provide all required details.");
265
- return;
 
 
 
 
 
 
 
 
 
 
 
 
 
266
  }
 
 
 
 
 
 
 
 
 
267
 
268
- console.log("Sending data:", { name, email, phone });
269
-
270
- fetch('/submit', {
271
- method: 'POST',
272
- headers: { 'Content-Type': 'application/json' },
273
- body: JSON.stringify({ name, email, phone })
274
- })
275
- .then(response => response.json())
276
- .then(data => {
277
- if (data.success) {
278
- speak(`Thank you for registering, ${name}!`);
279
- let statusText = document.getElementById('statusText');
280
- let statusMessage = document.getElementById('statusMessage');
281
-
282
- if (statusText && statusMessage) {
283
- statusText.textContent = `Thank you for registering, ${name}!`;
284
- statusMessage.style.display = 'block';
285
- setTimeout(() => {
286
- statusText.textContent = 'Submitted Successfully!';
287
- setTimeout(() => {
288
- window.location.reload();
289
- }, 5000);
290
- }, 6000);
291
- }
292
- } else {
293
- speak("There was an error submitting your details. Please try again.");
294
- let statusText = document.getElementById('statusText');
295
- let statusMessage = document.getElementById('statusMessage');
296
-
297
- if (statusText && statusMessage) {
298
- statusText.textContent = 'There was an error submitting your details. Please try again.';
299
- statusMessage.style.display = 'block';
300
- }
301
- }
302
- })
303
- .catch(error => {
304
- console.error("Fetch Error:", error);
305
- speak("An error occurred. Please try again.");
306
- let statusText = document.getElementById('statusText');
307
- let statusMessage = document.getElementById('statusMessage');
308
-
309
- if (statusText && statusMessage) {
310
- statusText.textContent = 'An error occurred. Please try again.';
311
- statusMessage.style.display = 'block';
312
- }
313
- });
314
- }
315
-
316
- // Start the process when the page loads
317
  window.onload = function () {
318
  askLoginOrRegister();
319
  };
320
  </script>
321
  </body>
322
- </html>
 
120
  alert("Speech Recognition API is not supported in this browser.");
121
  }
122
 
 
123
  function speak(text, callback) {
124
  const speech = new SpeechSynthesisUtterance(text);
125
  speech.onend = callback;
126
  window.speechSynthesis.speak(speech);
127
  }
128
 
 
129
  function askLoginOrRegister() {
130
+ speak("Welcome to Biryani Hub.Are you a new customer or an existing customer? Say 'new' to register or 'existing' to login.", function () {
131
  recognition.start();
132
  recognition.onresult = function (event) {
133
  let response = event.results[0][0].transcript.trim().toLowerCase();
 
145
  });
146
  }
147
 
 
148
  function showRegistrationForm() {
149
  document.getElementById('welcomePage').style.display = 'none';
150
  document.getElementById('registrationForm').style.display = 'block';
151
  document.getElementById('loginForm').style.display = 'none';
152
  }
153
 
 
154
  function showLoginForm() {
155
  document.getElementById('welcomePage').style.display = 'none';
156
  document.getElementById('registrationForm').style.display = 'none';
157
  document.getElementById('loginForm').style.display = 'block';
158
  }
159
+ function captureName() {
160
+ speak("Please say your name.", function () {
161
+ recognition.start();
162
+ recognition.onresult = function (event) {
163
+ let nameCaptured = event.results[0][0].transcript.trim();
164
+ document.getElementById('name').value = nameCaptured;
165
+ recognition.stop();
166
+ speak("You said " + nameCaptured + ". Is it correct?", function () {
167
+ confirmName(nameCaptured);
168
+ });
169
+ };
170
+ });
171
+ }
172
 
173
+ function confirmName(nameCaptured) {
174
+ recognition.start();
175
+ recognition.onresult = function (event) {
176
+ let confirmation = event.results[0][0].transcript.trim().toLowerCase();
177
+ recognition.stop();
178
+ if (isConfirmation(confirmation)) {
179
+ captureEmail();
180
+ } else {
181
+ captureName();
182
+ }
183
+ };
184
+ }
185
+
186
+ function captureEmail() {
187
+ speak("Now, say your email.", function () {
188
+ recognition.start();
189
+ recognition.onresult = function (event) {
190
+ let emailCaptured = event.results[0][0].transcript.trim().replace(/\bat\b/g, '@').replace(/\s+/g, '');
191
+ document.getElementById('email').value = emailCaptured;
192
+ recognition.stop();
193
+ speak("You said " + emailCaptured + ". Is it correct?", function () {
194
+ confirmEmail(emailCaptured);
195
  });
196
+ };
197
+ });
198
+ }
199
+
200
+ function confirmEmail(emailCaptured) {
201
+ recognition.start();
202
+ recognition.onresult = function (event) {
203
+ let confirmation = event.results[0][0].transcript.trim().toLowerCase();
204
+ recognition.stop();
205
+ if (isConfirmation(confirmation)) {
206
+ captureMobile();
207
+ } else {
208
+ captureEmail();
209
  }
210
+ };
211
+ }
212
 
213
+ function captureMobile() {
214
+ speak("Now, say your mobile number.", function () {
215
+ recognition.start();
216
+ recognition.onresult = function (event) {
217
+ let mobileCaptured = event.results[0][0].transcript.trim().replace(/\s+/g, '');
218
+ document.getElementById('mobile').value = mobileCaptured;
219
+ recognition.stop();
220
+ speak("You said " + mobileCaptured + ". Is it correct?", function () {
221
+ confirmMobile(mobileCaptured);
222
+ });
223
+ };
224
+ });
225
+ }
226
+
227
+ function confirmMobile(mobileCaptured) {
228
+ recognition.start();
229
+ recognition.onresult = function (event) {
230
+ let confirmation = event.results[0][0].transcript.trim().toLowerCase();
231
+ recognition.stop();
232
+ if (isConfirmation(confirmation)) {
233
+ submitRegistration();
234
+ } else {
235
+ captureMobile();
236
  }
237
+ };
238
+ }
239
+
240
+ function isConfirmation(confirmation) {
241
+ const validResponses = ["yes", "ok", "yeah", "correct", "yep"];
242
+ return validResponses.some(response => confirmation.includes(response));
243
+ }
244
 
245
+ function submitRegistration() {
246
+ const name = document.getElementById('name')?.value.trim();
247
+ const email = document.getElementById('email')?.value.trim();
248
+ const phone = document.getElementById('mobile')?.value.trim();
249
+
250
+ if (!name || !email || !phone) {
251
+ alert("Please provide all required details.");
252
+ return;
253
+ }
254
+
255
+ console.log("Sending data:", { name, email, phone });
256
+
257
+ fetch('/submit', {
258
+ method: 'POST',
259
+ headers: { 'Content-Type': 'application/json' },
260
+ body: JSON.stringify({ name, email, phone })
261
+ })
262
+ .then(response => response.json())
263
+ .then(data => {
264
+ console.log("Response Data:", data);
265
+ if (data.success) {
266
+ speak(Thank you for registering, ${name}!);
267
+ let statusText = document.getElementById('statusText');
268
+ let statusMessage = document.getElementById('statusMessage');
269
+
270
+ if (statusText && statusMessage) {
271
+ statusText.textContent = Thank you for registering, ${name}!;
272
+ statusMessage.style.display = 'block';
273
+ setTimeout(() => {
274
+ statusText.textContent = 'Submitted Successfully!';
275
+ setTimeout(() => {
276
+ window.location.reload();
277
+ }, 5000);
278
+ }, 6000);
279
+ }
280
+ } else {
281
+ speak("There was an error submitting your details. Please try again.");
282
+ let statusText = document.getElementById('statusText');
283
+ let statusMessage = document.getElementById('statusMessage');
284
+
285
+ if (statusText && statusMessage) {
286
+ statusText.textContent = 'There was an error submitting your details. Please try again.';
287
+ statusMessage.style.display = 'block';
288
+ }
289
+ }
290
+ })
291
+ .catch(error => {
292
+ console.error("Fetch Error:", error);
293
+ speak("An error occurred. Please try again.");
294
+ let statusText = document.getElementById('statusText');
295
+ let statusMessage = document.getElementById('statusMessage');
296
+
297
+ if (statusText && statusMessage) {
298
+ statusText.textContent = 'An error occurred. Please try again.';
299
+ statusMessage.style.display = 'block';
300
+ }
301
+ });
302
+ }
303
+
304
+
305
+
306
+ function speak(message, callback) {
307
+ const utterance = new SpeechSynthesisUtterance(message);
308
+ utterance.onend = function () {
309
+ if (callback) callback();
310
+ };
311
+ window.speechSynthesis.speak(utterance);
312
+ }
313
+
314
+
315
+ function captureLoginDetails() {
316
+ speak("Please say your email for login.", function () {
317
  recognition.start();
318
  recognition.onresult = function (event) {
319
  let emailCaptured = event.results[0][0].transcript.trim().replace(/\bat\b/g, '@').replace(/\s+/g, '');
320
+ document.getElementById('loginEmail').value = emailCaptured;
321
  recognition.stop();
322
  speak("You said " + emailCaptured + ". Is it correct?", function () {
323
+ confirmLoginEmail(emailCaptured);
324
  });
325
  };
326
  });
327
  }
328
 
329
+ function confirmLoginEmail(emailCaptured) {
 
330
  recognition.start();
331
  recognition.onresult = function (event) {
332
  let confirmation = event.results[0][0].transcript.trim().toLowerCase();
333
  recognition.stop();
334
  if (isConfirmation(confirmation)) {
335
+ captureLoginMobile();
336
  } else {
337
+ captureLoginDetails();
338
  }
339
  };
340
  }
341
 
342
+ function captureLoginMobile() {
 
343
  speak("Now, say your mobile number.", function () {
344
  recognition.start();
345
  recognition.onresult = function (event) {
346
  let mobileCaptured = event.results[0][0].transcript.trim().replace(/\s+/g, '');
347
+ document.getElementById('loginMobile').value = mobileCaptured;
348
  recognition.stop();
349
  speak("You said " + mobileCaptured + ". Is it correct?", function () {
350
+ confirmLoginMobile(mobileCaptured);
351
  });
352
  };
353
  });
354
  }
355
 
356
+ function confirmLoginMobile(mobileCaptured) {
 
357
  recognition.start();
358
  recognition.onresult = function (event) {
359
  let confirmation = event.results[0][0].transcript.trim().toLowerCase();
360
  recognition.stop();
361
  if (isConfirmation(confirmation)) {
362
+ submitLogin();
363
  } else {
364
+ captureLoginMobile();
365
  }
366
  };
367
  }
368
 
369
+ // function submitLogin() {
370
+ // const loginEmail = document.getElementById('loginEmail').value;
371
+ // const loginMobile = document.getElementById('loginMobile').value;
 
 
372
 
373
+ // // Simulate login check
374
+ // if (loginEmail && loginMobile) {
375
+ // window.location.href = '/menu'; // Redirect to menu after successful login
376
+ // } else {
377
+ // alert("Invalid login details. Please try again.");
378
+ // }
379
+ // }
380
+ function submitLogin() {
381
+ const loginEmail = document.getElementById('loginEmail').value;
382
+ const loginMobile = document.getElementById('loginMobile').value;
383
 
384
+ // Simulate login check by querying Salesforce
385
+ if (loginEmail && loginMobile) {
386
+ fetch('/validate-login', {
387
+ method: 'POST',
388
+ headers: { 'Content-Type': 'application/json' },
389
+ body: JSON.stringify({ email: loginEmail, mobile: loginMobile })
390
+ })
391
+ .then(response => response.json())
392
+ .then(data => {
393
+ if (data.success) {
394
+ const userName = data.name; // Retrieve the name from the response
395
+ speak(Welcome, ${userName}!); // Speak the welcome message with the user's name
396
+ window.location.href = '/menu'; // Redirect to menu after successful login
397
+ } else {
398
+ // alert("Invalid login details. Please try again.");
399
+ speak("Invalid login details. Please try again.");
400
  }
401
+ })
402
+ .catch(error => {
403
+ console.error('Login validation failed:', error);
404
+ alert("An error occurred. Please try again.");
405
+ });
406
+ } else {
407
+ alert("Please provide both email and mobile number.");
408
+ }
409
+ }
410
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
411
  window.onload = function () {
412
  askLoginOrRegister();
413
  };
414
  </script>
415
  </body>
416
+ </html>