Ajinkya Bapat
Published © MIT

Facts of India Alexa Skill

Skill to explore some amazing facts about India! Just ask "Alexa, open facts of india". Or in-short, just ask, "Facts about India".

BeginnerProtip964
Facts of India Alexa Skill

Things used in this project

Story

Read more

Code

Lambda Function Code

JavaScript
Code for Lambda Function: FactsOfIndiaSkill
/** 
* This sample demonstrates a simple skill built with the Amazon Alexa Skills nodejs skill development kit. 
* Created by: Ajinkya
**/ 

'use strict'; 
const Alexa = require('alexa-sdk'); 
const APP_ID = undefined;  // TODO replace with your app ID (OPTIONAL). 
const languageStrings = { 
   'en-IN': { 
       translation: { 
           FACTS: [ 
               'India’s name is derived from the “Indus” river.', 
               'Around a 100 million years ago, India was an island.', 
               'India invented the Number System. Zero was invented by Aryabhatta.', 
               'Yoga is an ancient Indian gift to the world.', 
               'Chess was invented in India.', 
               'Indus Valley Civilisation is the world’s oldest civilisation.', 
               'Today, India has the world’s largest school in terms of students, the City Montessori School in Lucknow. It has more than 45 thousand students!', 
               'India has the largest English speaking population in the world.', 
               'India’s first rocket was brought on cycle and a satellite on bullock cart.', 
               'The Sun is an almost perfect sphere.', 
               'Lonar Lake, a saltwater lake in Maharashtra, was created by a meteor hitting the Earth and is one of its kind in India.', 
               'India is the largest producer of films in the world.', 
               'Today, India is the world’s third largest economy.', 
               'The world’s largest road network is in India—over 1.9 million miles of roads cover the country.', 
           ], 
           SKILL_NAME: 'FactsOfIndiaSkill', 
           GET_FACT_MESSAGE: "Here's your fact about India: ", 
           HELP_MESSAGE: 'You can say tell me a fact about India, or, you can say exit... What can I help you with?', 
           HELP_REPROMPT: 'What can I help you with?', 
           STOP_MESSAGE: 'Goodbye!', 
       }, 
   },
   
   'en-US': { 
       translation: { 
           FACTS: [ 
               'India’s name is derived from the “Indus” river.', 
               'Around a 100 million years ago, India was an island.', 
               'India invented the Number System. Zero was invented by Aryabhatta.', 
               'Yoga is an ancient Indian gift to the world.', 
               'Chess was invented in India.', 
               'Indus Valley Civilisation is the world’s oldest civilisation.', 
               'Today, India has the world’s largest school in terms of students, the City Montessori School in Lucknow. It has more than 45 thousand students!', 
               'India has the largest English speaking population in the world.', 
               'India’s first rocket was brought on cycle and a satellite on bullock cart.', 
               'The Sun is an almost perfect sphere.', 
               'Lonar Lake, a saltwater lake in Maharashtra, was created by a meteor hitting the Earth and is one of its kind in India.', 
               'India is the largest producer of films in the world.', 
               'Today, India is the world’s third largest economy.', 
               'The world’s largest road network is in India—over 1.9 million miles of roads cover the country.', 
           ], 
           SKILL_NAME: 'FactsOfIndiaSkill', 
           GET_FACT_MESSAGE: "Here's your fact about India: ", 
           HELP_MESSAGE: 'You can say tell me a fact about India, or, you can say exit... What can I help you with?', 
           HELP_REPROMPT: 'What can I help you with?', 
           STOP_MESSAGE: 'Goodbye!', 
       }, 
   }, 
   
   'en-GB': { 
       translation: { 
           FACTS: [ 
               'India’s name is derived from the “Indus” river.', 
               'Around a 100 million years ago, India was an island.', 
               'India invented the Number System. Zero was invented by Aryabhatta.', 
               'Yoga is an ancient Indian gift to the world.', 
               'Chess was invented in India.', 
               'Indus Valley Civilisation is the world’s oldest civilisation.', 
               'Today, India has the world’s largest school in terms of students, the City Montessori School in Lucknow. It has more than 45 thousand students!', 
               'India has the largest English speaking population in the world.', 
               'India’s first rocket was brought on cycle and a satellite on bullock cart.', 
               'The Sun is an almost perfect sphere.', 
               'Lonar Lake, a saltwater lake in Maharashtra, was created by a meteor hitting the Earth and is one of its kind in India.', 
               'India is the largest producer of films in the world.', 
               'Today, India is the world’s third largest economy.', 
               'The world’s largest road network is in India—over 1.9 million miles of roads cover the country.', 
           ], 
           SKILL_NAME: 'FactsOfIndiaSkill', 
           GET_FACT_MESSAGE: "Here's your fact about India: ", 
           HELP_MESSAGE: 'You can say tell me a fact about India, or, you can say exit... What can I help you with?', 
           HELP_REPROMPT: 'What can I help you with?', 
           STOP_MESSAGE: 'Goodbye!', 
       }, 
   }, 
}; 


const handlers = { 
   'LaunchRequest': function () { 
       this.emit('GetFact'); 
   }, 
   'GetNewFactIntent': function () { 
       this.emit('GetFact'); 
   }, 
   'GetFact': function () { 
       // Get a random India fact from the India facts list 
       // Use this.t() to get corresponding language data 
       const factArr = this.t('FACTS'); 
       const factIndex = Math.floor(Math.random() * factArr.length); 
       const randomFact = factArr[factIndex]; 
       // Create speech output 
       const speechOutput = this.t('GET_FACT_MESSAGE') + randomFact; 
       this.emit(':tellWithCard', speechOutput, this.t('SKILL_NAME'), randomFact); 
   }, 
   'AMAZON.HelpIntent': function () { 
       const speechOutput = this.t('HELP_MESSAGE'); 
       const reprompt = this.t('HELP_MESSAGE'); 
       this.emit(':ask', speechOutput, reprompt); 
   }, 
   'AMAZON.CancelIntent': function () { 
       this.emit(':tell', this.t('STOP_MESSAGE')); 
   }, 
   'AMAZON.StopIntent': function () { 
       this.emit(':tell', this.t('STOP_MESSAGE')); 
   }, 
}; 
exports.handler = function (event, context) { 
   const alexa = Alexa.handler(event, context); 
   alexa.APP_ID = APP_ID; 
   // To enable string internationalization (i18n) features, set a resources object. 
   alexa.resources = languageStrings; 
   alexa.registerHandlers(handlers); 
   alexa.execute(); 
};  

Credits

Ajinkya Bapat

Ajinkya Bapat

2 projects • 1 follower
DevOps Engineer Tech Blogger Real Madrid Fan!

Comments