lokesh341 commited on
Commit
af960f6
·
verified ·
1 Parent(s): 0ec8fd1

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +153 -169
templates/index.html CHANGED
@@ -125,7 +125,7 @@
125
  window.speechSynthesis.speak(speech);
126
  }
127
  function askLoginOrRegister() {
128
- speak("Welcome to Biryani Hub.Are you a new customer or an existing customer? Say 'new' to register or 'existing' to login.", function () {
129
  recognition.start();
130
  recognition.onresult = function (event) {
131
  let response = event.results[0][0].transcript.trim().toLowerCase();
@@ -152,145 +152,139 @@
152
  document.getElementById('registrationForm').style.display = 'none';
153
  document.getElementById('loginForm').style.display = 'block';
154
  }
155
- function captureName() {
156
- speak("Please say your name.", function () {
157
- recognition.start();
158
- recognition.onresult = function (event) {
159
- let nameCaptured = event.results[0][0].transcript.trim();
160
- document.getElementById('name').value = nameCaptured;
161
- recognition.stop();
162
- speak("You said " + nameCaptured + ". Is it correct?", function () {
163
- confirmName(nameCaptured);
 
 
164
  });
165
- };
166
- });
167
- }
168
- function confirmName(nameCaptured) {
169
- recognition.start();
170
- recognition.onresult = function (event) {
171
- let confirmation = event.results[0][0].transcript.trim().toLowerCase();
172
- recognition.stop();
173
- if (isConfirmation(confirmation)) {
174
- captureEmail();
175
- } else {
176
- captureName();
177
  }
178
- };
179
- }
180
- function captureEmail() {
181
- speak("Now, say your email.", function () {
182
- recognition.start();
183
- recognition.onresult = function (event) {
184
- let emailCaptured = event.results[0][0].transcript.trim().replace(/\bat\b/g, '@').replace(/\s+/g, '');
185
- document.getElementById('email').value = emailCaptured;
186
- recognition.stop();
187
- speak("You said " + emailCaptured + ". Is it correct?", function () {
188
- confirmEmail(emailCaptured);
 
 
 
 
 
 
 
 
 
 
 
 
189
  });
190
- };
191
- });
192
- }
193
- function confirmEmail(emailCaptured) {
194
- recognition.start();
195
- recognition.onresult = function (event) {
196
- let confirmation = event.results[0][0].transcript.trim().toLowerCase();
197
- recognition.stop();
198
- if (isConfirmation(confirmation)) {
199
- captureMobile();
200
- } else {
201
- captureEmail();
202
  }
203
- };
204
- }
205
- function captureMobile() {
206
- speak("Now, say your mobile number.", function () {
207
- recognition.start();
208
- recognition.onresult = function (event) {
209
- let mobileCaptured = event.results[0][0].transcript.trim().replace(/\s+/g, '');
210
- document.getElementById('mobile').value = mobileCaptured;
211
- recognition.stop();
212
- speak("You said " + mobileCaptured + ". Is it correct?", function () {
213
- confirmMobile(mobileCaptured);
 
 
 
 
 
 
 
 
 
 
 
 
214
  });
215
- };
216
- });
217
- }
218
- function confirmMobile(mobileCaptured) {
219
- recognition.start();
220
- recognition.onresult = function (event) {
221
- let confirmation = event.results[0][0].transcript.trim().toLowerCase();
222
- recognition.stop();
223
- if (isConfirmation(confirmation)) {
224
- submitRegistration();
225
- } else {
226
- captureMobile();
227
  }
228
- };
229
- }
230
- function isConfirmation(confirmation) {
231
- const validResponses = ["yes", "ok", "yeah", "correct", "yep"];
232
- return validResponses.some(response => confirmation.includes(response));
233
- }
234
- function submitRegistration() {
235
- const name = document.getElementById('name')?.value.trim();
236
- const email = document.getElementById('email')?.value.trim();
237
- const phone = document.getElementById('mobile')?.value.trim();
238
- if (!name || !email || !phone) {
239
- alert("Please provide all required details.");
240
- return;
241
- }
242
- console.log("Sending data:", { name, email, phone });
243
- fetch('/submit', {
244
- method: 'POST',
245
- headers: { 'Content-Type': 'application/json' },
246
- body: JSON.stringify({ name, email, phone })
247
- })
248
- .then(response => response.json())
249
- .then(data => {
250
- console.log("Response Data:", data);
251
- if (data.success) {
252
- speak(`Thank you for registering, ${name}!`);
253
- let statusText = document.getElementById('statusText');
254
- let statusMessage = document.getElementById('statusMessage');
255
-
256
- if (statusText && statusMessage) {
257
- statusText.textContent = `Thank you for registering, ${name}!`;
258
- statusMessage.style.display = 'block';
259
- setTimeout(() => {
260
- statusText.textContent = 'Submitted Successfully!';
261
- setTimeout(() => {
262
- window.location.reload();
263
- }, 5000);
264
- }, 6000);
265
- }
266
- } else {
267
- speak("There was an error submitting your details. Please try again.");
268
- let statusText = document.getElementById('statusText');
269
- let statusMessage = document.getElementById('statusMessage');
270
- if (statusText && statusMessage) {
271
- statusText.textContent = 'There was an error submitting your details. Please try again.';
272
- statusMessage.style.display = 'block';
273
- }
274
  }
275
- })
276
- .catch(error => {
277
- console.error("Fetch Error:", error);
278
- speak("An error occurred. Please try again.");
279
- let statusText = document.getElementById('statusText');
280
- let statusMessage = document.getElementById('statusMessage');
281
- if (statusText && statusMessage) {
282
- statusText.textContent = 'An error occurred. Please try again.';
283
- statusMessage.style.display = 'block';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
  }
285
- });
286
- }
287
- function speak(message, callback) {
288
- const utterance = new SpeechSynthesisUtterance(message);
289
- utterance.onend = function () {
290
- if (callback) callback();
291
- };
292
- window.speechSynthesis.speak(utterance);
293
- }
294
  function captureLoginDetails() {
295
  speak("Please say your email for login.", function () {
296
  recognition.start();
@@ -341,45 +335,35 @@ function speak(message, callback) {
341
  }
342
  };
343
  }
344
- // function submitLogin() {
345
- // const loginEmail = document.getElementById('loginEmail').value;
346
- // const loginMobile = document.getElementById('loginMobile').value;
347
- // // Simulate login check
348
- // if (loginEmail && loginMobile) {
349
- // window.location.href = '/menu'; // Redirect to menu after successful login
350
- // } else {
351
- // alert("Invalid login details. Please try again.");
352
- // }
353
- // }
354
- function submitLogin() {
355
- const loginEmail = document.getElementById('loginEmail').value;
356
- const loginMobile = document.getElementById('loginMobile').value;
357
- // Simulate login check by querying Salesforce
358
- if (loginEmail && loginMobile) {
359
- fetch('/validate-login', {
360
- method: 'POST',
361
- headers: { 'Content-Type': 'application/json' },
362
- body: JSON.stringify({ email: loginEmail, mobile: loginMobile })
363
- })
364
- .then(response => response.json())
365
- .then(data => {
366
- if (data.success) {
367
- const userName = data.name; // Retrieve the name from the response
368
- speak(`Welcome, ${userName}!`); // Speak the welcome message with the user's name
369
- window.location.href = '/menu'; // Redirect to menu after successful login
370
  } else {
371
- // alert("Invalid login details. Please try again.");
372
- speak("Invalid login details. Please try again.");
373
  }
374
- })
375
- .catch(error => {
376
- console.error('Login validation failed:', error);
377
- alert("An error occurred. Please try again.");
378
- });
379
- } else {
380
- alert("Please provide both email and mobile number.");
381
- }
382
- }
383
  window.onload = function () {
384
  askLoginOrRegister();
385
  };
 
125
  window.speechSynthesis.speak(speech);
126
  }
127
  function askLoginOrRegister() {
128
+ speak("Welcome to Biryani Hub. Are you a new customer or an existing customer? Say 'new' to register or 'existing' to login.", function () {
129
  recognition.start();
130
  recognition.onresult = function (event) {
131
  let response = event.results[0][0].transcript.trim().toLowerCase();
 
152
  document.getElementById('registrationForm').style.display = 'none';
153
  document.getElementById('loginForm').style.display = 'block';
154
  }
155
+ function captureName() {
156
+ speak("Please say your name.", function () {
157
+ recognition.start();
158
+ recognition.onresult = function (event) {
159
+ let nameCaptured = event.results[0][0].transcript.trim();
160
+ document.getElementById('name').value = nameCaptured;
161
+ recognition.stop();
162
+ speak("You said " + nameCaptured + ". Is it correct?", function () {
163
+ confirmName(nameCaptured);
164
+ });
165
+ };
166
  });
 
 
 
 
 
 
 
 
 
 
 
 
167
  }
168
+ function confirmName(nameCaptured) {
169
+ recognition.start();
170
+ recognition.onresult = function (event) {
171
+ let confirmation = event.results[0][0].transcript.trim().toLowerCase();
172
+ recognition.stop();
173
+ if (isConfirmation(confirmation)) {
174
+ captureEmail();
175
+ } else {
176
+ captureName();
177
+ }
178
+ };
179
+ }
180
+ function captureEmail() {
181
+ speak("Now, say your email.", function () {
182
+ recognition.start();
183
+ recognition.onresult = function (event) {
184
+ let emailCaptured = event.results[0][0].transcript.trim().replace(/\bat\b/g, '@').replace(/\s+/g, '');
185
+ document.getElementById('email').value = emailCaptured;
186
+ recognition.stop();
187
+ speak("You said " + emailCaptured + ". Is it correct?", function () {
188
+ confirmEmail(emailCaptured);
189
+ });
190
+ };
191
  });
 
 
 
 
 
 
 
 
 
 
 
 
192
  }
193
+ function confirmEmail(emailCaptured) {
194
+ recognition.start();
195
+ recognition.onresult = function (event) {
196
+ let confirmation = event.results[0][0].transcript.trim().toLowerCase();
197
+ recognition.stop();
198
+ if (isConfirmation(confirmation)) {
199
+ captureMobile();
200
+ } else {
201
+ captureEmail();
202
+ }
203
+ };
204
+ }
205
+ function captureMobile() {
206
+ speak("Now, say your mobile number.", function () {
207
+ recognition.start();
208
+ recognition.onresult = function (event) {
209
+ let mobileCaptured = event.results[0][0].transcript.trim().replace(/\s+/g, '');
210
+ document.getElementById('mobile').value = mobileCaptured;
211
+ recognition.stop();
212
+ speak("You said " + mobileCaptured + ". Is it correct?", function () {
213
+ confirmMobile(mobileCaptured);
214
+ });
215
+ };
216
  });
 
 
 
 
 
 
 
 
 
 
 
 
217
  }
218
+ function confirmMobile(mobileCaptured) {
219
+ recognition.start();
220
+ recognition.onresult = function (event) {
221
+ let confirmation = event.results[0][0].transcript.trim().toLowerCase();
222
+ recognition.stop();
223
+ if (isConfirmation(confirmation)) {
224
+ submitRegistration();
225
+ } else {
226
+ captureMobile();
227
+ }
228
+ };
229
+ }
230
+ function isConfirmation(confirmation) {
231
+ const validResponses = ["yes", "ok", "yeah", "correct", "yep"];
232
+ return validResponses.some(response => confirmation.includes(response));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233
  }
234
+ function submitRegistration() {
235
+ const name = document.getElementById('name')?.value.trim();
236
+ const email = document.getElementById('email')?.value.trim();
237
+ const phone = document.getElementById('mobile')?.value.trim();
238
+ if (!name || !email || !phone) {
239
+ alert("Please provide all required details.");
240
+ return;
241
+ }
242
+ console.log("Sending data:", { name, email, phone });
243
+ fetch('/submit', {
244
+ method: 'POST',
245
+ headers: { 'Content-Type': 'application/json' },
246
+ body: JSON.stringify({ name, email, phone })
247
+ })
248
+ .then(response => response.json())
249
+ .then(data => {
250
+ console.log("Response Data:", data);
251
+ if (data.success) {
252
+ speak(`Thank you for registering, ${name}!`);
253
+ speak(`Hi ${name}, Welcome to Biryani Hub. Speak out.`);
254
+ let statusText = document.getElementById('statusText');
255
+ let statusMessage = document.getElementById('statusMessage');
256
+
257
+ if (statusText && statusMessage) {
258
+ statusText.textContent = `Thank you for registering, ${name}!`;
259
+ statusMessage.style.display = 'block';
260
+ setTimeout(() => {
261
+ statusText.textContent = 'Submitted Successfully!';
262
+ setTimeout(() => {
263
+ window.location.reload();
264
+ }, 5000);
265
+ }, 6000);
266
+ }
267
+ } else {
268
+ speak("There was an error submitting your details. Please try again.");
269
+ let statusText = document.getElementById('statusText');
270
+ let statusMessage = document.getElementById('statusMessage');
271
+ if (statusText && statusMessage) {
272
+ statusText.textContent = 'There was an error submitting your details. Please try again.';
273
+ statusMessage.style.display = 'block';
274
+ }
275
+ }
276
+ })
277
+ .catch(error => {
278
+ console.error("Fetch Error:", error);
279
+ speak("An error occurred. Please try again.");
280
+ let statusText = document.getElementById('statusText');
281
+ let statusMessage = document.getElementById('statusMessage');
282
+ if (statusText && statusMessage) {
283
+ statusText.textContent = 'An error occurred. Please try again.';
284
+ statusMessage.style.display = 'block';
285
+ }
286
+ });
287
  }
 
 
 
 
 
 
 
 
 
288
  function captureLoginDetails() {
289
  speak("Please say your email for login.", function () {
290
  recognition.start();
 
335
  }
336
  };
337
  }
338
+ function submitLogin() {
339
+ const loginEmail = document.getElementById('loginEmail').value;
340
+ const loginMobile = document.getElementById('loginMobile').value;
341
+ // Simulate login check by querying Salesforce
342
+ if (loginEmail && loginMobile) {
343
+ fetch('/validate-login', {
344
+ method: 'POST',
345
+ headers: { 'Content-Type': 'application/json' },
346
+ body: JSON.stringify({ email: loginEmail, mobile: loginMobile })
347
+ })
348
+ .then(response => response.json())
349
+ .then(data => {
350
+ if (data.success) {
351
+ const userName = data.name; // Retrieve the name from the response
352
+ speak(`Welcome, ${userName}!`); // Speak the welcome message with the user's name
353
+ window.location.href = '/menu'; // Redirect to menu after successful login
354
+ } else {
355
+ // alert("Invalid login details. Please try again.");
356
+ speak("Invalid login details. Please try again.");
357
+ }
358
+ })
359
+ .catch(error => {
360
+ console.error('Login validation failed:', error);
361
+ alert("An error occurred. Please try again.");
362
+ });
 
363
  } else {
364
+ alert("Please provide both email and mobile number.");
 
365
  }
366
+ }
 
 
 
 
 
 
 
 
367
  window.onload = function () {
368
  askLoginOrRegister();
369
  };