How to use getPrompt method in Webdriverio

Best JavaScript code snippet using webdriverio-monorepo

index.js

Source:index.js Github

copy

Full Screen

...151 context.attributes.kitchenBoard = kitchen_board;152 var recipe_num = Object.keys(kitchen_board).length;153 var prompt_str = 'there are ' + recipe_num + ' recipes on your kitchen board.';154 prompt_str += ' do you want me to list em ?';155 context.emit(':ask', prompt_str, rspRandomPrompt.getPrompt('Resp_Continue_AudioOnly'));156 }157 });158 }159 });160 });161 });162 }163 });164 //finish cognito sync165 },166 'Intent_GlossaryLookup': function () {167 var helpText = this.event.request.intent.slots.helptext.value;168 console.log('Intent_GlossaryLookup Handler Generic ::: for help text :: ' + helpText);169 if (this.handler.state !== states.GLOSSARY) {170 this.attributes.goBackToState = this.handler.state;171 this.handler.state = states.GLOSSARY;172 }173 gsHelper.setLookupTerm(helpText);174 // ask the user if this is the word intended175 var printStmt = 'did you ask for <break time=\"0.1s\" /> ' + helpText + ' ?';176 this.emit(':ask', printStmt, rspRandomPrompt.getPrompt('Resp_Continue_Generic'));177 }178};179/*180 The state Glossary is a temporary state that is set upon invocation of the181 Intent_GlossaryLookup from any of the other states, typically from the INGREDIENTS state.182 The handlers shall keep a note of the previous or go-back-to state, after servicing the183 request and corresponding user dialogue.184 */185var glossaryHandlers = Alexa.CreateStateHandler(states.GLOSSARY, {186 // if ever the skill finds itself here (i.e. in NewSession with state Glossary),187 // fall back to the previous / go-back-to state188 'NewSession': function () {189 console.log('new session in GLOSSARY state!');190 this.handler.state = this.attributes.goBackToState;191 gsHelper.init();192 this.emit(':ask',193 rspRandomPrompt.getPrompt('Resp_Continue_Generic'),194 rspRandomPrompt.getPrompt('Resp_Continue_Generic'));195 },196 'AMAZON.YesIntent': function () {197 console.log('AMAZON.YesIntent Handler in state GLOSSARY:::');198 // go back to the orginal state199 this.handler.state = this.attributes.goBackToState;200 var printStmt = gsHelper.findItem();201 gsHelper.init();202 this.emit(':ask', printStmt, rspRandomPrompt.getPrompt('Resp_Continue_Generic'));203 },204 'AMAZON.NoIntent': function () {205 console.log('AMAZON.NoIntent Handler in state GLOSSARY:::');206 var promptstr = 'sorry about that. appears I did not hear you right. ';207 var repeatpromptstr = 'Ask for the term again ';208 promptstr += repeatpromptstr;209 this.emit(':ask', promptstr, repeatpromptstr);210 },211 'Intent_GlossaryLookup': function () {212 var helpText = this.event.request.intent.slots.helptext.value;213 console.log('Intent_GlossaryLookup Handler in state GLOSSARY::: for help text :: ' + helpText);214 this.emit('Intent_GlossaryLookup'); // Uses the handler in newSessionHandlers215 },216 'AMAZON.HelpIntent': function () {217 console.log('AMAZON.HelpIntent Handler in state GLOSSARY:::');218 var promptstr = 'Ask for the term by saying <break time=\"0.2s\" /> what is <break time=\"0.2s\" /> and then the term. ';219 promptstr += rspRandomPrompt.getPrompt('Resp_Continue_Generic');220 var repromptstr = 'Ask for the term again ';221 repromptstr += rspRandomPrompt.getPrompt('Resp_Continue_Generic');222 this.emit(':ask', promptstr, repeatpromptstr);223 },224 'AMAZON.CancelIntent': function () {225 console.log('AMAZON.CancelIntent Handler in state GLOSSARY:::');226 // go back to the orginal state227 this.handler.state = this.attributes.goBackToState;228 gsHelper.init();229 this.emit(':ask', rspRandomPrompt.getPrompt('Resp_Continue_Generic'));230 },231 'Unhandled': function () {232 console.log('Unhandled Handler in state GLOSSARY:::');233 // ask user if he is looking for the term, if captured already. else cancel.234 if (!gsHelper.getLookupTerm()) {235 this.handler.state = this.attributes.goBackToState;236 gsHelper.init();237 this.emit(':ask', rspRandomPrompt.getPrompt('Resp_Continue_Generic'));238 } else {239 var promptstr = 'did you ask for <break time=\"0.1s\" /> ' +240 gsHelper.getLookupTerm() + ' ?' +241 rspRandomPrompt.getPrompt('Resp_Continue_Generic');242 this.emit(':ask', promptstr);243 }244 }245});246var searchrecipesHandlers = Alexa.CreateStateHandler(states.SEARCHRECIPES, {247 'NewSession': function () {248 console.log('new session in SEARCHRECIPES state!');249 this.emit('NewSession'); // Uses the handler in newSessionHandlers250 },251 'AMAZON.YesIntent': function () {252 console.log('AMAZON.YesIntent Handler in state SEARCHRECIPES:::');253 rcpHelper.findRecipe(this.attributes.kitchenBoard);254 this.handler.state = states.TRAVERSESEARCHLIST;255 // var promptstr = rspRandomPrompt.getPrompt('Resp_RecipeSearch_Discovery_C');256 var promptstr = rcpHelper.getNextPageOfItems(PAGINATION_SIZE);257 var repeatpromptstr = 'would you like to repeat the items, or start over ?';258 console.log('AMAZON.YesIntent Handler in state SEARCHRECIPES::: NextPage items text recieved \n' + promptstr);259 // ask teh user to pick one of the choices260 this.emit(':ask', promptstr, repeatpromptstr);261 },262 'AMAZON.NoIntent': function () {263 console.log('AMAZON.NoIntent Handler in state SEARCHRECIPES:::');264 var promptstr = rspRandomPrompt.getPrompt('Resp_Resume_SearchRecipes_F');265 var repeatpromptstr = rspRandomPrompt.getPrompt('Resp_Resume_SearchRecipes_E');266 this.emit(':ask', promptstr, repeatpromptstr);267 },268 'AMAZON.HelpIntent': function () {269 console.log('AMAZON.HelpIntent Handler in state SEARCHRECIPES:::');270 },271 'AMAZON.CancelIntent': function () {272 console.log('AMAZON.CancelIntent Handler in state TRAVERSESEARCHLIST:::');273 this.handler.state = states.SEARCHRECIPES;274 this.emit(':tell', 'see you next time.');275 },276 'Intent_GlossaryLookup': function () {277 var helpText = this.event.request.intent.slots.helptext.value;278 console.log('Intent_GlossaryLookup Handler in state SEARCHRECIPES::: for help text :: ' + helpText);279 this.emit('Intent_GlossaryLookup'); // Uses the handler in newSessionHandlers280 },281 'Unhandled': function () {282 console.log('Unhandled Handler in state SEARCHRECIPES:::');283 var say_stmt = rspRandomPrompt.getPrompt('Resp_Unhandled_Discovery_A');284 var repeat_stmt = rspRandomPrompt.getPrompt('Resp_Repeat_SearchRecipes');285 if (Object.keys(this.attributes).length !== 0) {286 // we don't have a recipe yet287 repeat_stmt = rspRandomPrompt.getPrompt('Resp_Continue_Discovery');288 } else {289 say_stmt = rspRandomPrompt.getPrompt('Resp_Unhandled_Discovery_B');290 }291 this.emit(':ask', say_stmt, repeat_stmt);292 }293});294var traversesearchHandlers = Alexa.CreateStateHandler(states.TRAVERSESEARCHLIST, {295 'NewSession': function () {296 console.log('new session in TRAVERSESEARCHLIST state!');297 this.emit('NewSession'); // Uses the handler in newSessionHandlers298 },299 'Intent_ListChoice': function () {300 console.log('Intent_ListChoice Handler in state TRAVERSESEARCHLIST:::');301 var choiceNum = this.event.request.intent.slots.choicenumber.value;302 // verify that the number given as choice is a valid once303 this.attributes.currentrecipe = rcpHelper.chooseListItem(choiceNum);304 if (undefined !== this.attributes.currentrecipe) {305 this.attributes.recipename = this.attributes.currentrecipe.recipename;306 this.attributes.stepnumber = 0;307 this.handler.state = states.RECIPESELECTED;308 // prompt the309 var promptstr = rcpHelper.introRecipe();310 promptstr += ' Say describe for a description, or ';311 var promptstr2 = 'say proceed to go through the ingredients.';312 promptstr += promptstr2;313 // var cardTitle = 'Recipe for ' + rcpHelper.nameRecipe();314 var cardTitle = rcpHelper.nameRecipe();315 var cardContent = rcpHelper.describeRecipe();316 cardContent += '\n\nIngredients List:\n' + rcpHelper.currentRecipeListOfIngredients();317 // cardContent += '\n\nPreparation Steps:' + rcpHelper.currentRecipeListOfCookingSteps();318 /*319 do not add the images to teh card, as they are not converted to the required image specs320 var imageObj = {321 smallImageUrl: rcpHelper.currentRecipeSmallImageUrl(),322 largeImageUrl: rcpHelper.currentRecipeLargeImageUrl()323 };324 */325 console.log('picked the recipe with following details ' + cardContent);326 // this.emit(':askWithCard', promptstr, promptstr2, cardTitle, cardContent, imageObj);327 this.emit(':askWithCard', promptstr, promptstr2, cardTitle, cardContent);328 } else {329 this.emit(':ask',330 'choice not successful. please select again.',331 rspRandomPrompt.getPrompt('Resp_Repeat_SearchRecipes'));332 }333 },334 'AMAZON.NextIntent': function () {335 console.log('AMAZON.NextIntent Handler in state TRAVERSESEARCHLIST:::');336 // advance the list and present the choices again337 if (rcpHelper.ResultsFound() > 0) {338 var promptstr = rcpHelper.getNextPageOfItems(PAGINATION_SIZE);339 var repeatpromptstr = 'would you like to repeat the items, or start over ?';340 console.log(promptstr);341 // ask teh user to pick one of the choices342 this.emit(':ask', promptstr, repeatpromptstr);343 } else {344 // prompt for negative search345 var promptstr = 'No recipes found for the search term : ' + RecipeSearchTerm;346 var repeatpromptstr = 'would you like to cancel?';347 promptstr += repeatpromptstr;348 console.log(promptstr);349 this.emit(':ask', promptstr, repeatpromptstr);350 }351 },352 'AMAZON.RepeatIntent': function () {353 console.log('AMAZON.RepeatIntent Handler in state TRAVERSESEARCHLIST:::');354 rcpHelper.backtrackListCurrent(PAGINATION_SIZE);355 if (rcpHelper.ResultsFound() > 0) {356 var promptstr = rcpHelper.getNextPageOfItems(PAGINATION_SIZE);357 var repeatpromptstr = 'would you like to repeat the items, or start over ?';358 console.log(promptstr);359 // ask teh user to pick one of the choices360 this.emit(':ask', promptstr, repeatpromptstr);361 } else {362 // prompt for negative search363 var promptstr = 'No recipes found for the search term : ' + RecipeSearchTerm;364 var repeatpromptstr = 'would you like to cancel?';365 promptstr += repeatpromptstr;366 console.log(promptstr);367 this.emit(':ask', promptstr, repeatpromptstr);368 }369 },370 'AMAZON.StartOverIntent': function () {371 console.log('AMAZON.StartOverIntent Handler in state TRAVERSESEARCHLIST:::');372 rcpHelper.resetListCurrent();373 // advance the list and present the choices again374 if (rcpHelper.ResultsFound() > 0) {375 var promptstr = rcpHelper.getNextPageOfItems(PAGINATION_SIZE);376 var repeatpromptstr = 'would you like to repeat the items, or start over ?';377 console.log(promptstr);378 // ask teh user to pick one of the choices379 this.emit(':ask', promptstr, repeatpromptstr);380 } else {381 // prompt for negative search382 var promptstr = 'No recipes found for the search term : ' + RecipeSearchTerm;383 var repeatpromptstr = 'would you like to cancel?';384 promptstr += repeatpromptstr;385 console.log(promptstr);386 this.emit(':ask', promptstr, repeatpromptstr);387 }388 },389 'AMAZON.CancelIntent': function () {390 console.log('AMAZON.CancelIntent Handler in state TRAVERSESEARCHLIST:::');391 this.handler.state = states.SEARCHRECIPES;392 var promptstr = rspRandomPrompt.getPrompt('Resp_Resume_SearchRecipes_C');393 var repeatpromptstr = rspRandomPrompt.getPrompt('Resp_Resume_SearchRecipes_C');394 this.emit(':ask', promptstr, repeatpromptstr);395 },396 'AMAZON.HelpIntent': function () {397 console.log('AMAZON.HelpIntent Handler in state TRAVERSESEARCHLIST:::');398 },399 'Unhandled': function () {400 console.log('Unhandled Handler in state TRAVERSESEARCHLIST:::');401 this.emit(':ask'402 , rspRandomPrompt.getPrompt('Resp_Unhandled_Generic')403 , rspRandomPrompt.getPrompt('Resp_Continue_Generic')404 );405 }406});407var recipeselectedHandlers = Alexa.CreateStateHandler(states.RECIPESELECTED, {408 'NewSession': function () {409 console.log('new session in RECIPESELECTED state!');410 this.emit('NewSession'); // Uses the handler in newSessionHandlers411 },412 'AMAZON.StartOverIntent': function () {413 console.log('AMAZON.StartOverIntent Handler in state RECIPESELECTED:::');414 var promptstr = rcpHelper.introRecipe();415 promptstr += 'Say, describe for a description, or ';416 var promptstr2 = rspRandomPrompt.getPrompt('Resp_RecipeSelected_Discovery_A');417 promptstr += promptstr2;418 this.emit(':ask', promptstr, promptstr2);419 },420 // handle a request for new recipe421 'Intent_RecipeDescribe': function () {422 console.log('Intent_RecipeDescribe Handler in state RECIPESELECTED:::');423 var promptstr = rcpHelper.describeRecipe();424 promptstr += ' <break time=\"0.2s\" /> ';425 promptstr += 'there are ' + rcpHelper.currentRecipeNumberOfIngredients() + 'ingredients in this recipe. '426 var abridgedIngredientList = rcpHelper.shortListofIngredients();427 // if the number of ingredients is428 if (abridgedIngredientList.length < ALLOW_SIZE_INGREDIENTS_IN_DESCRIPTION) {429 promptstr += 'Notably <break time=\"0.2s\" /> ';430 var retstr = abridgedIngredientList.join(', '); // put in , seperating elements in the string431 promptstr += retstr.replace(/\,(?=[^,]*$)/, ", and,"); // put in an and instead of a , for the last seperator432 promptstr += ' <break time=\"0.2s\" /> ';433 }434 var promptstr2 = rspRandomPrompt.getPrompt('Resp_RecipeSelected_Discovery_A');435 promptstr += ' <break time=\"0.2s\" /> ' + promptstr2;436 this.emit(':ask', promptstr, promptstr2);437 },438 'AMAZON.RepeatIntent': function () {439 console.log('AMAZON.RepeatIntent Handler in state RECIPESELECTED:::');440 var promptstr = rcpHelper.describeRecipe();441 var promptstr2 = rspRandomPrompt.getPrompt('Resp_RecipeSelected_Discovery_A');442 promptstr += ' <break time=\"0.2s\" /> ' + promptstr2;443 this.emit(':ask', promptstr, promptstr2);444 },445 'AMAZON.NextIntent': function () {446 console.log('AMAZON.NextIntent Handler in state RECIPESELECTED:::');447 this.handler.state = states.INGREDIENTS;448 var repromptstr = rspRandomPrompt.getPrompt('Resp_Continue_Discovery_B');449 // tell the user , how many ingredients there are in this recipe at the beginning.450 var promptstr = '';451 // promptstr += rspRandomPrompt.getPrompt('Resp_Resume_Ingredients_INTRO');452 promptstr += 'There are ' + rcpHelper.currentRecipeNumberOfIngredients() + ' ingredients. ';453 promptstr += repromptstr;454 this.emit(':ask', promptstr, repromptstr);455 },456 'AMAZON.PreviousIntent': function () {457 console.log('AMAZON.PreviousIntent Handler in state RECIPESELECTED:::');458 this.handler.state = states.TRAVERSESEARCHLIST;459 rcpHelper.resetListCurrent();460 // advance the list and present the choices again461 if (rcpHelper.ResultsFound() > 0) {462 var promptstr = rcpHelper.getNextPageOfItems(PAGINATION_SIZE);463 var repeatpromptstr = 'would you like to repeat the items, or start over ?';464 console.log(promptstr);465 // ask teh user to pick one of the choices466 this.emit(':ask', promptstr, repeatpromptstr);467 } else {468 // prompt for negative search469 var promptstr = 'No recipes found for the search term : ' + RecipeSearchTerm;470 var repeatpromptstr = 'would you like to cancel?';471 promptstr += repeatpromptstr;472 console.log(promptstr);473 this.emit(':ask', promptstr, repeatpromptstr);474 }475 },476 'AMAZON.CancelIntent': function () {477 console.log('AMAZON.CancelIntent Handler in state RECIPESELECTED:::');478 // this.attributes.goBackToState = states.SEARCHRECIPES;479 this.handler.state = states.TRAVERSESEARCHLIST;480 // this.emit('NewSession'); // Uses the handler in newSessionHandlers481 // go back to the traversal of the list482 rcpHelper.resetListCurrent();483 // advance the list and present the choices again484 if (rcpHelper.ResultsFound() > 0) {485 var promptstr = rcpHelper.getNextPageOfItems(PAGINATION_SIZE);486 var repeatpromptstr = 'would you like to repeat the items, or start over ?';487 console.log(promptstr);488 // ask teh user to pick one of the choices489 this.emit(':ask', promptstr, repeatpromptstr);490 } else {491 // prompt for negative search492 var promptstr = 'No recipes found for the search term : ' + RecipeSearchTerm;493 var repeatpromptstr = 'would you like to cancel?';494 promptstr += repeatpromptstr;495 console.log(promptstr);496 this.emit(':ask', promptstr, repeatpromptstr);497 }498 },499 'AMAZON.HelpIntent': function () {500 console.log('AMAZON.HelpIntent Handler in state RECIPESELECTED:::');501 },502 'Unhandled': function () {503 console.log('Unhandled Handler in state RECIPESELECTED:::');504 this.emit(':ask'505 , rspRandomPrompt.getPrompt('Resp_Resume_Ingredients')506 + rspRandomPrompt.getPrompt('Resp_Continue_Discovery_B')507 , rspRandomPrompt.getPrompt('Resp_Continue_Discovery_B')508 );509 }510});511var ingredientsHandlers = Alexa.CreateStateHandler(states.INGREDIENTS, {512 // handle a new session513 'NewSession': function () {514 console.log('NewSession Handler in state INGREDIENTS::: \n\n' + JSON.stringify(this.attributes, null, 4));515 // we got here after teh last action sequence was prompted, and the counter incremented516 if (this.attributes.stepnumber > 0) {517 // in order to get the last statement to be repeated, need to decrement hte counter adn518 // prompt the statement. Then increment back again.519 this.attributes['stepnumber'] -= 1;520 /*521 In xyz, the <say-as interpret-as="ordinal">11</say-as> ingredient is,522 <break time=\"0.4s\" /> blah blah <break time=\"0.4s\" />523 <audio src=\"https://s3.amazonaws.com/genie.us.pepper.bucket/AudioFiles16khzMp3/Continue.mp3\" />524 */525 var promptstmt = 'In ' + this.attributes.currentrecipe.recipename +526 ', the <say-as interpret-as="ordinal">' +527 rcpHelper.currentRecipeNumberOfIngredients() +528 '</say-as> ingredient is, <break time=\"0.4s\" />' +529 this.attributes.currentrecipe.ingredients[this.attributes['stepnumber']].prompt +530 '<break time=\"0.4s\" />' +531 rspRandomPrompt.getPrompt('Resp_Continue_Ingredients');532 this.attributes['stepnumber'] += 1;533 this.emit(':ask'534 , promptstmt535 , rspRandomPrompt.getPrompt('Resp_Continue_Ingredients')536 );537 } else {538 this.emit(':ask'539 , rspRandomPrompt.getPrompt('Resp_Resume_Ingredients')540 + rspRandomPrompt.getPrompt('Resp_Resume_Ingredients_A2')541 , rspRandomPrompt.getPrompt('Resp_Continue_Ingredients')542 );543 }544 },545 // handle the request to proceed with the next ingredient description546 'AMAZON.NextIntent': function () {547 console.log('AMAZON.NextIntent Handler in state INGREDIENTS:::');548 // check if there is ingredients list present.549 if (this.attributes.currentrecipe.hasOwnProperty('ingredients')) {550 // cycle through this list551 var stepnum = this.attributes.stepnumber;552 if (stepnum < this.attributes.currentrecipe.ingredients.length) {553 // increment the step counter for the next cycle of this handler554 // this.attributes.stepnumber = stepnum + 1;555 this.attributes['stepnumber'] += 1;556 // echo the current step to the user557 var promptstmt = '';558 // prefix the ingredient number to the ingredient only 30% of the times.559 if (Math.random() < FEATURE_PROB_STEPNUMBER_UTTER) {560 promptstmt += '<say-as interpret-as="ordinal">' + (stepnum - 0 + 1) + '</say-as> ingredient <break time=\"0.4s\" /> ';561 }562 promptstmt += this.attributes.currentrecipe.ingredients[stepnum].prompt;563 promptstmt += '<break time=\"0.4s\" />' + rspRandomPrompt.getPrompt('Resp_Continue_AudioOnly');564 this.emit(':ask', promptstmt, rspRandomPrompt.getPrompt('Resp_Continue_Ingredients'));565 } else {566 // all steps completed. exit to the next state567 this.handler.state = states.COOKING;568 // intialize the step counter again, as it is reused for the preparation steps569 this.attributes.stepnumber = 0;570 var promptstmt = rspRandomPrompt.getPrompt('Resp_Resume_Ingredients_B');571 if (Math.floor(Math.random() < FEATURE_PROB_HISTORICAL_FACT)) {572 promptstmt += ' <break time=\"0.2s\" /> ';573 // promptstmt += rspRandomPrompt.getPrompt('Resp_HistoricalFacts_AudioOnly');574 promptstmt += rcpHelper.historicalFactsRecipe();575 promptstmt += ' <break time=\"0.2s\" /> ';576 }577 promptstmt += rspRandomPrompt.getPrompt('Resp_Resume_Cooking_B');578 console.log('AMAZON.NextIntent Handler in state INGREDIENTS:::' + promptstmt);579 this.emit(':ask'580 , promptstmt581 , rspRandomPrompt.getPrompt('Resp_Continue_Ingredients')582 );583 }584 } else {585 // ingredients list does not exist586 // all steps completed. exit to the next state587 this.handler.state = states.COOKING;588 // intialize the step counter again, as it is reused for the preparation steps589 this.attributes.stepnumber = 0;590 this.emit(':ask'591 , rspRandomPrompt.getPrompt('Resp_Resume_Ingredients_B')592 + rspRandomPrompt.getPrompt('Resp_Resume_Cooking_B')593 , rspRandomPrompt.getPrompt('Resp_Continue_Ingredients')594 );595 }596 },597 'AMAZON.ResumeIntent': function () {598 console.log('AMAZON.ResumeIntent Handler in state INGREDIENTS:::');599 this.emit('AMAZON.NextIntent');600 },601 // handle a request to repeat the last instruction in the list602 'AMAZON.RepeatIntent': function () {603 console.log('AMAZON.RepeatIntent Handler in state INGREDIENTS:::');604 // decrement the stepnumber by one, in case its not the first one already605 if (this.attributes['stepnumber'] > 0) {606 this.attributes['stepnumber'] -= 1;607 }608 var promptstmt = this.attributes.currentrecipe.ingredients[this.attributes['stepnumber']].prompt;609 // increment it back again , after we've made the prompt statement610 this.attributes['stepnumber'] += 1;611 this.emit(':ask'612 , rspRandomPrompt.getPrompt('Resp_Repeat_Ingredients')613 + promptstmt + rspRandomPrompt.getPrompt('Resp_Continue_AudioOnly')614 , rspRandomPrompt.getPrompt('Resp_Continue_Ingredients')615 );616 },617 'AMAZON.PreviousIntent': function () {618 console.log('AMAZON.PreviousIntent Handler in state INGREDIENTS:::');619 // decrement the stepnumber by one, in case its not the first one already620 if (this.attributes['stepnumber'] > 1) {621 this.attributes['stepnumber'] -= 2;622 }623 var promptstmt = this.attributes.currentrecipe.ingredients[this.attributes['stepnumber']].prompt;624 // increment it back again , after we've made the prompt statement625 this.attributes['stepnumber'] += 1;626 this.emit(':ask'627 , rspRandomPrompt.getPrompt('Resp_Repeat_Ingredients')628 + promptstmt + rspRandomPrompt.getPrompt('Resp_Continue_AudioOnly')629 , rspRandomPrompt.getPrompt('Resp_Continue_Ingredients')630 )631 },632 // handle request to start over the list again633 'AMAZON.StartOverIntent': function () {634 console.log('AMAZON.StartOverIntent Handler in state INGREDIENTS:::');635 // intialize the step counter again, as it is reused for the preparation steps636 this.attributes.stepnumber = 0;637 this.emit(':ask'638 , rspRandomPrompt.getPrompt('Resp_JumpToSectionStart_Ingredients')639 , rspRandomPrompt.getPrompt('Resp_Continue_Ingredients')640 );641 },642 // handle a request to skip and jump over to the cooking directions643 'Intent_JumpToDirections': function () {644 console.log('Intent_JumpToDirections Handler in state INGREDIENTS:::');645 this.handler.state = states.COOKING;646 // intialize the step counter again, as it is reused for the preparation steps647 this.attributes.stepnumber = 0;648 this.emit(':ask'649 , rspRandomPrompt.getPrompt('Resp_JumpToDirections_Ingredients')650 , rspRandomPrompt.getPrompt('Resp_Continue_Ingredients')651 );652 },653 'Intent_GlossaryLookup': function () {654 var helpText = this.event.request.intent.slots.helptext.value;655 console.log('Intent_GlossaryLookup Handler in state INGREDIENTS::: for help text :: ' + helpText);656 this.emit('Intent_GlossaryLookup'); // Uses the handler in newSessionHandlers657 },658 'Intent_SubstitutesLookup': function () {659 var substitutelookuptext = this.event.request.intent.slots.substitutelookuptext.value;660 console.log('Intent_SubstitutesLookup Handler in state INGREDIENTS::: for help text :: ' + substitutelookuptext);661 var printStmt = substituteHelper.findItem(substitutelookuptext);662 printStmt += ' <break time=\"0.2s\" /> ' + rspRandomPrompt.getPrompt('Resp_Continue_Ingredients_C');663 this.emit(':ask', printStmt, rspRandomPrompt.getPrompt('Resp_Continue_Ingredients_C'));664 },665 'Intent_OrderingIngredients': function () {666 console.log('Intent_OrderingIngredients Handler in state INGREDIENTS:::');667 this.emit(':ask'668 , rspRandomPrompt.getPrompt('Resp_OrderingIngredients_Ingredients')669 , rspRandomPrompt.getPrompt('Resp_Continue_Ingredients')670 );671 },672 'AMAZON.StopIntent': function () {673 console.log('AMAZON.StopIntent Handler in state INGREDIENTS:::');674 // this.attributes.goBackToState = states.SEARCHRECIPES;675 rcpHelper.cleanupAndReset();676 this.handler.state = states.SEARCHRECIPES;677 console.log('AMAZON.StopIntent Handler in state INGREDIENTS::: saving state ' + JSON.stringify(this.attributes, null, 4));678 this.emit(':tell', rspRandomPrompt.getPrompt('Resp_Cancel_Ingredients'));679 },680 'AMAZON.PauseIntent': function () {681 console.log('AMAZON.StopIntent Handler in state INGREDIENTS:::');682 this.emit(':tell', 'OK.');683 },684 'AMAZON.CancelIntent': function () {685 console.log('AMAZON.CancelIntent Handler in state INGREDIENTS:::');686 // this.attributes.goBackToState = states.SEARCHRECIPES;687 rcpHelper.cleanupAndReset();688 this.handler.state = states.SEARCHRECIPES;689 console.log('AMAZON.CancelIntent Handler in state INGREDIENTS::: saving state ' + JSON.stringify(this.attributes, null, 4));690 this.emit(':tell', rspRandomPrompt.getPrompt('Resp_Cancel_Ingredients'));691 },692 'ExitAndErasePersistence': function () {693 console.log('ExitToResumeIntent Handler! in state INGREDIENTS:::');694 // clean up recipe from the persistence too695 this.handler.state = states.SEARCHRECIPES;696 this.emit(':tell', 'see you next time.');697 },698 'Unhandled': function () {699 console.log('Unhandled Handler in state INGREDIENTS:::');700 var say_stmt = rspRandomPrompt.getPrompt('Resp_Unhandled_Ingredients');701 var repeat_stmt = rspRandomPrompt.getPrompt('Resp_Continue_Ingredients');702 this.emit(':ask', say_stmt, repeat_stmt);703 }704});705var cookingHandlers = Alexa.CreateStateHandler(states.COOKING, {706 // handle a new session707 'NewSession': function () {708 console.log('NewSession Handler in state COOKING::: \n\n' + JSON.stringify(this.attributes, null, 4));709 this.attributes.ignoreUnhandled = false;710 // we got here after teh last action sequence was prompted, and the counter incremented711 if (this.attributes.stepnumber > 0) {712 // in order to get the last statement to be repeated, need to decrement hte counter adn713 // prompt the statement. Then increment back again.714 this.attributes['stepnumber'] -= 1;715 /*716 In recipe xyz. Assuming you've completed the 4th step. Say next to continue.717 */718 var promptstmt = '';719 var repromptstmt = '';720 // detect if there is an early wake up detected.721 if (this.attributes.currentrecipe.cookingsteps[this.attributes['stepnumber']].hasOwnProperty('starttime')) {722 // check against the starttime723 var timeNow = Math.floor(Date.now() / 1000);724 var timeElapsedSecs = timeNow - this.attributes.currentrecipe.cookingsteps[this.attributes['stepnumber']].starttime;725 var stepDurationSecs = utilsHelper.timeDurationInSeconds(this.attributes.currentrecipe.cookingsteps[this.attributes['stepnumber']].duration);726 if (( stepDurationSecs - timeElapsedSecs ) > 120) {727 promptstmt += rspRandomPrompt.getPrompt('Resp_Resume_Cooking_D1');728 promptstmt += utilsHelper.timeInSpeechFormat(stepDurationSecs - timeElapsedSecs);729 promptstmt += rspRandomPrompt.getPrompt('Resp_Resume_Cooking_D2');730 promptstmt += '<say-as interpret-as="ordinal">' + (this.attributes['stepnumber'] - 0 + 1) + '</say-as> step. ';731 promptstmt += rspRandomPrompt.getPrompt('Resp_Resume_Cooking_D3');732 // ignore the unhandled, if there is some ambient chatter picked up733 this.attributes.ignoreUnhandled = true;734 console.log('setting hte ignoreUnhandled as TRUE');735 } else {736 promptstmt += 'Assuming you\'ve completed the <say-as interpret-as="ordinal">' +737 (this.attributes['stepnumber'] - 0 + 1) +738 '</say-as> step. Say next to continue.';739 promptstmt += rspRandomPrompt.getPrompt('Resp_Resume_Cooking_A');740 repromptstmt = rspRandomPrompt.getPrompt('Resp_Continue_Cooking');741 }742 } else {743 promptstmt += 'Assuming you\'ve completed the <say-as interpret-as="ordinal">' +744 (this.attributes['stepnumber'] - 0 + 1) +745 '</say-as> step. Say next to continue.';746 promptstmt += rspRandomPrompt.getPrompt('Resp_Resume_Cooking_A');747 repromptstmt = rspRandomPrompt.getPrompt('Resp_Continue_Cooking');748 }749 this.attributes['stepnumber'] += 1;750 this.emit(':ask', promptstmt, repromptstmt);751 } else {752 this.emit(':ask'753 , rspRandomPrompt.getPrompt('Resp_Resume_Cooking_C')754 , rspRandomPrompt.getPrompt('Resp_Continue_Cooking')755 );756 }757 },758 // handle the request to proceed with the next ingredient description759 'AMAZON.NextIntent': function () {760 console.log('AMAZON.NextIntent Handler in state COOKING:::');761 this.attributes.ignoreUnhandled = false;762 // check if there is ingredients list present.763 if (this.attributes.currentrecipe.hasOwnProperty('cookingsteps')) {764 // cycle through this list765 var stepnum = this.attributes.stepnumber;766 console.log('Intent_Continue Handler COOKING::: step number = ' + stepnum);767 if (stepnum < this.attributes.currentrecipe.cookingsteps.length) {768 console.log('Intent_Continue Handler COOKING::: about to extract promt for step number = ' + stepnum);769 // echo the current step to the user770 var promptstmt = '';771 // prefix the ingredient number to the ingredient only 30% of the times.772 if (Math.random() < FEATURE_PROB_STEPNUMBER_UTTER) {773 promptstmt += '<say-as interpret-as="ordinal">' + (stepnum - 0 + 1) + '</say-as> step <break time=\"0.4s\" /> ';774 }775 promptstmt += this.attributes.currentrecipe.cookingsteps[stepnum].prompt;776 // increment the step counter for the next cycle of this handler777 this.attributes['stepnumber'] += 1;778 if (this.attributes.currentrecipe.cookingsteps[stepnum].hasOwnProperty('duration')) {779 // if there is a duration associated, add the mention of time, start the timer and sleep780 promptstmt += ' <break time=\"0.2s\" /> '781 + 'wake me up after '782 + this.attributes.currentrecipe.cookingsteps[stepnum].duration783 + ', when you\'re ready'784 + rspRandomPrompt.getPrompt('Resp_ClockTick_AudioOnly');785 // record the start time stamp on this step to compare the return time elapsed786 this.attributes.currentrecipe.cookingsteps[stepnum].starttime = Math.floor(Date.now() / 1000);787 console.log('AMAZON.NextIntent Handler in state COOKING:::' + promptstmt);788 this.attributes.ignoreUnhandled = true; // so that the unhandled is ignored now.789 this.emit(':ask', promptstmt);790 } else {791 promptstmt += rspRandomPrompt.getPrompt('Resp_Continue_AudioOnly');792 var repromptstmt = rspRandomPrompt.getPrompt('Resp_Continue_Cooking');793 this.emit(':ask', promptstmt, repromptstmt);794 }795 } else {796 // done with the last preparation step797 console.log('Intent_Continue Handler in state COOKING::: preparation steps complete.');798 this.attributes['stepnumber'] = 0;799 this.handler.state = states.SEARCHRECIPES;800 var promptstmt = '<break time=\"0.2s\" /> Well, <break time=\"0.4s\" /> that is all for this recipe. ' +801 'By the way, <break time=\"0.4s\" /> what rating would you give this recipe? <break time=\"0.4s\" /> ' +802 'Awesome?, <break time=\"0.4s\" /> Alright? <break time=\"0.4s\" /> or horrible <break time=\"2.0s\" />Got it. ' +803 '<break time=\"0.4s\" /> We hope to see you soon for your next cooking adventure. ' +804 '<break time=\"0.4s\" /> Till then, stay healthy! <break time=\"0.4s\" /> I will leave you with a fun fact <break time=\"0.8s\" />';805 promptstmt += cuisineNuggetsHelper.randomFact(this.attributes.currentrecipe.cuisine);806 promptstmt += rspRandomPrompt.getPrompt('Resp_Resume_CloseOut');807 console.log('Intent_Continue Handler in state COOKING::: preparation steps complete.' + promptstmt);808 this.emit(':tell', promptstmt);809 }810 } else {811 console.log('Intent_Continue Handler in state COOKING::: recipe does not have preparation steps.');812 this.attributes['stepnumber'] = 0;813 this.handler.state = states.SEARCHRECIPES;814 this.emit(':tell', rspRandomPrompt.getPrompt('Resp_Resume_CloseOut'));815 }816 },817 'AMAZON.ResumeIntent': function () {818 console.log('AMAZON.ResumeIntent Handler in state COOKING:::');819 this.attributes.ignoreUnhandled = false;820 this.emit('AMAZON.NextIntent');821 },822 // handle a request to repeat the last instruction in the list823 'AMAZON.RepeatIntent': function () {824 console.log('AMAZON.RepeatIntent Handler in state COOKING:::');825 this.attributes.ignoreUnhandled = false;826 // decrement the stepnumber by one, in case its not the first one already827 if (this.attributes['stepnumber'] > 0) {828 this.attributes['stepnumber'] -= 1;829 }830 var stepnum = this.attributes.stepnumber;831 // increment the step counter for the next cycle of this handler832 // this.attributes.stepnumber = stepnum + 1;833 this.attributes['stepnumber'] += 1;834 var promptstmt = rspRandomPrompt.getPrompt('Resp_Repeat_Cooking')835 + this.attributes.currentrecipe.cookingsteps[stepnum].prompt;836 promptstmt += rspRandomPrompt.getPrompt('Resp_Continue_AudioOnly');837 var repromptstmt = rspRandomPrompt.getPrompt('Resp_Continue_Cooking');838 this.emit(':ask', promptstmt, repromptstmt);839 },840 // handle request to start over the list again841 'AMAZON.StartOverIntent': function () {842 console.log('AMAZON.StartOverIntent Handler in state COOKING:::');843 this.attributes.ignoreUnhandled = false;844 this.attributes.stepnumber = 0;845 this.emit(':ask'846 , rspRandomPrompt.getPrompt('Resp_JumpToSectionStart_Cooking')847 , rspRandomPrompt.getPrompt('Resp_Continue_Cooking')848 );849 },850 'Intent_GlossaryLookup': function () {851 this.attributes.ignoreUnhandled = false;852 var helpText = this.event.request.intent.slots.helptext.value;853 console.log('Intent_GlossaryLookup Handler in state COOKING::: for help text :: ' + helpText);854 this.emit('Intent_GlossaryLookup'); // Uses the handler in newSessionHandlers855 },856 'AMAZON.CancelIntent': function () {857 console.log('AMAZON.CancelIntent Handler in state COOKING:::');858 this.attributes.ignoreUnhandled = false;859 rcpHelper.cleanupAndReset();860 // this.attributes['stepnumber'] = 0;861 console.log('AMAZON.CancelIntent Handler in state COOKING::: saving state ' + JSON.stringify(this.attributes, null, 4));862 // clean up recipe from the persistence too863 this.handler.state = states.SEARCHRECIPES;864 // this.emit(':tell', 'see you next time.');865 this.emit(':tell', rspRandomPrompt.getPrompt('Resp_Cancel_Ingredients'));866 },867 'AMAZON.StopIntent': function () {868 console.log('AMAZON.StopIntent Handler in state COOKING:::');869 this.attributes.ignoreUnhandled = false;870 // this.attributes['stepnumber'] = 0;871 // clean up recipe from the persistence too872 this.handler.state = states.SEARCHRECIPES;873 // this.emit(':tell', 'see you next time.');874 this.emit(':tell', rspRandomPrompt.getPrompt('Resp_Cancel_Ingredients'));875 },876 'AMAZON.PauseIntent': function () {877 console.log('AMAZON.StopIntent Handler in state COOKING:::');878 this.attributes.ignoreUnhandled = false;879 this.emit(':tell', 'OK.');880 },881 // SessionEndedEvent882 'SessionEndedRequest': function () {883 console.log('SessionEndedRequest Handler in state COOKING:::');884 this.attributes.ignoreUnhandled = false;885 this.emit(':saveState', true);886 },887 'Unhandled': function () {888 if (!this.attributes.ignoreUnhandled) {889 console.log('Unhandled Handler in state COOKING:::Discovered ignoreUnhandled as FALSE');890 this.emit(':ask', rspRandomPrompt.getPrompt('Resp_Unhandled_Cooking'));891 } else {892 console.log('Unhandled Handler in state COOKING:::Discovered ignoreUnhandled as TRUE. Setting it back to FALSE, after :tell and pause');893 this.attributes.ignoreUnhandled = false;894 // this is a case only for :ask disguised as :tell for the condition in895 // early wakeup for a duration step896 this.emit(':tell', rspRandomPrompt.getPrompt('Resp_ClockTick_AudioOnly'));897 }898 }899});900var commonHandlers = {901 'Unhandled': function () {902 console.log('Unhandled Handler :::');903 this.emit(':ask'904 , rspRandomPrompt.getPrompt('Resp_Unhandled_Generic')905 , rspRandomPrompt.getPrompt('Resp_Continue_Generic')906 );907 }...

Full Screen

Full Screen

errorMessage.js

Source:errorMessage.js Github

copy

Full Screen

1import Vue from 'vue'2let checkMsg = {3 verifyMobile: (mobile) => {4 if (!mobile) {5 return Vue.$dictionary.getPrompt('promptInformation.inputMobile')6 }7 if (!(/^1(([34578]\d{9}$)|(((99)|(98)|(66))\d{8}$))/.test(mobile))) {8 return Vue.$dictionary.getPrompt('promptInformation.mobileWrongFormat')9 }10 return ''11 },12 otherMobile: (mobile) => {13 if (!mobile) {14 return Vue.$dictionary.getPrompt('promptInformation.inputMobile')15 }16 if (!(/^\d{1,14}$/.test(mobile))) {17 return Vue.$dictionary.getPrompt('promptInformation.mobileWrongFormat')18 }19 return ''20 },21 verifyFirstPassword: (firstPassword) => {22 if (!firstPassword) {23 return Vue.$dictionary.getPrompt('promptInformation.inputPwd')24 }25 if (firstPassword.length < 8 || firstPassword.length > 20) {26 return Vue.$dictionary.getPrompt('promptInformation.enterPwd')27 }28 return ''29 },30 verifyNewPassword: (firstPassword, newPassword) => {31 if (!newPassword) {32 return Vue.$dictionary.getPrompt('promptInformation.confirmPwd')33 }34 if (firstPassword !== newPassword) {35 return Vue.$dictionary.getPrompt('promptInformation.reEnter')36 }37 return ''38 },39 verifyFirstFundPwd: (firstPassword) => {40 if (!firstPassword) {41 return Vue.$dictionary.getPrompt('promptInformation.fundPwd')42 }43 if (!(/^\d{6}$/.test(firstPassword))) {44 return Vue.$dictionary.getPrompt('promptInformation.sixFundsPassword')45 }46 return ''47 },48 verifyNewFundPwd: (firstPassword, newPassword) => {49 if (!newPassword) {50 return Vue.$dictionary.getPrompt('promptInformation.confirmFundPwd')51 }52 if (firstPassword !== newPassword) {53 return Vue.$dictionary.getPrompt('promptInformation.reEnter')54 }55 return ''56 },57 verifyPwdAndFirstPwd: (password, firstPassword) => {58 if (firstPassword === password) {59 return Vue.$dictionary.getPrompt('promptInformation.oldAndNewPwd')60 }61 return ''62 },63 verifyCode: (code) => {64 if (!code) {65 return Vue.$dictionary.getPrompt('promptInformation.inputCode')66 }67 if (code.length !== 6) {68 return Vue.$dictionary.getPrompt('promptInformation.inputNumberCode')69 }70 return ''71 },72 verifyTwiceCode: (twiceMobileAuth, code) => {73 if (twiceMobileAuth && !code) {74 return Vue.$dictionary.getPrompt('promptInformation.inputCode')75 }76 if (twiceMobileAuth && !(/^\d{6}$/.test(code))) {77 return Vue.$dictionary.getPrompt('promptInformation.inputNumberCode')78 }79 if (twiceMobileAuth) {80 return ''81 }82 },83 verifyGoogleCode: (googleCode) => {84 if (!googleCode) {85 return Vue.$dictionary.getPrompt('promptInformation.inputGoogle')86 }87 if (!(/^\d{6}$/.test(googleCode))) {88 return Vue.$dictionary.getPrompt('promptInformation.inputSixGoogle')89 }90 return ''91 },92 verifyTwiceGoogleCode: (twiceGoogleAuth, googleCode) => {93 if (twiceGoogleAuth && !googleCode) {94 return Vue.$dictionary.getPrompt('promptInformation.inputGoogle')95 }96 if (twiceGoogleAuth && !(/^\d{6}$/.test(googleCode))) {97 return Vue.$dictionary.getPrompt('promptInformation.inputSixGoogle')98 }99 if (twiceGoogleAuth) {100 return ''101 }102 },103 verifyNewGoogleCode: (newGoogleCode) => {104 if (!newGoogleCode) {105 return Vue.$dictionary.getPrompt('promptInformation.inputNewGoogle')106 }107 if (!(/^\d{6}$/.test(newGoogleCode))) {108 return Vue.$dictionary.getPrompt('promptInformation.inputSixGoogle')109 }110 return ''111 },112 verifyEmail: (email) => {113 if (!email) {114 return Vue.$dictionary.getPrompt('promptInformation.inputEmail')115 }116 if (!(/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(email))) {117 return Vue.$dictionary.getPrompt('promptInformation.inputEmailFormat')118 }119 return ''120 },121 verifyAccount: (account) => {122 if (!account) {123 return Vue.$dictionary.getPrompt('promptInformation.resetAccount')124 } else if ((account.length <= 14) || (/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(account))) {125 return ''126 } else {127 return Vue.$dictionary.getPrompt('promptInformation.mobileOrEmailFormat')128 }129 },130 verifyMobileAccount: (account) => {131 if (!account) {132 return Vue.$dictionary.getPrompt('promptInformation.loginAccount')133 } else if ((account.length <= 14) || (/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(account))) {134 return ''135 } else {136 return Vue.$dictionary.getPrompt('promptInformation.mobileOrEmailFormat')137 }138 },139 verifyIdCard: (identityNo) => {140 if (!identityNo) {141 return Vue.$dictionary.getPrompt('promptInformation.inputIdNumber')142 }143 if (!(/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/.test(identityNo))) {144 return Vue.$dictionary.getPrompt('promptInformation.idNumberFormatError')145 }146 return ''147 },148 verifyLicenseNumber: (identityNo) => {149 if (!identityNo) {150 return Vue.$dictionary.getPrompt('promptInformation.licenseNumber')151 }152 if (!(/^[a-z0-9]+$/i).test(identityNo)) {153 return Vue.$dictionary.getPrompt('promptInformation.licenseNumberError')154 }155 return ''156 },157 verifyRealName: (realName) => {158 if (!realName) {159 return Vue.$dictionary.getPrompt('promptInformation.inputName')160 }161 return ''162 },163 checkHighAuth: (fileName, fileNameError) => {164 if (fileName && fileNameError) {165 return ''166 } else {167 return false168 }169 },170 verifyHighAuth: (fileNameOne, fileNameTwo, fileNameThree) => {171 // if (!fileNameOne || !fileNameTwo || !fileNameThree) {172 // return '请先上传证件照!'173 // }174 if (!fileNameOne) {175 return Vue.$dictionary.getPrompt('promptInformation.firstIdPhoto')176 }177 if (!fileNameTwo) {178 return Vue.$dictionary.getPrompt('promptInformation.secondIdPhoto')179 }180 if (!fileNameThree) {181 return Vue.$dictionary.getPrompt('promptInformation.thirdIdPhoto')182 }183 return ''184 },185 verifyCheckOne: (checkedOne) => {186 if (!checkedOne) {187 return Vue.$dictionary.getPrompt('promptInformation.companyStatement')188 }189 return ''190 },191 verifyCheck: (checked) => {192 if (!checked) {193 return Vue.$dictionary.getPrompt('promptInformation.companyStatement')194 }195 return ''196 },197 verifyApiName: (apiName) => {198 if (!apiName) {199 return Vue.$dictionary.getPrompt('promptInformation.inputRemarks')200 }201 return ''202 },203 isIdCard: (cardid) => {204 // 身份证正则表达式(18位)205 let isIdCard2 = /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/206 let stard = '10X98765432' // 最后一位身份证的号码207 let first = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2] // 1-17系数208 let sum = 0209 if (!isIdCard2.test(cardid)) {210 return false211 }212 let year = cardid.substr(6, 4)213 let month = cardid.substr(10, 2)214 let day = cardid.substr(12, 2)215 let birthday = cardid.substr(6, 8)216 // 校验日期是否合法217 if (birthday !== checkMsg.dateToString(new Date(year + '/' + month + '/' + day))) {218 return false219 }220 for (let i = 0; i < cardid.length - 1; i++) {221 sum += cardid[i] * first[i]222 }223 let result = sum % 11224 let last = stard[result] // 计算出来的最后一位身份证号码225 if (cardid[cardid.length - 1].toUpperCase() === last) {226 return true227 } else {228 return false229 }230 },231 // 日期转字符串 返回日期格式20080808232 dateToString: (date) => {233 if (date instanceof Date) {234 let year = date.getFullYear()235 let month = date.getMonth() + 1236 month = month < 10 ? '0' + month : month237 let day = date.getDate()238 day = day < 10 ? '0' + day : day239 return year.toString() + month.toString() + day.toString()240 }241 return ''242 },243 // 提现金额验证244 getMoneyVerity: (num, maxNum, highAuth, videoAuth) => {245 if (!num) return Vue.$dictionary.getPrompt('promptInformation.withdrawalAmount')246 if (!/^\d*(?:\.\d{0, 2})?$/.test(num)) {247 return Vue.$dictionary.getPrompt('promptInformation.twoDecimalPlaces')248 } else if (num < 100) {249 return Vue.$dictionary.getPrompt('promptInformation.minimumCash')250 } else if (num > maxNum) {251 return Vue.$dictionary.getPrompt('promptInformation.amountLimit')252 } else if (!highAuth) {253 return Vue.$dictionary.getPrompt('promptInformation.advancedCertification')254 } else if (num > 5000 && !videoAuth) {255 return Vue.$dictionary.getPrompt('promptInformation.videoCertification')256 } else {257 return ''258 }259 },260 // 验证资金密码261 moneyPwdVerity: (pwd) => {262 if (!pwd) {263 return Vue.$dictionary.getPrompt('promptInformation.fundPwd')264 }265 if (!(/^\d{6}$/.test(pwd))) {266 return Vue.$dictionary.getPrompt('promptInformation.fundPwdError')267 }268 return ''269 },270 // 验证数字271 numberVerity: (num) => {272 if (!num) {273 return Vue.$dictionary.getPrompt('promptInformation.inputNumber')274 }275 if (!/^\d*(?:\.\d{0, 2})?$/.test(num)) {276 return Vue.$dictionary.getPrompt('promptInformation.twoDecimalPlaces')277 }278 return ''279 },280 // 验证数字281 numberEightVerity: (value, num = 8) => {282 if (!value || !Number(value)) {283 return Vue.$dictionary.getPrompt('promptInformation.greaterThanZero')284 }285 let rg = new RegExp('^[0-9]{0, 8}([.]{1}[0-9]{0, " + num + "}){0, 1}$')286 if (!rg.test(value)) {287 return Vue.$dictionary.getPrompt('promptInformation.eightDecimals1') + num + Vue.$dictionary.getPrompt('promptInformation.eightDecimals2')288 }289 return ''290 },291 bankVerity: (num) => {292 if (!num) {293 return Vue.$dictionary.getPrompt('promptInformation.inputBankCard')294 }295 let odd = 0296 let even = 0297 let n = 0298 for (let i = num.length; i--;) {299 n = Number(num.slice(i, i + 1))300 if (isNaN(n)) {301 return Vue.$dictionary.getPrompt('promptInformation.bankCardError')302 }303 if ((num.length - i) % 2) {304 odd += n305 } else {306 n *= 2307 if (n.toString().length === 2) {308 n -= 9309 }310 even += n311 }312 }313 if ((odd + even) % 10) {314 return Vue.$dictionary.getPrompt('promptInformation.bankCardError')315 }316 return ''317 }318}...

Full Screen

Full Screen

script.js

Source:script.js Github

copy

Full Screen

...14 let isMessageValid = false;15 /**16 * getPrompt Function - produces the message at the element id in the specific color17 */18 function getPrompt(message, prompt_location, color) {19 document.getElementById(prompt_location).innerHTML = message;20 document.getElementById(prompt_location).style.color = color;21 } //end of getPrompt function22 /**23 * checkNameInput function - Validates that user has entered a valid first and last24 * name in the specified input field.25 */26 function checkNameInput() {27 let name = $('#icon_prefix').val();28 let message = "";29 if (name.length === 0) {30 message = "Your first and last name is required!";31 isNameValid = false;32 getPrompt(message, "contact__form--name-prompt", red);33 return false;34 }35 if (!name.match(name_pattern)) {36 message = "Enter first and last name only!";37 isNameValid = false;38 getPrompt(message, "contact__form--name-prompt", red);39 return false;40 }41 message = "Welcome " + name;42 isNameValid = true;43 getPrompt(message, "contact__form--name-prompt", green);44 return true;45 } //end of the checkNameInput Function46 /**47 * checkPhoneInput function - Validates that user has entered a valid phone number48 * in the specified input field.49 */50 function checkPhoneInput() {51 let message = "";52 let phone = $('#icon_telephone').val();53 if (phone.length === 0) {54 message = "Your phone number is optional!";55 isPhoneValid = true;56 getPrompt(message, "contact__form--phone-prompt", green);57 return true;58 }59 if (!phone.match(phone_pattern)){60 message = "Preferred pattern is: 123-456-7890!";61 isPhoneValid = false;62 getPrompt(message, "contact__form--phone-prompt", red);63 return false;64 }65 message = "Valid phone number";66 getPrompt(message, "contact__form--phone-prompt", green);67 isPhoneValid = true;68 return true;69 }//end of the checkPhoneInput Function70 /**71 * checkEmailInput function - Validates that user has entered a valid email in the72 * specified input field.73 */74 function checkEmailInput() {75 let email = $('#email').val();76 let message = "";77 if (email.length === 0) {78 message = "Your email address is required!";79 isEmailValid = false;80 getPrompt(message, "contact__form--email-prompt", red);81 return false;82 }83 if (!email.match(email_pattern)) {84 message = "Invalid email address!";85 isEmailValid = false;86 getPrompt(message, "contact__form--email-prompt", red);87 return false;88 }89 message = "Valid email address";90 isEmailValid = true;91 getPrompt(message, "contact__form--email-prompt", green);92 return true;93 } //end of the checkEmailInput Function94 /**95 * checkMessageInput function - Validates that user has entered a valid message with the96 * required characters in the specified input field.97 */98 function checkMessageInput() {99 let form_message = $("#textarea1").val();100 let characters_left = (required_message_length - form_message.length);101 let message = "";102 if (form_message.length < required_message_length) {103 message = characters_left + " more characters required in message!";104 isMessageValid = false;105 getPrompt(message, "contact__form--message-prompt", red);106 return false;107 } else {108 message = "Valid message";109 isMessageValid = true;110 getPrompt(message, "contact__form--message-prompt", green);111 return true;112 }113 } //end of the checkMessageInput Function114 /**115 * performValidForm function - Validates that user has entered a valid input in all116 * of the input fields and textarea.117 */118 function performValidForm() {119 $('#contact__form--submit').val('Valid Form');120 $('#contact__form--submit').addClass('valid');121 if ($('#contact__form--submit').hasClass('submitted')) {122 $('#contact__form--submit').val('Form has been sent!');123 }124 if (!$('#contact__form--submit').hasClass('submitted')) {125 $('#error__message').hide(500);126 setTimeout(function () {127 $('#contact__form--submit').val('Sending Message...');128 }, 500);129 if ($('#contact__form--submit').hasClass('valid')) {130 setTimeout(function () {131 $('#contact__form--submit').val('Message Sent');132 $('#success__message').show(1000);133 }, 3000);134 }135 resetForm();136 }137 } //end of the performValidForm Function138 /**139 * performInvalidForm function - performs invalid message when user has entered140 * invalid input in any of input fields and textarea.141 */142 function performInvalidForm() {143 $('#contact__form--submit').val('Check Form & Click Again!');144 $('#contact__form--submit').removeClass('valid');145 updateErrors();146 $('#success__message').hide(250);147 $('#error__message').show(1250);148 $('#error__message').effect('shake', {149 times: 5150 }, 1000);151 } //end of the performInvalidForm Function152 /**153 * updateErrors function - update the message in the error message id when user154 * has entered invalid input in any input fields and textarea.155 */156 function updateErrors() {157 let message = "";158 $('#error__message').html(`<h4>Error!</h4>159 <p>The following are error(s) in the form:</p>`);160 if (!isNameValid) {161 if ($('#icon_prefix').val().length === 0) {162 $('#error__message').append(`<p>Your first and last name is required!!</p>`);163 message = "Your first and last name is required!";164 getPrompt(message, "contact__form--name-prompt", red);165 } else {166 $('#error__message').append(`<p>Enter first and last name only!!</p>`);167 message = "Enter first and last name only!";168 getPrompt(message, "contact__form--name-prompt", red);169 }170 }171 if (!isPhoneValid) {172 if ($('#icon_telephone').val().length === 0) {173 message = "Your phone number is optional!";174 getPrompt(message, "contact__form--phone-prompt", green);175 } else {176 $('#error__message').append(`<p>Preferred phone pattern is: 123-456-7890!!</p>`);177 message = "Preferred pattern is: 123-456-7890!";178 getPrompt(message, "contact__form--phone-prompt", red);179 }180 }181 if (!isEmailValid) {182 if ($('#email').val().length === 0) {183 $('#error__message').append(`<p>Your email address is required!!</p>`);184 message = "Your email address is required!";185 getPrompt(message, "contact__form--email-prompt", red);186 } else {187 $('#error__message').append(`<p>Your email address is Invalid!!</p>`);188 message = "Invalid email address!";189 getPrompt(message, "contact__form--email-prompt", red);190 }191 }192 if (!isMessageValid) {193 let characters_left = (required_message_length - $('#textarea1').val().length);194 let messageData = characters_left + " more characters required in message!!";195 $('#error__message').append(`<p>${messageData}</p>`);196 message = characters_left + " more characters required in message!";197 getPrompt(message, "contact__form--message-prompt", red);198 }199 } //end of the updateErrors Function200 /**201 * checkFormValidation Function - Checks whether the form is valid or not. If the202 * form is valid, it calls the performValidForm function; otherwise, it call the203 * performInvalidForm function.204 */205 function checkFormValidation() {206 if (isNameValid && isPhoneValid && isEmailValid && isMessageValid) {207 performValidForm();208 } else {209 performInvalidForm();210 }211 } //end of the checkFormValidation Function212 /**213 * resetForm Function - Resets the form after it call the performValidForm function.214 */215 function resetForm() {216 let message = null;217 let color = null;218 $('#contact__form input[type="text"]').val('').focus(null).removeClass('focus-visible');219 getPrompt(message, "contact__form--name-prompt", color);220 $('#contact__form #name__label').removeClass('active');221 $('#contact__form input[type="tel"]').val('').focus(null).removeClass('focus-visible');222 getPrompt(message, "contact__form--phone-prompt", color);223 $('#contact__form #phone__label').removeClass('active');224 $('#contact__form input[type="email"]').val('').focus(null).removeClass('focus-visible');225 getPrompt(message, "contact__form--email-prompt", color);226 $('#contact__form #email__label').removeClass('active');227 $('#contact__form #textarea1').val('').focus(null).removeClass('focus-visible');228 getPrompt(message, "contact__form--message-prompt", color);229 $('#contact__form #message__label').removeClass('active');230 $('#contact__form--submit').addClass('submitted');231 }232 $('#icon_prefix').keyup(checkNameInput);233 $('#icon_telephone').keyup(checkPhoneInput);234 $('#email').keyup(checkEmailInput);235 $('#textarea1').keyup(checkMessageInput);236 $('#contact__form--submit').click(checkFormValidation);...

Full Screen

Full Screen

create.js

Source:create.js Github

copy

Full Screen

...35 const found_team = utils.teamValidation(conv, 36 params.team_name); 37 if(!found_team){38 conv.contexts.set(CONTEXTS.select_team.name, 1);39 return conv.ask(utils.getPrompt(conv, 40 'select_team', conv.data.db_teams));41 }42 else{43 conv.data.current_team = found_team;44 }45 }46 //team selected47 const today = utils.getTodaysDate();48 console.log('today: ' + today);49 conv.data.entry = templates.entry;50 conv.data.entry.user = conv.data.db_user;51 conv.data.entry.date = today;52 conv.data.entry.team = conv.data.current_team;53 const payload = conv.user.profile.payload;54 const email = payload.email; 55 56 try{57 //get entry from db for team for today58 const rs = await axios.get(backend+'standup/' + today + '/team/' + 59 conv.data.current_team.teamName );60 console.log(rs.data);61 const todays_entries = rs.data.standups;62 var entry = '';63 for(const standup of todays_entries){64 if(standup.user.email == email){65 entry = standup;66 } 67 }68 if(entry != ''){69 conv.data.update = 1;70 conv.data.entry = entry;71 conv.data.myContext = CONTEXTS.submit_review;72 conv.contexts.set(CONTEXTS.submit_review.name, 1);73 conv.contexts.set(CONTEXTS.today.name, 0);74 return conv.ask(utils.getPrompt(75 conv, 'already_existing', conv.data.current_team));76 }77 }catch(error){78 console.log('error in create: ' + error);79 //return conv.ask(utils.getPrompt(conv, 'http_error'));80 }81 conv.data.update = 0;82 conv.contexts.set(CONTEXTS.today.name, 1);83 return conv.ask(utils.getPrompt(conv, 'today'));84 },85 //accepts any speech, saves it86 'create_did_today' : (conv) => {87 console.log("in today");88 console.log(conv.input.raw);89 conv.data.myContext = CONTEXTS.tomorrow;90 conv.contexts.set(CONTEXTS.redo.name, 1);91 conv.data.redo_flag = 1;92 93 conv.data.entry.todayText = conv.input.raw;94 return conv.ask(utils.getPrompt(conv, 'tomorrow'));95 },96 //accepts any speech, saves it97 'create_do_tomorrow' : (conv) => {98 conv.data.myContext = CONTEXTS.blocking_choice;99 console.log("in tomorrow");100 console.log(conv.input.raw);101 console.log(conv.data);102 conv.contexts.set(CONTEXTS.redo.name, 1);103 conv.data.redo_flag = 2;104 conv.data.entry.tomorrowText = conv.input.raw;105 return conv.ask(utils.getPrompt(conv, 'blocking_choice'));106 },107 'create_blocking_yes' : (conv) => {108 conv.data.myContext = CONTEXTS.blocking_content;109 console.log("in blocking yes");110 conv.contexts.set(CONTEXTS.redo.name, 1);111 conv.data.redo_flag = 3;112 return conv.ask(utils.getPrompt(conv, 'blocking_yes'));113 },114 //User now either submits, reviews or exits115 'create_blocking_no' : (conv) => {116 conv.data.myContext = CONTEXTS.submit_review;117 console.log("in blocking no");118 conv.contexts.set(CONTEXTS.redo.name, 1);119 conv.data.redo_flag = 3;120 conv.data.entry.blockingText = '';121 return conv.ask(utils.getPrompt(conv, 'submit_review'));122 },123 //accepts any speech, saves it. User now either submits, reviews or exits124 'create_blocking_content' : (conv) => {125 conv.data.myContext = CONTEXTS.submit_review;126 console.log("in blocking content");127 console.log(conv.input.raw);128 console.log(conv.data);129 conv.data.entry.blockingText = conv.input.raw;130 conv.contexts.set(CONTEXTS.redo.name, 1);131 conv.data.redo_flag = 3;132 return conv.ask(utils.getPrompt(conv, 'submit_review'));133 },134 'create_redo': (conv) => {135 if(conv.data.redo_flag == 1){136 console.log('redo 1');137 conv.data.myContext = CONTEXTS.today;138 conv.contexts.set(CONTEXTS.today.name, 1);139 return conv.ask(utils.getPrompt(conv, 'today')); 140 141 }142 else if(conv.data.redo_flag == 2){143 console.log('redo 2');144 conv.data.myContext = CONTEXTS.tomorrow;145 conv.contexts.set(CONTEXTS.tomorrow.name, 1);146 return conv.ask(utils.getPrompt(conv, 'tomorrow')); 147 }148 else if(conv.data.redo_flag == 3){149 console.log('redo 3');150 conv.data.myContext = CONTEXTS.blocking_choice;151 conv.contexts.set(CONTEXTS.blocking_choice.name, 1);152 return conv.ask(utils.getPrompt(conv, 'blocking_choice')); 153 }154 else{155 console.log('redo x');156 conv.data.current_team = null;157 conv.data.myContext = CONTEXTS.menu;158 conv.contexts.set(CONTEXTS.menu.name, 1);159 return conv.ask(utils.getPrompt(conv, 'invalid_redo')); 160 }161 },162 'create_edit': (conv, params) => {163 conv.data.edit_choice = params.edit_choice;164 if(params.edit_choice == 'today' || params.edit_choice == 'tomorrow'){165 conv.data.myContext = CONTEXTS.editing;166 conv.contexts.set(CONTEXTS.editing.name, 1);167 return conv.ask(utils.getPrompt(conv, 'edit')); 168 }169 if(params.edit_choice == 'blocking'){170 conv.data.myContext = CONTEXTS.blocking_choice;171 conv.contexts.set(CONTEXTS.blocking_choice.name, 1);172 return conv.ask(utils.getPrompt(conv, 'blocking_choice')); 173 }174 175 conv.data.myContext = CONTEXTS.submit_review;176 conv.contexts.set(CONTEXTS.blocking_choice.name, 1);177 return conv.ask(utils.getPrompt(conv, 'today')); 178 },179 'create_editing' : (conv) => {180 const input = conv.input.raw;181 if(conv.data.edit_choice == 'today'){182 conv.data.entry.todayText = input;183 }184 if(conv.data.edit_choice == 'tomorrow'){185 conv.data.entry.tomorrowText = input;186 }187 conv.data.myContext = CONTEXTS.submit_review;188 conv.contexts.set(CONTEXTS.blocking_choice.name, 1);189 return conv.ask(utils.getPrompt(conv, 'edit_done')); 190 },191 'create_review' : (conv) => {192 conv.data.myContext = CONTEXTS.submit_review;193 console.log("in submit review");194 console.log(conv.data);195 return conv.ask(utils.getPrompt(conv, 'review', conv.data.entry));196 },197 //tries to post entry to db, replies to the198 //user whether it was successful or not199 'create_submit' : async (conv) => {200 conv.data.myContext = CONTEXTS.menu;201 console.log("in submit yes");202 console.log(conv.data);203 //post standup entry204 try{205 var rs = '';206 if(conv.data.update){207 rs = await axios.put(backend + 'entry/' + 208 conv.data.entry.standupEntryID, conv.data.entry);209 }...

Full Screen

Full Screen

challenge5.js

Source:challenge5.js Github

copy

Full Screen

1/*2const arrAvg = arr => arr.reduce((a,b) => a + b, 0) / arr.length;3const arrSum = arr => arr.reduce((a,b) => a + b, 0);4function getPrompt(val,valu) {5var getValu = prompt(val,valu);6return getValu;7}8*/9var john = {10 fullName: getPrompt("What is your name?","John Smith"),11 bills: [], //[124, 48, 268, 180, 42],12 getBill: function() {13 var getBillsQty = getPrompt("How many bills do you have, " + this.fullName + "?", "5");14 getBillsQty = parseInt(getBillsQty);15 if (getBillsQty >= 0) {16 for (let i = 1; i <= getBillsQty; i++) {17 var getBill = getPrompt("How much was bill number " + i + "?","124");18 this.bills.push(getBill);19 }20 }21 this.tips = [];22 this.finalValues = [];23 // Determine tipping rules in order to determine percentage24 var inc1 = getPrompt("What is the highest percentage you would pay for a tip?","20"),25 lowAmt1 = getPrompt("What would the lowest amount be you would willing to pay that tip to?"),26 hiAmt1 = getPrompt("What would the highest amount you would be willing to pay that tip to?", "50"),27 inc2 = getPrompt("What is the highest percentage you would pay for a tip?","15"),28 lowAmt2 = getPrompt("What would the lowest amount be you would willing to pay that tip to?","50"),29 hiAmt2 = getPrompt("What would the highest amount you would be willing to pay that tip to?", "200"),30 inc3 = getPrompt("What is the next lowest percentage you would pay for a tip?","10"),31 lowAmt3 = getPrompt("What would the lowest amount be you would willing to pay that tip to?","200"),32 hiAmt3 = getPrompt("What would the highest amount you would be willing to pay that tip to?");33 inc1 = parseInt(inc1);34 inc2 = parseInt(inc2);35 inc3 = parseInt(inc3);36 lowAmt1 = parseInt(lowAmt1);37 lowAmt2 = parseInt(lowAmt2);38 lowAmt3 = parseInt(lowAmt3);39 hiAmt1 = parseInt(hiAmt1);40 hiAmt2 = parseInt(hiAmt2);41 hiAmt3 = parseInt(hiAmt3);42 for (var i = 0; i < this.bills.length; i++) {43 var bill = this.bills[i];44 if (bill < lowAmt1) {45 percentage = inc1 / 100;46 } else if (bill >= lowAmt2 && bill < hiAmt2) {47 percentage = inc2 / 100;48 } else {49 percentage = inc3 / 100;50 }51 // Add results to the corresponing arrays52 this.tips[i] = bill * percentage;53 this.finalValues[i] = bill + bill * percentage;54 }55 }56}57var mark = {58 fullName: getPrompt("What is your friend's name?","Mark Miller"), //'Mark Miller',59 bills: [], // [77, 475, 110, 45],60 getBill: function() {61 var getBillsQty = getPrompt("How many bills does he/she have, " + this.fullName + "?", "4");62 getBillsQty = parseInt(getBillsQty);63 if (getBillsQty >= 0) {64 for (let i = 1; i <= getBillsQty; i++) {65 var getBill = getPrompt("How much was bill number " + i + "?","77");66 this.bills.push(getBill);67 }68 }69 this.tips = [];70 this.finalValues = [];71 // Determine percentage based on tipping rules72 var inc1 = getPrompt("What is the highest percentage he/she would pay for a tip?","25"),73 lowAmt1 = getPrompt("What would the lowest amount be he/she would willing to pay that tip to?", "300"),74 hiAmt1 = getPrompt("What would the highest amount he/she would be willing to pay that tip to?"),75 inc2 = getPrompt("What is the next highest percentage he/she would pay for a tip?","20"),76 lowAmt2 = getPrompt("What would the lowest amount be he/she would willing to pay that tip to?","50"),77 hiAmt2 = getPrompt("What would the highest amount he/she would be willing to pay that tip to?", "200"),78 inc3 = getPrompt("What is the next lowest percentage he/she would pay for a tip?","10"),79 lowAmt3 = getPrompt("What would the lowest amount be he/she would willing to pay that tip to?","200"),80 hiAmt3 = getPrompt("What would the highest amount he/she would be willing to pay that tip to?");81 inc1 = parseInt(inc1);82 inc2 = parseInt(inc2);83 inc3 = parseInt(inc3);84 lowAmt1 = parseInt(lowAmt1);85 lowAmt2 = parseInt(lowAmt2);86 lowAmt3 = parseInt(lowAmt3);87 hiAmt1 = parseInt(hiAmt1);88 hiAmt2 = parseInt(hiAmt2);89 hiAmt3 = parseInt(hiAmt3);90 for (var i = 0; i < this.bills.length; i++) {91 var bill = this.bills[i];92 if (bill >= lowAmt1 && bill <= hiAmt1 || bill >= lowAmt1 && hiAmt2 === 0 || bill <= hiAmt1 && lowAmt1 === 0) {93 percentage = inc1 / 100;94 } else if (bill >= lowAmt2 && bill <= hiAmt2) {...

Full Screen

Full Screen

playback.js

Source:playback.js Github

copy

Full Screen

...23 const found_team = utils.teamValidation(conv,24 params.team_name); 25 if(!found_team){26 conv.contexts.set(CONTEXTS.select_team.name, 1);27 return conv.ask(utils.getPrompt(conv,28 'select_team', conv.data.db_teams));29 }30 else{31 conv.data.current_team = found_team;32 }33 }34 35 console.log(params);36 console.log(conv.user.profile.payload);37 const payload = conv.user.profile.payload;38 const email = payload.email; 39 const date = conv.data.date;40 console.log(email);41 console.log(date);42 try{43 console.log(backend+'standup/' + date + '/team/' +44 conv.data.current_team.teamName);45 const rs = await axios.get(46 backend+'standup/' + date + '/team/' + conv.data.current_team.teamName);47 console.log(rs.data);48 conv.data.standup = rs.data;49 conv.data.myContext = CONTEXTS.menu;50 conv.contexts.set(CONTEXTS.menu.name, 1);51 if(rs.data == null || rs.data == ''){52 conv.ask(utils.getPrompt(conv, 'no_standup', 53 {54 team : conv.data.current_team, 55 date: date56 }));57 conv.data.current_team = null;58 return 59 }60 return conv.ask(utils.getPrompt(conv, 'play_entire', conv.data.standup));61 } catch(error) {62 console.log(error)63 conv.data.myContext = CONTEXTS.menu;64 conv.contexts.set(CONTEXTS.menu.name, 1);65 conv.data.current_team = null;66 return conv.ask(utils.getPrompt(conv, 'no_standup',67 {68 team : conv.data.current_team, 69 date: date70 }));71 }72 },73 'play_single_member' : (conv, params) => {74 console.log('in single member');75 console.log(params);76 conv.data.myContext = CONTEXTS.playback;77 conv.contexts.set(CONTEXTS.playback.name, 1);78 const member = utils.matchTeamMember(params);79 if(member == null){80 return conv.ask(utils.getPrompt(conv, 'invalid_member'));81 }82 83 conv.ask(utils.getPrompt(conv, 'play_entry', entry));84 return conv.ask(utils.getPrompt(conv, 'playback_prompt'));85 },86 'play_entire' : (conv) => {87 conv.contexts.set(CONTEXTS.playback.name, 1);88 conv.data.myContext = CONTEXTS.menu;89 conv.contexts.set(CONTEXTS.menu.name, 1);90 return conv.ask(utils.getPrompt(conv, 'play_entire', conv.data.standup)); 91 }92};93 /*94 conv.data.myContext = CONTEXTS.playback;95 conv.contexts.set(CONTEXTS.playback.name, 1);96 for(const standup of conv.data.standups){97 if(standup.team.teamName == conv.data.current_team){98 conv.data.current_standup = standup99 }100 }101 console.log(rs.data);102 console.log(rs.data[0]);103 return conv.ask(utils.getPrompt(conv, 'playback_prompt'));...

Full Screen

Full Screen

create_team.js

Source:create_team.js Github

copy

Full Screen

...10 if(valid == 1){11 conv.contexts.set(CONTEXTS.submit_team.name, 1);12 conv.data.myContext = CONTEXTS.confirm_name13 conv.data.pot_name = params.team_name;14 return conv.ask(utils.getPrompt(conv, 'confirm_team' , params.team_name));15 }16 else{17 conv.contexts.set(CONTEXTS.naming.name, 1);18 conv.data.myContext = CONTEXTS.naming;19 //2 means the team name was already taken20 if(valid == 2)21 return conv.ask(utils.getPrompt(conv, 'taken_name', params.team_name));22 return conv.ask(utils.getPrompt(conv, 'invalid_name', params.team_name));23 }24}25function checkForName(conv, params){26 console.log(params);27 if(params.team_name){28 return respondToName(conv,params);29 }30 else{ 31 conv.contexts.set(CONTEXTS.naming.name, 1);32 conv.data.myContext = CONTEXTS.naming;33 return conv.ask(utils.getPrompt(conv, 'get_name'));34 }35}36module.exports = {37 'create_team' : (conv, params) => {38 console.log('in create team');39 checkForName(conv,params);40 },41 'name_team' : (conv, params) => {42 console.log('in name');43 checkForName(conv,params);44 },45 'rename_team' : (conv, params) => {46 console.log('in rename');47 checkForName(conv,params);48 },49 'review_name' : (conv) => {50 console.log('in review team');51 conv.contexts.set(CONTEXTS.confirm_name.name, 1);52 return conv.ask(utils.getPrompt(conv, 'review_name', conv.data.pot_name));53 },54 'submit_team' : async (conv) => {55 console.log('in submit team');56 var team = templates.team;57 team.teamName = conv.data.pot_name;58 team.scrumMasterEmail = conv.data.db_user.email;59 team.users.push(conv.data.db_user);60 console.log(team);61 try { 62 //axios create team63 const rs = await axios.post(backend + 'team', team);64 //axios get teams65 console.log(rs);66 conv.ask(utils.getPrompt(conv, 'team_submit_success'));67 }catch (error) {68 console.log(error);69 conv.ask(utils.getPrompt(conv, 'team_submit_failure'));70 }71 try {72 const rs = await axios.get(backend + 'team/user/' + conv.data.db_user.email);73 console.log(rs);74 conv.data.db_teams = rs.data;75 }catch (error) {76 console.log(error);77 conv.ask(utils.getPrompt(conv, 'team_submit_failure'));78 }79 conv.data.myContext = CONTEXTS.menu;80 },81 82 ...

Full Screen

Full Screen

game-func.test.js

Source:game-func.test.js Github

copy

Full Screen

...24 }25 return null;26 })27 });28 const prompt = getPrompt();29 play(prompt);30 console.log(prompt)31 //expect(prompt).toHaveBeenCalledTimes(2);32 expect(prompt).toHaveBeenCalledWith(`Take a guess `);33 expect(prompt).toHaveBeenCalledWith(`Name? `);34 });35 it('sets name to Stranger when there is no input', () => {36 getPrompt.mockImplementation(() => {37 return jest.fn((ask) => {38 if (ask === 'Name? ') {39 return '';40 }41 if (ask === 'Take a guess ') {42 return '1234';43 }44 return null;45 });46 });47 const consoleSpy = jest.spyOn(console, 'log');48 const prompt = getPrompt();49 play(prompt);50 expect(consoleSpy).toHaveBeenCalledWith(`Congratulations Stranger!`);51 })52 it('congratulates user with correct name when guess is correct', () => {53 getPrompt.mockImplementation(() => {54 return jest.fn((ask) => {55 if (ask === 'Name? ') {56 return 'Jane';57 }58 if (ask === 'Take a guess ') {59 return '1234';60 }61 return null;62 });63 });64 const consoleSpy = jest.spyOn(console, 'log');65 const prompt = getPrompt();66 play(prompt);67 expect(consoleSpy).toHaveBeenCalledWith(`Congratulations Jane!`);68 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6var client = webdriverio.remote(options);7 .init()8 .getTitle().then(function(title) {9 console.log('Title was: ' + title);10 })11 .end();

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6 .remote(options)7 .init()8 .getPrompt(function(err, res) {9 console.log(res.value);10 })11 .end();12var webdriverio = require('webdriverio');13var options = {14 desiredCapabilities: {15 }16};17 .remote(options)18 .init()19 .getPrompt(function(err, res) {20 console.log(res.value);21 })22 .end();23var webdriverio = require('webdriverio');24var options = {25 desiredCapabilities: {26 }27};28 .remote(options)29 .init()30 .getPrompt(function(err, res) {31 console.log(res.value);32 })33 .end();34var webdriverio = require('webdriverio');35var options = {36 desiredCapabilities: {37 }38};39 .remote(options)40 .init()41 .getPrompt(function(err, res) {42 console.log(res.value);43 })44 .end();45var webdriverio = require('webdriverio');46var options = {47 desiredCapabilities: {48 }49};50 .remote(options)51 .init()52 .getPrompt(function(err, res) {53 console.log(res.value);54 })55 .end();56var webdriverio = require('webdriverio');57var options = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6var client = webdriverio.remote(options);7 .init()8 .getTitle().then(function(title) {9 console.log('Title was: ' + title);10 })11 .end();12var promptText = client.getPrompt();13console.log(promptText);

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = { desiredCapabilities: { browserName: 'chrome' } };3 .remote(options)4 .init()5 .getTitle().then(function(title) {6 console.log('Title was: ' + title);7 })8 .end();9var webdriver = require('selenium-webdriver');10var driver = new webdriver.Builder()11 .forBrowser('chrome')12 .build();13driver.getTitle().then(function(title) {14 console.log('Title was: ' + title);15});16driver.quit();17var protractor = require('protractor');18var driver = new protractor.Builder()19 .forBrowser('chrome')20 .build();21driver.getTitle().then(function(title) {22 console.log('Title was: ' + title);23});24driver.quit();25var nightwatch = require('nightwatch');26var driver = new nightwatch.Builder()27 .forBrowser('chrome')28 .build();29driver.getTitle().then(function(title) {30 console.log('Title was: ' + title);31});32driver.quit();33var nightmare = require('nightmare');34var driver = new nightmare.Builder()35 .forBrowser('chrome')36 .build();37driver.getTitle().then(function(title) {38 console.log('Title was: ' + title);39});40driver.quit();41var sahi = require('sahi');42var driver = new sahi.Builder()43 .forBrowser('chrome')44 .build();45driver.getTitle().then(function(title) {46 console.log('Title was: ' + title);47});48driver.quit();49var casperjs = require('casperjs');50var driver = new casperjs.Builder()51 .forBrowser('chrome')

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = { desiredCapabilities: { browserName: 'chrome' } };3var client = webdriverio.remote(options);4 .init()5 .getTitle().then(function(title) {6 console.log('Title was: ' + title);7 })8 .end();9var webdriverio = require('webdriverio');10var options = { desiredCapabilities: { browserName: 'chrome' } };11var client = webdriverio.remote(options);12 .init()13 .getTitle().then(function(title) {14 console.log('Title was: ' + title);15 })16 .end();17var webdriverio = require('webdriverio');18var options = { desiredCapabilities: { browserName: 'chrome' } };19var client = webdriverio.remote(options);20 .init()21 .getTitle().then(function(title) {22 console.log('Title was: ' + title);23 })24 .end();25var webdriverio = require('webdriverio');26var options = { desiredCapabilities: { browserName: 'chrome' } };27var client = webdriverio.remote(options);28 .init()29 .getTitle().then(function(title) {30 console.log('Title was: ' + title);31 })32 .end();33var webdriverio = require('webdriverio');34var options = { desiredCapabilities: { browserName: 'chrome' } };35var client = webdriverio.remote(options);36 .init()37 .getTitle().then(function(title) {38 console.log('Title was: ' + title);39 })40 .end();41var webdriverio = require('webdriverio');42var options = { desiredCapabilities: { browserName: 'chrome' } };43var client = webdriverio.remote(options);

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('webdriver.io page', () => {2 it('should have the right title', () => {3 const title = browser.getTitle()4 expect(title).toEqual('WebdriverIO · Next-gen browser and mobile automation test framework for Node.js')5 })6})7describe('webdriver.io page', () => {8 it('should have the right title', async () => {9 const title = await page.title()10 expect(title).toEqual('WebdriverIO · Next-gen browser and mobile automation test framework for Node.js')11 })12})13describe('webdriver.io page', () => {14 it('should have the right title', () => {15 cy.title().should('eq', 'WebdriverIO · Next-gen browser and mobile automation test framework for Node.js')16 })17})18describe('webdriver.io page', () => {19 it('should have the right title', async () => {20 const title = await page.title()21 expect(title).toEqual('WebdriverIO · Next-gen browser and mobile automation test framework for Node.js')22 })23})24test('My first test', async t => {25 .typeText('#developer-name', 'John Smith')26 .click('#submit-button')27 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');28});29describe('angularjs homepage', function() {30 it('should greet the named user', function() {31 element(by.model('yourName')).sendKeys('Julie');32 var greeting = element(by.binding('yourName'));33 expect(greeting.getText()).toEqual('Hello Julie!');34 });35});36describe('Google Advanced Search', function() {37 after(browser => browser.end())38 test('by text', function

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = { desiredCapabilities: { browserName: 'chrome' } };3var client = webdriverio.remote(options);4 .init()5 .getTitle().then(function(title) {6 console.log('Title was: ' + title);7 })8 .end();9var webdriverio = require('webdriverio');10var options = { desiredCapabilities: { browserName: 'chrome' } };11var client = webdriverio.remote(options);12 .init()13 .getTitle().then(function(title) {14 console.log('Title was: ' + title);15 })16 .end();17var webdriverio = require('webdriverio');18var options = { desiredCapabilities: { browserName: 'chrome' } };19var client = webdriverio.remote(options);20 .init()21 .getTitle().then(function(title) {22 console.log('Title was: ' + title);23 })24 .end();25var webdriverio = require('webdriverio');26var options = { desiredCapabilities: { browserName: 'chrome' } };27var client = webdriverio.remote(options);28 .init()29 .getTitle().then(function(title) {30 console.log('Title was: ' + title);31 })32 .end();33var webdriverio = require('webdriverio');34var options = { desiredCapabilities: { browserName: 'chrome' } };35var client = webdriverio.remote(options);36 .init()37 .getTitle().then(function(title) {38 console.log('Title was: ' + title);39 })40 .end();

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Test Suite', function() {2 it('Test Case', function() {3 browser.getTitle().should.be.equal('Google');4 browser.getTitle().should.be.equal('Google Images');5 browser.getTitle().should.be.equal('Google - About Google, Our Culture & Company News');6 browser.getTitle().should.be.equal('Privacy & Terms - Google');7 browser.back();8 browser.getTitle().should.be.equal('Google - About Google, Our Culture & Company News');9 browser.back();10 browser.getTitle().should.be.equal('Google Images');11 browser.back();12 browser.getTitle().should.be.equal('Google');13 browser.getTitle().should.be.equal('Google - About Google, Our Culture & Company News');14 browser.getTitle().should.be.equal('Privacy & Terms - Google');15 browser.forward();16 browser.getTitle().should.be.equal('Google - About Google, Our Culture & Company News');17 browser.forward();18 browser.getTitle().should.be.equal('Google Images');19 browser.forward();20 browser.getTitle().should.be.equal('Google');21 });22});

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My Test', () => {2 it('should do something', () => {3 browser.pause(2000);4 browser.getPrompt('Enter your name:', 'John Doe');5 browser.pause(2000);6 });7});8exports.config = {9 capabilities: [{10 }],11 mochaOpts: {12 }13};

Full Screen

WebdriverIO Tutorial

Wondering what could be a next-gen browser and mobile test automation framework that is also simple and concise? Yes, that’s right, it's WebdriverIO. Since the setup is very easy to follow compared to Selenium testing configuration, you can configure the features manually thereby being the center of attraction for automation testing. Therefore the testers adopt WedriverIO to fulfill their needs of browser testing.

Learn to run automation testing with WebdriverIO tutorial. Go from a beginner to a professional automation test expert with LambdaTest WebdriverIO tutorial.

Chapters

  1. Running Your First Automation Script - Learn the steps involved to execute your first Test Automation Script using WebdriverIO since the setup is very easy to follow and the features can be configured manually.

  2. Selenium Automation With WebdriverIO - Read more about automation testing with WebdriverIO and how it supports both browsers and mobile devices.

  3. Browser Commands For Selenium Testing - Understand more about the barriers faced while working on your Selenium Automation Scripts in WebdriverIO, the ‘browser’ object and how to use them?

  4. Handling Alerts & Overlay In Selenium - Learn different types of alerts faced during automation, how to handle these alerts and pops and also overlay modal in WebdriverIO.

  5. How To Use Selenium Locators? - Understand how Webdriver uses selenium locators in a most unique way since having to choose web elements very carefully for script execution is very important to get stable test results.

  6. Deep Selectors In Selenium WebdriverIO - The most popular automation testing framework that is extensively adopted by all the testers at a global level is WebdriverIO. Learn how you can use Deep Selectors in Selenium WebdriverIO.

  7. Handling Dropdown In Selenium - Learn more about handling dropdowns and how it's important while performing automated browser testing.

  8. Automated Monkey Testing with Selenium & WebdriverIO - Understand how you can leverage the amazing quality of WebdriverIO along with selenium framework to automate monkey testing of your website or web applications.

  9. JavaScript Testing with Selenium and WebdriverIO - Speed up your Javascript testing with Selenium and WebdriverIO.

  10. Cross Browser Testing With WebdriverIO - Learn more with this step-by-step tutorial about WebdriverIO framework and how cross-browser testing is done with WebdriverIO.

Run Webdriverio automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful