From 1875b1d350f818da6fed39ac0544b1a068e45a2c Mon Sep 17 00:00:00 2001 From: bbezerra Date: Fri, 15 Nov 2019 14:14:02 +0000 Subject: [PATCH 1/8] added moment.js package in order to make sure that the dates are calculated correctly inregardless of language --- i18n/lambda/index.js | 116 ++++++++++++++++++++++----------------- i18n/lambda/package.json | 35 ++++++------ 2 files changed, 85 insertions(+), 66 deletions(-) diff --git a/i18n/lambda/index.js b/i18n/lambda/index.js index 933b1f5..a0e6b77 100644 --- a/i18n/lambda/index.js +++ b/i18n/lambda/index.js @@ -15,6 +15,8 @@ const i18n = require('i18next'); // We import a language strings object containing all of our strings. // The keys for each string will then be referenced in our code, e.g. handlerInput.t('WELCOME_MSG') const languageStrings = require('./l10n'); +// We will use the moment.js package in order to make sure that we calculate the remaining days to the user's birthday correctly +const moment = require('moment'); ///////////////////////////////// // Handlers Definition @@ -26,31 +28,31 @@ const languageStrings = require('./l10n'); */ const HasBirthdayLaunchRequestHandler = { canHandle(handlerInput) { - const {attributesManager} = handlerInput; + const { attributesManager } = handlerInput; const sessionAttributes = attributesManager.getSessionAttributes() || {}; - + const year = sessionAttributes.hasOwnProperty('year') ? sessionAttributes.year : 0; const month = sessionAttributes.hasOwnProperty('month') ? sessionAttributes.month : 0; const day = sessionAttributes.hasOwnProperty('day') ? sessionAttributes.day : 0; - - return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest' - && year - && month + + return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest' + && year + && month && day; }, async handle(handlerInput) { - const {serviceClientFactory, requestEnvelope, attributesManager} = handlerInput; + const { serviceClientFactory, requestEnvelope, attributesManager } = handlerInput; const deviceId = Alexa.getDeviceId(requestEnvelope) const sessionAttributes = attributesManager.getSessionAttributes() || {}; - + const year = sessionAttributes.hasOwnProperty('year') ? sessionAttributes.year : 0; const month = sessionAttributes.hasOwnProperty('month') ? sessionAttributes.month : 0; const day = sessionAttributes.hasOwnProperty('day') ? sessionAttributes.day : 0; - + let userTimeZone; try { const upsServiceClient = serviceClientFactory.getUpsServiceClient(); - userTimeZone = await upsServiceClient.getSystemTimeZone(deviceId); + userTimeZone = await upsServiceClient.getSystemTimeZone(deviceId); } catch (error) { if (error.name !== 'ServiceError') { const errorSpeechText = handlerInput.t('ERROR_TIMEZONE_MSG'); @@ -59,38 +61,43 @@ const HasBirthdayLaunchRequestHandler = { console.log('error', error.message); } console.log('userTimeZone', userTimeZone); - - const oneDay = 24*60*60*1000; - + // getting the current date with the time const locale = Alexa.getLocale(requestEnvelope); - const currentDateTime = new Date(new Date().toLocaleString(locale, {timeZone: userTimeZone})); + const currentDateTime = new Date(new Date().toLocaleString(locale, { timeZone: userTimeZone })); // removing the time from the date because it affects our difference calculation - const currentDate = new Date(currentDateTime.getFullYear(), currentDateTime.getMonth(), currentDateTime.getDate()); - let currentYear = currentDate.getFullYear(); - + const currentDate = moment(new Date(currentDateTime.getFullYear(), currentDateTime.getMonth(), currentDateTime.getDate())); + const currentYear = currentDate.year(); + console.log('currentDateTime:', currentDateTime); - console.log('currentDate:', currentDate); - + console.log('currentDate:', currentDate.toString()); + // getting the next birthday - let nextBirthday = Date.parse(`${month} ${day}, ${currentYear}`); - - // adjust the nextBirthday by one year if the current date is after their birthday - if (currentDate.getTime() > nextBirthday) { - nextBirthday = Date.parse(`${month} ${day}, ${currentYear + 1}`); - currentYear++; - } - + let dateStr = currentYear.toString() + ' ' + month + ' ' + day.toString(); + let nextBirthday = moment(dateStr, 'YYYY MMM DD', locale); + console.log('nextBirthday:', nextBirthday.toString()) + + // check the difference between the current date and the next birthday + let diffDays = nextBirthday.diff(currentDate, 'days'); + // setting the default speakOutput to Happy xth Birthday!! // Alexa will automatically correct the ordinal for you. // no need to worry about when to use st, th, rd - const age = currentYear - year; - let speakOutput = handlerInput.t('HAPPY_BIRTHDAY_MSG', {count: age}); - if (currentDate.getTime() !== nextBirthday) { - const diffDays = Math.round(Math.abs((currentDate.getTime() - nextBirthday)/oneDay)); - speakOutput = handlerInput.t('WELCOME_BACK_MSG', {count: diffDays, age: age}); + let age = currentYear - year; + + let speakOutput = handlerInput.t('HAPPY_BIRTHDAY_MSG', { age: age }); + // checking if birthday still this year or + if (diffDays > 0) { + speakOutput = handlerInput.t('WELCOME_BACK_MSG', { count: diffDays, age: age }); + } + // has already happened + else if (diffDays < 0) { + nextBirthday = nextBirthday.add(1, 'Y'); + diffDays = nextBirthday.diff(currentDate, 'days') + age++ + speakOutput = handlerInput.t('WELCOME_BACK_MSG', { count: diffDays, age: age }); } - + return handlerInput.responseBuilder .speak(speakOutput) .getResponse(); @@ -107,7 +114,7 @@ const LaunchRequestHandler = { }, handle(handlerInput) { const speakOutput = handlerInput.t('WELCOME_MSG'); - const repromptOutput = handlerInput.t('WELCOME_REPROMPT_MSG'); + const repromptOutput = handlerInput.t('WELCOME_REPROMPT_MSG'); return handlerInput.responseBuilder .speak(speakOutput) @@ -126,25 +133,26 @@ const BirthdayIntentHandler = { && Alexa.getIntentName(handlerInput.requestEnvelope) === 'CaptureBirthdayIntent'; }, async handle(handlerInput) { - const {attributesManager, requestEnvelope} = handlerInput; + const { attributesManager, requestEnvelope } = handlerInput; const year = Alexa.getSlotValue(requestEnvelope, 'year'); const month = Alexa.getSlotValue(requestEnvelope, 'month'); const day = Alexa.getSlotValue(requestEnvelope, 'day'); - + const birthdayAttributes = { "year": year, "month": month, "day": day - + }; attributesManager.setPersistentAttributes(birthdayAttributes); - await attributesManager.savePersistentAttributes(); - - const speakOutput = handlerInput.t('REGISTER_BIRTHDAY_MSG', {month: month, day: day, year:year}); + await attributesManager.savePersistentAttributes(); + + const speakOutput = handlerInput.t('REGISTER_BIRTHDAY_MSG', { month: month, day: day, year: year }); return handlerInput.responseBuilder .speak(speakOutput) //.reprompt('add a reprompt if you want to keep the session open for the user to respond') + .withShouldEndSession(true) // force the skill to close the session after confirming the birthday date .getResponse(); } }; @@ -156,7 +164,7 @@ const BirthdayIntentHandler = { const HelpIntentHandler = { canHandle(handlerInput) { return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' - && Alexa.getIntentName(handlerInput.requestEnvelope) ==='AMAZON.HelpIntent'; + && Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.HelpIntent'; }, handle(handlerInput) { const speakOutput = handlerInput.t('HELP_MSG'); @@ -213,7 +221,7 @@ const IntentReflectorHandler = { }, handle(handlerInput) { const intentName = Alexa.getIntentName(handlerInput.requestEnvelope); - const speakOutput = handlerInput.t('REFLECTOR_MSG', {intentName: intentName}); + const speakOutput = handlerInput.t('REFLECTOR_MSG', { intentName: intentName }); return handlerInput.responseBuilder .speak(speakOutput) @@ -251,7 +259,16 @@ const ErrorHandler = { */ const LoggingRequestInterceptor = { process(handlerInput) { - console.log(`Incoming request: ${JSON.stringify(handlerInput.requestEnvelope)}`); + const { requestEnvelope } = handlerInput; + const type = Alexa.getRequestType(requestEnvelope); + const locale = Alexa.getLocale(requestEnvelope); + if (type !== 'IntentRequest') { + console.log(`[INFO] ${type} (${locale})`); + } else { + console.log(`[INFO] ${handlerInput.requestEnvelope.request.intent.name} (${locale})`); + } + console.log("\n" + "********** REQUEST *********\n" + + JSON.stringify(handlerInput, null, 4)); } }; @@ -260,7 +277,8 @@ const LoggingRequestInterceptor = { */ const LoggingResponseInterceptor = { process(handlerInput, response) { - console.log(`Outgoing response: ${JSON.stringify(response)}`); + if (response) console.log("\n" + "************* RESPONSE **************\n" + + JSON.stringify(response, null, 4)); } }; @@ -287,13 +305,13 @@ const LocalisationRequestInterceptor = { * */ const LoadBirthdayInterceptor = { async process(handlerInput) { - const {attributesManager} = handlerInput; + const { attributesManager } = handlerInput; const sessionAttributes = await attributesManager.getPersistentAttributes() || {}; - + const year = sessionAttributes.hasOwnProperty('year') ? sessionAttributes.year : 0; const month = sessionAttributes.hasOwnProperty('month') ? sessionAttributes.month : 0; const day = sessionAttributes.hasOwnProperty('day') ? sessionAttributes.day : 0; - + if (year && month && day) { attributesManager.setSessionAttributes(sessionAttributes); } @@ -311,7 +329,7 @@ const LoadBirthdayInterceptor = { */ exports.handler = Alexa.SkillBuilders.custom() .withPersistenceAdapter( - new persistenceAdapter.S3PersistenceAdapter({bucketName:process.env.S3_PERSISTENCE_BUCKET}) + new persistenceAdapter.S3PersistenceAdapter({ bucketName: process.env.S3_PERSISTENCE_BUCKET }) ) .addRequestHandlers( HasBirthdayLaunchRequestHandler, @@ -331,4 +349,4 @@ exports.handler = Alexa.SkillBuilders.custom() .addResponseInterceptors( LoggingResponseInterceptor) .withApiClient(new Alexa.DefaultApiClient()) - .lambda(); + .lambda(); \ No newline at end of file diff --git a/i18n/lambda/package.json b/i18n/lambda/package.json index 2878a17..221db50 100644 --- a/i18n/lambda/package.json +++ b/i18n/lambda/package.json @@ -1,18 +1,19 @@ { - "name": "cake-walk", - "version": "0.9.0", - "description": "alexa utility for quickly building skills", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "Amazon Alexa", - "license": "ISC", - "dependencies": { - "ask-sdk-core": "^2.0.7", - "ask-sdk-model": "^1.4.1", - "aws-sdk": "^2.326.0", - "ask-sdk-s3-persistence-adapter": "^2.0.0", - "i18next": "^15.0.5" - } - } \ No newline at end of file + "name": "hello-world", + "version": "1.1.0", + "description": "alexa utility for quickly building skills", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Amazon Alexa", + "license": "ISC", + "dependencies": { + "ask-sdk-core": "^2.6.0", + "ask-sdk-model": "^1.18.0", + "ask-sdk-s3-persistence-adapter": "^2.0.0", + "aws-sdk": "^2.326.0", + "i18next": "^15.0.5", + "moment": "^2.24.0" + } +} \ No newline at end of file From 6720c7fe5b518e5c8013db5f14e903edc0074c29 Mon Sep 17 00:00:00 2001 From: Andrea Muttoni Date: Wed, 27 Nov 2019 10:20:33 +0100 Subject: [PATCH 2/8] Update it-IT.json --- i18n/models/it-IT.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/i18n/models/it-IT.json b/i18n/models/it-IT.json index 73b9c49..a53d59d 100644 --- a/i18n/models/it-IT.json +++ b/i18n/models/it-IT.json @@ -78,7 +78,7 @@ }, { "name": "day", - "type": "AMAZON.Ordinal", + "type": "AMAZON.Number", "confirmationRequired": false, "elicitationRequired": true, "prompts": { @@ -87,7 +87,7 @@ }, { "name": "year", - "type": "AMAZON.FOUR_DIGIT_NUMBER", + "type": "AMAZON.Number", "confirmationRequired": false, "elicitationRequired": true, "prompts": { From b031eeda9234f82f1412a7dd68b66d86a3efdbcc Mon Sep 17 00:00:00 2001 From: Andrea Muttoni Date: Wed, 27 Nov 2019 10:28:23 +0100 Subject: [PATCH 3/8] Update it-IT.json --- i18n/models/it-IT.json | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/i18n/models/it-IT.json b/i18n/models/it-IT.json index a53d59d..956f988 100644 --- a/i18n/models/it-IT.json +++ b/i18n/models/it-IT.json @@ -24,15 +24,33 @@ "slots": [ { "name": "month", - "type": "AMAZON.Month" + "type": "AMAZON.Month", + "samples": [ + "sono nata a {month}", + "sono nato a {month}", + "sono nato ad {month}", + "il mese di {month}", + "{month}" + ] }, { "name": "day", - "type": "AMAZON.Number" + "type": "AMAZON.NUMBER", + "samples": [ + "il {day}", + "sono nato il {day}", + "{day}" + ] }, { "name": "year", - "type": "AMAZON.Number" + "type": "AMAZON.NUMBER", + "samples": [ + "sono del {year}", + "nell'anno {year}", + "nel {year}", + "{year}" + ] } ], "samples": [ @@ -78,7 +96,7 @@ }, { "name": "day", - "type": "AMAZON.Number", + "type": "AMAZON.NUMBER", "confirmationRequired": false, "elicitationRequired": true, "prompts": { @@ -87,7 +105,7 @@ }, { "name": "year", - "type": "AMAZON.Number", + "type": "AMAZON.NUMBER", "confirmationRequired": false, "elicitationRequired": true, "prompts": { @@ -118,7 +136,7 @@ "variations": [ { "type": "PlainText", - "value": "Sono nata il 6. Che giorno del mese è il tuo compleanno?" + "value": "Io sono nata il sei. Che giorno del mese è il tuo compleanno?" } ] }, From d27fee6833935794ac3354dbc5bfb02c70bc2aca Mon Sep 17 00:00:00 2001 From: Gaetano Ursomanno Date: Fri, 29 Nov 2019 14:25:35 +0000 Subject: [PATCH 4/8] renamed i10n.js to languageStrings.js and updated imports accordingly. --- i18n/lambda/index.js | 4 +--- i18n/lambda/{l10n.js => languageStrings.js} | 0 2 files changed, 1 insertion(+), 3 deletions(-) rename i18n/lambda/{l10n.js => languageStrings.js} (100%) diff --git a/i18n/lambda/index.js b/i18n/lambda/index.js index a0e6b77..ea1d0bd 100644 --- a/i18n/lambda/index.js +++ b/i18n/lambda/index.js @@ -14,9 +14,7 @@ const persistenceAdapter = require('ask-sdk-s3-persistence-adapter'); const i18n = require('i18next'); // We import a language strings object containing all of our strings. // The keys for each string will then be referenced in our code, e.g. handlerInput.t('WELCOME_MSG') -const languageStrings = require('./l10n'); -// We will use the moment.js package in order to make sure that we calculate the remaining days to the user's birthday correctly -const moment = require('moment'); +const languageStrings = require('./languageStrings'); ///////////////////////////////// // Handlers Definition diff --git a/i18n/lambda/l10n.js b/i18n/lambda/languageStrings.js similarity index 100% rename from i18n/lambda/l10n.js rename to i18n/lambda/languageStrings.js From fcf9979acc37bb431c2ae07a3cf72c8256f44eb3 Mon Sep 17 00:00:00 2001 From: bbezerra Date: Wed, 15 Jan 2020 14:31:46 +0000 Subject: [PATCH 5/8] wut --- i18n/lambda/index.js | 2 ++ i18n/lambda/package.json | 34 +++++++++++++++++----------------- i18n/models/en-AU.json | 2 +- i18n/models/en-CA.json | 2 +- i18n/models/en-GB.json | 2 +- i18n/models/en-IN.json | 2 +- i18n/models/en-US.json | 2 +- i18n/skill.json | 38 ++++++++++++++++++++++---------------- 8 files changed, 46 insertions(+), 38 deletions(-) diff --git a/i18n/lambda/index.js b/i18n/lambda/index.js index ea1d0bd..6ee78ac 100644 --- a/i18n/lambda/index.js +++ b/i18n/lambda/index.js @@ -16,6 +16,8 @@ const i18n = require('i18next'); // The keys for each string will then be referenced in our code, e.g. handlerInput.t('WELCOME_MSG') const languageStrings = require('./languageStrings'); +const moment = require('moment'); + ///////////////////////////////// // Handlers Definition ///////////////////////////////// diff --git a/i18n/lambda/package.json b/i18n/lambda/package.json index 221db50..a5b8a1b 100644 --- a/i18n/lambda/package.json +++ b/i18n/lambda/package.json @@ -1,19 +1,19 @@ { - "name": "hello-world", - "version": "1.1.0", - "description": "alexa utility for quickly building skills", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "Amazon Alexa", - "license": "ISC", - "dependencies": { - "ask-sdk-core": "^2.6.0", - "ask-sdk-model": "^1.18.0", - "ask-sdk-s3-persistence-adapter": "^2.0.0", - "aws-sdk": "^2.326.0", - "i18next": "^15.0.5", - "moment": "^2.24.0" + "name": "cake-walk", + "version": "0.9.0", + "description": "alexa utility for quickly building skills", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Amazon Alexa", + "license": "ISC", + "dependencies": { + "ask-sdk-core": "^2.0.7", + "ask-sdk-model": "^1.4.1", + "aws-sdk": "^2.326.0", + "ask-sdk-s3-persistence-adapter": "^2.0.0", + "i18next": "^15.0.5", + "moment": "^2.24.0" + } } -} \ No newline at end of file diff --git a/i18n/models/en-AU.json b/i18n/models/en-AU.json index 5b34280..38769bf 100644 --- a/i18n/models/en-AU.json +++ b/i18n/models/en-AU.json @@ -1,7 +1,7 @@ { "interactionModel": { "languageModel": { - "invocationName": "cake walk", + "invocationName": "cakewalk", "intents": [ { "name": "AMAZON.CancelIntent", diff --git a/i18n/models/en-CA.json b/i18n/models/en-CA.json index 5a0b593..724e809 100644 --- a/i18n/models/en-CA.json +++ b/i18n/models/en-CA.json @@ -1,7 +1,7 @@ { "interactionModel": { "languageModel": { - "invocationName": "cake walk", + "invocationName": "cakewalk", "intents": [ { "name": "AMAZON.CancelIntent", diff --git a/i18n/models/en-GB.json b/i18n/models/en-GB.json index 5a0b593..724e809 100644 --- a/i18n/models/en-GB.json +++ b/i18n/models/en-GB.json @@ -1,7 +1,7 @@ { "interactionModel": { "languageModel": { - "invocationName": "cake walk", + "invocationName": "cakewalk", "intents": [ { "name": "AMAZON.CancelIntent", diff --git a/i18n/models/en-IN.json b/i18n/models/en-IN.json index 0f0e44e..50e419a 100644 --- a/i18n/models/en-IN.json +++ b/i18n/models/en-IN.json @@ -1,7 +1,7 @@ { "interactionModel": { "languageModel": { - "invocationName": "cake walk", + "invocationName": "cakewalk", "intents": [ { "name": "AMAZON.CancelIntent", diff --git a/i18n/models/en-US.json b/i18n/models/en-US.json index 5a0b593..724e809 100644 --- a/i18n/models/en-US.json +++ b/i18n/models/en-US.json @@ -1,7 +1,7 @@ { "interactionModel": { "languageModel": { - "invocationName": "cake walk", + "invocationName": "cakewalk", "intents": [ { "name": "AMAZON.CancelIntent", diff --git a/i18n/skill.json b/i18n/skill.json index 0fc996a..2226bbc 100644 --- a/i18n/skill.json +++ b/i18n/skill.json @@ -2,32 +2,23 @@ "manifest": { "publishingInformation": { "locales": { - "en-US": { - "name": "Cake Walk" + "de-DE": { + "name": "Herzlichen Glückwunsch" }, - "en-GB": { + "en-AU": { "name": "Cake Walk" }, "en-CA": { "name": "Cake Walk" }, - "fr-FR": { - "name": "Joyeux Anniversaire" - }, - "fr-CA": { - "name": "Bonne Fête" - }, - "it-IT": { - "name": "Buon Compleanno" - }, - "ja-JP": { - "name": "ケークウォーク" + "en-GB": { + "name": "Cake Walk" }, "en-IN": { "name": "cake walk" }, - "hi-IN": { - "name": "cake walk" + "en-US": { + "name": "Cake Walk" }, "es-ES": { "name": "feliz cumpleaños" @@ -38,6 +29,21 @@ "es-US": { "name": "feliz cumpleaños" }, + "fr-CA": { + "name": "Bonne Fête" + }, + "fr-FR": { + "name": "Joyeux Anniversaire" + }, + "hi-IN": { + "name": "cake walk" + }, + "it-IT": { + "name": "Buon Compleanno" + }, + "ja-JP": { + "name": "ケークウォーク" + }, "pt-BR": { "name": "Feliz Aniversário" }, From 6cefe826c7a33e01f741a8a3294a9ad70b8b5994 Mon Sep 17 00:00:00 2001 From: bbezerra Date: Thu, 16 Jan 2020 10:57:56 +0000 Subject: [PATCH 6/8] perfomed multiple fixes; details on the Pull Request description --- i18n/lambda/package.json | 2 +- i18n/models/en-GB.json | 244 +++++++++++++++++++-------------------- i18n/models/en-US.json | 224 ++++++++++++++++++----------------- i18n/models/es-ES.json | 9 +- i18n/models/es-MX.json | 8 +- i18n/models/es-US.json | 6 +- i18n/models/fr-CA.json | 4 +- i18n/models/fr-FR.json | 4 +- i18n/models/it-IT.json | 21 ++-- i18n/skill.json | 12 +- 10 files changed, 261 insertions(+), 273 deletions(-) diff --git a/i18n/lambda/package.json b/i18n/lambda/package.json index a5b8a1b..512e381 100644 --- a/i18n/lambda/package.json +++ b/i18n/lambda/package.json @@ -14,6 +14,6 @@ "aws-sdk": "^2.326.0", "ask-sdk-s3-persistence-adapter": "^2.0.0", "i18next": "^15.0.5", - "moment": "^2.24.0" + "moment-timezone": "^0.5.27" } } diff --git a/i18n/models/en-GB.json b/i18n/models/en-GB.json index 724e809..40ca8c2 100644 --- a/i18n/models/en-GB.json +++ b/i18n/models/en-GB.json @@ -1,124 +1,124 @@ { - "interactionModel": { - "languageModel": { - "invocationName": "cakewalk", - "intents": [ - { - "name": "AMAZON.CancelIntent", - "samples": [] - }, - { - "name": "AMAZON.HelpIntent", - "samples": [] - }, - { - "name": "AMAZON.StopIntent", - "samples": [] - }, - { - "name": "AMAZON.NavigateHomeIntent", - "samples": [] - }, - { - "name": "CaptureBirthdayIntent", - "slots": [ - { - "name": "month", - "type": "AMAZON.Month" - }, - { - "name": "day", - "type": "AMAZON.Ordinal" - }, - { - "name": "year", - "type": "AMAZON.FOUR_DIGIT_NUMBER" - } - ], - "samples": [ - "{month} {day}", - "{month} {day} {year}", - "{month} {year}", - "I was born on {month} {day} ", - "I was born on {month} {day} {year}", - "I was born on {month} {year}", - "register my birthday" - ] - } - ], - "types": [] - }, - "dialog": { - "intents": [ - { - "name": "CaptureBirthdayIntent", - "confirmationRequired": false, - "prompts": {}, - "slots": [ - { - "name": "month", - "type": "AMAZON.Month", - "confirmationRequired": false, - "elicitationRequired": true, - "prompts": { - "elicitation": "Elicit.Slot.303899476312.795077103633" - } - }, - { - "name": "day", - "type": "AMAZON.Ordinal", - "confirmationRequired": false, - "elicitationRequired": true, - "prompts": { - "elicitation": "Elicit.Slot.303899476312.985837334781" - } - }, - { - "name": "year", - "type": "AMAZON.FOUR_DIGIT_NUMBER", - "confirmationRequired": false, - "elicitationRequired": true, - "prompts": { - "elicitation": "Elicit.Slot.303899476312.27341833344" - } - } - ] - } - ], - "delegationStrategy": "ALWAYS" - }, - "prompts": [ - { - "id": "Elicit.Slot.303899476312.795077103633", - "variations": [ - { - "type": "PlainText", - "value": "I was born in November. What month were you born?" - }, - { - "type": "PlainText", - "value": "What month were you born?" - } - ] - }, - { - "id": "Elicit.Slot.303899476312.985837334781", - "variations": [ - { - "type": "PlainText", - "value": "I was born on the sixth. What day were you born?" - } - ] - }, - { - "id": "Elicit.Slot.303899476312.27341833344", - "variations": [ - { - "type": "PlainText", - "value": "I was born in two thousand fourteen, what year were you born?" - } - ] - } - ] - } + "interactionModel": { + "languageModel": { + "invocationName": "cakewalk", + "intents": [ + { + "name": "AMAZON.CancelIntent", + "samples": [] + }, + { + "name": "AMAZON.HelpIntent", + "samples": [] + }, + { + "name": "AMAZON.StopIntent", + "samples": [] + }, + { + "name": "AMAZON.NavigateHomeIntent", + "samples": [] + }, + { + "name": "CaptureBirthdayIntent", + "slots": [ + { + "name": "month", + "type": "AMAZON.Month" + }, + { + "name": "day", + "type": "AMAZON.Ordinal" + }, + { + "name": "year", + "type": "AMAZON.FOUR_DIGIT_NUMBER" + } + ], + "samples": [ + "{month} {day}", + "{month} {day} {year}", + "{month} {year}", + "I was born on {month} {day} ", + "I was born on {month} {day} {year}", + "I was born on {month} {year}", + "register my birthday" + ] + } + ], + "types": [] + }, + "dialog": { + "intents": [ + { + "name": "CaptureBirthdayIntent", + "confirmationRequired": false, + "prompts": {}, + "slots": [ + { + "name": "month", + "type": "AMAZON.Month", + "confirmationRequired": false, + "elicitationRequired": true, + "prompts": { + "elicitation": "Elicit.Slot.303899476312.795077103633" + } + }, + { + "name": "day", + "type": "AMAZON.Ordinal", + "confirmationRequired": false, + "elicitationRequired": true, + "prompts": { + "elicitation": "Elicit.Slot.303899476312.985837334781" + } + }, + { + "name": "year", + "type": "AMAZON.FOUR_DIGIT_NUMBER", + "confirmationRequired": false, + "elicitationRequired": true, + "prompts": { + "elicitation": "Elicit.Slot.303899476312.27341833344" + } + } + ] + } + ], + "delegationStrategy": "ALWAYS" + }, + "prompts": [ + { + "id": "Elicit.Slot.303899476312.795077103633", + "variations": [ + { + "type": "PlainText", + "value": "I was born in November. What month were you born?" + }, + { + "type": "PlainText", + "value": "What month were you born?" + } + ] + }, + { + "id": "Elicit.Slot.303899476312.985837334781", + "variations": [ + { + "type": "PlainText", + "value": "I was born on the sixth. What day were you born?" + } + ] + }, + { + "id": "Elicit.Slot.303899476312.27341833344", + "variations": [ + { + "type": "PlainText", + "value": "I was born in two thousand fourteen, what year were you born?" + } + ] + } + ] + } } \ No newline at end of file diff --git a/i18n/models/en-US.json b/i18n/models/en-US.json index 724e809..1988b7f 100644 --- a/i18n/models/en-US.json +++ b/i18n/models/en-US.json @@ -1,124 +1,120 @@ { - "interactionModel": { - "languageModel": { - "invocationName": "cakewalk", - "intents": [ - { - "name": "AMAZON.CancelIntent", - "samples": [] - }, - { - "name": "AMAZON.HelpIntent", - "samples": [] - }, - { - "name": "AMAZON.StopIntent", - "samples": [] - }, - { - "name": "AMAZON.NavigateHomeIntent", - "samples": [] - }, - { - "name": "CaptureBirthdayIntent", - "slots": [ - { - "name": "month", - "type": "AMAZON.Month" - }, - { - "name": "day", - "type": "AMAZON.Ordinal" - }, - { - "name": "year", - "type": "AMAZON.FOUR_DIGIT_NUMBER" - } - ], - "samples": [ - "{month} {day}", - "{month} {day} {year}", - "{month} {year}", - "I was born on {month} {day} ", - "I was born on {month} {day} {year}", - "I was born on {month} {year}", - "register my birthday" - ] - } - ], - "types": [] + "interactionModel": { + "languageModel": { + "invocationName": "cake walk", + "intents": [ + { + "name": "AMAZON.CancelIntent", + "samples": [] }, - "dialog": { - "intents": [ - { - "name": "CaptureBirthdayIntent", - "confirmationRequired": false, - "prompts": {}, - "slots": [ - { - "name": "month", - "type": "AMAZON.Month", - "confirmationRequired": false, - "elicitationRequired": true, - "prompts": { - "elicitation": "Elicit.Slot.303899476312.795077103633" - } - }, - { - "name": "day", - "type": "AMAZON.Ordinal", - "confirmationRequired": false, - "elicitationRequired": true, - "prompts": { - "elicitation": "Elicit.Slot.303899476312.985837334781" - } - }, - { - "name": "year", - "type": "AMAZON.FOUR_DIGIT_NUMBER", - "confirmationRequired": false, - "elicitationRequired": true, - "prompts": { - "elicitation": "Elicit.Slot.303899476312.27341833344" - } - } - ] - } - ], - "delegationStrategy": "ALWAYS" + { + "name": "AMAZON.HelpIntent", + "samples": [] }, - "prompts": [ + { + "name": "AMAZON.StopIntent", + "samples": [] + }, + { + "name": "AMAZON.NavigateHomeIntent", + "samples": [] + }, + { + "name": "CaptureBirthdayIntent", + "slots": [ + { + "name": "month", + "type": "AMAZON.Month" + }, + { + "name": "day", + "type": "AMAZON.Ordinal" + }, + { + "name": "year", + "type": "AMAZON.FOUR_DIGIT_NUMBER" + } + ], + "samples": [ + "I was born in {month} {year}", + "I was born on {month} {day} {year}", + "I was born on {month} {day}", + "{month} {year}", + "{month} {day} {year}", + "{month} {day}" + ] + } + ], + "types": [] + }, + "dialog": { + "intents": [ + { + "name": "CaptureBirthdayIntent", + "confirmationRequired": false, + "prompts": {}, + "slots": [ { - "id": "Elicit.Slot.303899476312.795077103633", - "variations": [ - { - "type": "PlainText", - "value": "I was born in November. What month were you born?" - }, - { - "type": "PlainText", - "value": "What month were you born?" - } - ] + "name": "month", + "type": "AMAZON.Month", + "elicitationRequired": true, + "confirmationRequired": false, + "prompts": { + "elicitation": "Elicit.Slot.1545633524831.1347716407493" + } }, { - "id": "Elicit.Slot.303899476312.985837334781", - "variations": [ - { - "type": "PlainText", - "value": "I was born on the sixth. What day were you born?" - } - ] + "name": "day", + "type": "AMAZON.Ordinal", + "elicitationRequired": true, + "confirmationRequired": false, + "prompts": { + "elicitation": "Elicit.Slot.1545633524831.190084519655" + } }, { - "id": "Elicit.Slot.303899476312.27341833344", - "variations": [ - { - "type": "PlainText", - "value": "I was born in two thousand fourteen, what year were you born?" - } - ] + "name": "year", + "type": "AMAZON.FOUR_DIGIT_NUMBER", + "elicitationRequired": true, + "confirmationRequired": false, + "prompts": { + "elicitation": "Elicit.Slot.1545633524831.788317813173" + } } + ] + } + ], + "delegationStrategy": "ALWAYS" + }, + "prompts": [ + { + "id": "Elicit.Slot.1545633524831.1347716407493", + "variations": [ + { + "type": "PlainText", + "value": "What month were you born in?" + } + ] + }, + { + "id": "Elicit.Slot.1545633524831.190084519655", + "variations": [ + { + "type": "PlainText", + "value": "Which day were you born on?" + } + ] + }, + { + "id": "Elicit.Slot.1545633524831.788317813173", + "variations": [ + { + "type": "PlainText", + "value": "Which year were you born on?" + } ] - } -} \ No newline at end of file + } + ] + }, + "version": "5" +} diff --git a/i18n/models/es-ES.json b/i18n/models/es-ES.json index d6146d0..89358c9 100644 --- a/i18n/models/es-ES.json +++ b/i18n/models/es-ES.json @@ -28,11 +28,11 @@ }, { "name": "day", - "type": "AMAZON.Number" + "type": "AMAZON.NUMBER" }, { "name": "year", - "type": "AMAZON.Number" + "type": "AMAZON.FOUR_DIGIT_NUMBER" } ], "samples": [ @@ -41,7 +41,6 @@ "el año {year}", "en {year}", "nací en {year}", - "nací en {year}", "el {day} de {month}", "el día {day} de {month}", "mi fecha de nacimiento es el {day} de {month} de {year}", @@ -78,7 +77,7 @@ }, { "name": "day", - "type": "AMAZON.Ordinal", + "type": "AMAZON.NUMBER", "confirmationRequired": false, "elicitationRequired": true, "prompts": { @@ -118,7 +117,7 @@ "variations": [ { "type": "PlainText", - "value": "Nací el 6. Qué día del mes es tu cumpleaños?" + "value": "Nací el seis. Qué día del mes es tu cumpleaños?" } ] }, diff --git a/i18n/models/es-MX.json b/i18n/models/es-MX.json index d6146d0..e23480d 100644 --- a/i18n/models/es-MX.json +++ b/i18n/models/es-MX.json @@ -28,11 +28,11 @@ }, { "name": "day", - "type": "AMAZON.Number" + "type": "AMAZON.NUMBER" }, { "name": "year", - "type": "AMAZON.Number" + "type": "AMAZON.FOUR_DIGIT_NUMBER" } ], "samples": [ @@ -78,7 +78,7 @@ }, { "name": "day", - "type": "AMAZON.Ordinal", + "type": "AMAZON.NUMBER", "confirmationRequired": false, "elicitationRequired": true, "prompts": { @@ -133,4 +133,4 @@ } ] } -} +} \ No newline at end of file diff --git a/i18n/models/es-US.json b/i18n/models/es-US.json index d6146d0..d361b40 100644 --- a/i18n/models/es-US.json +++ b/i18n/models/es-US.json @@ -28,11 +28,11 @@ }, { "name": "day", - "type": "AMAZON.Number" + "type": "AMAZON.NUMBER" }, { "name": "year", - "type": "AMAZON.Number" + "type": "AMAZON.FOUR_DIGIT_NUMBER" } ], "samples": [ @@ -78,7 +78,7 @@ }, { "name": "day", - "type": "AMAZON.Ordinal", + "type": "AMAZON.NUMBER", "confirmationRequired": false, "elicitationRequired": true, "prompts": { diff --git a/i18n/models/fr-CA.json b/i18n/models/fr-CA.json index d5c3e89..7e5f726 100644 --- a/i18n/models/fr-CA.json +++ b/i18n/models/fr-CA.json @@ -46,7 +46,7 @@ }, { "name": "year", - "type": "AMAZON.NUMBER", + "type": "AMAZON.FOUR_DIGIT_NUMBER", "samples": [ "je suis né en {year}", "mon année de naissance est {year}", @@ -113,7 +113,7 @@ }, { "name": "year", - "type": "AMAZON.NUMBER", + "type": "AMAZON.FOUR_DIGIT_NUMBER", "confirmationRequired": false, "elicitationRequired": true, "prompts": { diff --git a/i18n/models/fr-FR.json b/i18n/models/fr-FR.json index ab5b6b1..775bd34 100644 --- a/i18n/models/fr-FR.json +++ b/i18n/models/fr-FR.json @@ -46,7 +46,7 @@ }, { "name": "year", - "type": "AMAZON.NUMBER", + "type": "AMAZON.FOUR_DIGIT_NUMBER", "samples": [ "je suis né en {year}", "mon année de naissance est {year}", @@ -109,7 +109,7 @@ }, { "name": "year", - "type": "AMAZON.NUMBER", + "type": "AMAZON.FOUR_DIGIT_NUMBER", "confirmationRequired": false, "elicitationRequired": true, "prompts": { diff --git a/i18n/models/it-IT.json b/i18n/models/it-IT.json index 956f988..a51c082 100644 --- a/i18n/models/it-IT.json +++ b/i18n/models/it-IT.json @@ -35,22 +35,11 @@ }, { "name": "day", - "type": "AMAZON.NUMBER", - "samples": [ - "il {day}", - "sono nato il {day}", - "{day}" - ] + "type": "AMAZON.NUMBER" }, { "name": "year", - "type": "AMAZON.NUMBER", - "samples": [ - "sono del {year}", - "nell'anno {year}", - "nel {year}", - "{year}" - ] + "type": "AMAZON.FOUR_DIGIT_NUMBER" } ], "samples": [ @@ -136,7 +125,11 @@ "variations": [ { "type": "PlainText", +<<<<<<< HEAD "value": "Io sono nata il sei. Che giorno del mese è il tuo compleanno?" +======= + "value": "Sono nata il seis. Che giorno del mese è il tuo compleanno?" +>>>>>>> perfomed multiple fixes; details on the Pull Request description } ] }, @@ -151,4 +144,4 @@ } ] } -} +} \ No newline at end of file diff --git a/i18n/skill.json b/i18n/skill.json index 2226bbc..60d251d 100644 --- a/i18n/skill.json +++ b/i18n/skill.json @@ -15,19 +15,19 @@ "name": "Cake Walk" }, "en-IN": { - "name": "cake walk" + "name": "Cake Walk" }, "en-US": { "name": "Cake Walk" }, "es-ES": { - "name": "feliz cumpleaños" + "name": "Feliz Cumpleaños" }, "es-MX": { - "name": "feliz cumpleaños" + "name": "Feliz Cumpleaños" }, "es-US": { - "name": "feliz cumpleaños" + "name": "Feliz Cumpleaños" }, "fr-CA": { "name": "Bonne Fête" @@ -36,7 +36,7 @@ "name": "Joyeux Anniversaire" }, "hi-IN": { - "name": "cake walk" + "name": "Cake Walk" }, "it-IT": { "name": "Buon Compleanno" @@ -66,4 +66,4 @@ }, "manifestVersion": "1.0" } -} +} \ No newline at end of file From b0472081f3cd5ce4673655a6ec6a62df8c632f1b Mon Sep 17 00:00:00 2001 From: bbezerra Date: Thu, 16 Jan 2020 13:31:55 +0000 Subject: [PATCH 7/8] minor fix on index.js --- i18n/lambda/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/i18n/lambda/index.js b/i18n/lambda/index.js index 6ee78ac..85b39ba 100644 --- a/i18n/lambda/index.js +++ b/i18n/lambda/index.js @@ -16,6 +16,7 @@ const i18n = require('i18next'); // The keys for each string will then be referenced in our code, e.g. handlerInput.t('WELCOME_MSG') const languageStrings = require('./languageStrings'); +// We will use the moment.js package in order to make sure that we calculate the remaining days to the user's birthday correctly const moment = require('moment'); ///////////////////////////////// From 0d5f714608f3d3815859bc655ab90cce41fbe4ab Mon Sep 17 00:00:00 2001 From: bbezerra Date: Thu, 16 Jan 2020 13:51:57 +0000 Subject: [PATCH 8/8] fixed index.js --- i18n/lambda/index.js | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/i18n/lambda/index.js b/i18n/lambda/index.js index 85b39ba..1fc735a 100644 --- a/i18n/lambda/index.js +++ b/i18n/lambda/index.js @@ -15,9 +15,8 @@ const i18n = require('i18next'); // We import a language strings object containing all of our strings. // The keys for each string will then be referenced in our code, e.g. handlerInput.t('WELCOME_MSG') const languageStrings = require('./languageStrings'); - -// We will use the moment.js package in order to make sure that we calculate the remaining days to the user's birthday correctly -const moment = require('moment'); +// We will use the moment.js package in order to make sure that we calculate the date correctly +const moment = require('moment-timezone'); ///////////////////////////////// // Handlers Definition @@ -63,38 +62,39 @@ const HasBirthdayLaunchRequestHandler = { } console.log('userTimeZone', userTimeZone); - // getting the current date with the time - const locale = Alexa.getLocale(requestEnvelope); - const currentDateTime = new Date(new Date().toLocaleString(locale, { timeZone: userTimeZone })); - // removing the time from the date because it affects our difference calculation - const currentDate = moment(new Date(currentDateTime.getFullYear(), currentDateTime.getMonth(), currentDateTime.getDate())); + // getting the current date with the time set to the start of the day, aka 00:00AM + const currentDate = moment().tz(userTimeZone).startOf('day') + // getting the current year const currentYear = currentDate.year(); - - console.log('currentDateTime:', currentDateTime); + console.log('currentDate:', currentDate.toString()); - + // getting the next birthday - let dateStr = currentYear.toString() + ' ' + month + ' ' + day.toString(); + const dateStr = currentYear.toString() + ' ' + month + ' ' + day.toString(); + const locale = Alexa.getLocale(requestEnvelope); let nextBirthday = moment(dateStr, 'YYYY MMM DD', locale); console.log('nextBirthday:', nextBirthday.toString()) - // check the difference between the current date and the next birthday + // calculate the difference between the current date and the next birthday let diffDays = nextBirthday.diff(currentDate, 'days'); // setting the default speakOutput to Happy xth Birthday!! // Alexa will automatically correct the ordinal for you. // no need to worry about when to use st, th, rd let age = currentYear - year; - let speakOutput = handlerInput.t('HAPPY_BIRTHDAY_MSG', { age: age }); - // checking if birthday still this year or + + // checking if birthday is still to happen or... if (diffDays > 0) { speakOutput = handlerInput.t('WELCOME_BACK_MSG', { count: diffDays, age: age }); } - // has already happened + // has already happened this year else if (diffDays < 0) { + // in this case, add one year to the next birthday, nextBirthday = nextBirthday.add(1, 'Y'); + // recalculate the difference, diffDays = nextBirthday.diff(currentDate, 'days') + // and add on extra year to the age age++ speakOutput = handlerInput.t('WELCOME_BACK_MSG', { count: diffDays, age: age }); } @@ -260,21 +260,13 @@ const ErrorHandler = { */ const LoggingRequestInterceptor = { process(handlerInput) { - const { requestEnvelope } = handlerInput; - const type = Alexa.getRequestType(requestEnvelope); - const locale = Alexa.getLocale(requestEnvelope); - if (type !== 'IntentRequest') { - console.log(`[INFO] ${type} (${locale})`); - } else { - console.log(`[INFO] ${handlerInput.requestEnvelope.request.intent.name} (${locale})`); - } console.log("\n" + "********** REQUEST *********\n" + JSON.stringify(handlerInput, null, 4)); } }; /** - * This response interceptor will log all outgoing responses in the associated Logs (CloudWatch) of the AWS Lambda functions + * This response interceptor will log outgoing responses if any in the associated Logs (CloudWatch) of the AWS Lambda functions */ const LoggingResponseInterceptor = { process(handlerInput, response) {