Vijay Nawak
Created June 14, 2017

Fruit Facts

This skill tells you random and interesting facts about fruit.

14
Fruit Facts

Things used in this project

Hardware components

Echo Dot
Amazon Alexa Echo Dot
×1

Software apps and online services

AWS Lambda
Amazon Web Services AWS Lambda
Alexa Skills Kit
Amazon Alexa Alexa Skills Kit

Story

Read more

Code

Fruit Facts

JavaScript
the function returns a random fact about fruit when the trigger is activated. paste it into your AWS Lambda function code.
'use strict';

const Alexa = require('alexa-sdk');

const APP_ID = undefined;  // TODO replace with your app ID (OPTIONAL).

const languageStrings = {
    'en': {
        translation: {
            FACTS: [
                'A strawberry is not an actual berry, but a banana is.',
                'Grapes explode when you put them in the microwave.',
                'Apples, peaches and raspberries are all members of the rose family.',
                'Oranges are not even in the top ten list of common foods when it comes to vitamin C levels.',
                'The Most Popular Fruit in the world is the TOMATO.',
                'Coffee beans are not beans. They are fruit pits.',
                'Oranges contain antioxidants that help fight the free radicals that damage and age our skin',
                'Strawberries and cashews are the only fruits that have their seeds on the outside unlike all other fruits which have their seeds inside',
                'There are over 7000 different types of apples grown all over the world.',
                'Lemons can kill bacteria-as they have high content of acid which makes them suitable for cleaning.',
                'The cabbage encloses nearly as much water as watermelon. Watermelon contains 92% water where cabbage is 90% and carrots are 87%',
                'Sapodilla is a uniquely tasted fruit. It had a soft brown flesh which flavors like a sweet mix of brown sugar and root beer.',
                'The name pine-apple was the original name for a pine cone (grows on pine trees). Because the fruit pineapple looked like a huge pine cone, it too was called a pine-apple',
            ],
            SKILL_NAME: 'Fruit Facts',
            GET_FACT_MESSAGE: "Here's your fruit fact: ",
            HELP_MESSAGE: 'You can say tell me a fruit fact, 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 () {

        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

Vijay Nawak

Vijay Nawak

1 project • 0 followers

Comments