Tyler Steck
Created June 8, 2017

Alexa Skill - Alexa Skill with card images from S3

This skill will help teach you how to create an Alexa skill that will display an image from S3.

174
Alexa Skill - Alexa Skill with card images from S3

Things used in this project

Story

Read more

Schematics

Alexa skill with S3 data

This is the data flow of an Alexa skill with S3 data storage.
Image pulled from: https://www.linkedin.com/pulse/amazon-alexa-skill-development-creation-morse-coder-kay-lerch

Code

Lambda Function

JavaScript
This is the code for the Lambda Function
/* eslint-disable  func-names */
/* eslint quote-props: ["error", "consistent"]*/

'use strict';

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

const APP_ID = null

var HELP_MESSAGE = 'You can say next temple, or temples to show a picture of a lds temple on your alexa app?';
var HELP_REPROMPT = 'You can say next temple, or temples';
var STOP_MESSAGE = 'Have a blessed day!';


const handlers = {
    'c': function () {
        this.emit('GetTemple');
    },
    'TempleFactIntent': function () {
        this.emit('GetTemple');
    },
    'GetTemple': function () {
        const templeIndex = Math.floor(Math.random() * temples.length);
        const templeObj = temples[templeIndex];

        var imageObj = {
                            smallImageUrl: templeObj.src,
                            largeImageUrl: templeObj.src
                        };
        
        var speech = templeObj.name + "! Please check the alexa app for a picture."
        var repromptSpeech = 'You can say next temple, or temples';
        
        this.emit(':askWithCard', speech ,repromptSpeech ,templeObj.name, templeObj.name + " by: " + templeObj.copyright, imageObj);
    },
    'AMAZON.HelpIntent': function () {
        const speechOutput = HELP_MESSAGE;
        const reprompt = HELP_MESSAGE;
        this.emit(':ask', speechOutput, reprompt);
    },
    'AMAZON.CancelIntent': function () {
        this.emit(':tell', STOP_MESSAGE)
    },
    'AMAZON.StopIntent': function () {
        this.emit(':tell', STOP_MESSAGE);
    },
    'Unhandled': function() {
        this.emit('GetTemple');
    }
};

exports.handler = function (event, context) {
    const alexa = Alexa.handler(event, context);
    alexa.APP_ID = APP_ID;
    alexa.registerHandlers(handlers);
    alexa.execute();
};

var temples = [
    {
        "name": "Draper Utah",
        "src": "https://s3.amazonaws.com/lds-temples/draper-mormon-temple21.jpg",
        "copyright": "David C. Moore"
    },
    {
        "name": "Brigham City Utah",
        "src": "https://s3.amazonaws.com/lds-temples/brigham-city-mormon-temple5.jpg",
        "copyright": "Neil D Johnson"
    },
    {
        "name": "Bountiful Utah",
        "src": "https://s3.amazonaws.com/lds-temples/bountiful-mormon-temple28.jpg",
        "copyright": "Doug Havens"
    },
    {
        "name": "Manti Utah",
        "src": "https://s3.amazonaws.com/lds-temples/manti-mormon-temple71.jpg",
        "copyright": "Ronald E. Larsen"
    },
    {
        "name": "Manti Utah",
        "src": "https://s3.amazonaws.com/lds-temples/manti-mormon-temple9.jpg",
        "copyright": "Rick Satterfield"
    },
    {
        "name": "Mount Timpanogos Utah",
        "src": "https://s3.amazonaws.com/lds-temples/mount-timpanogos-mormon-temple54.jpg",
        "copyright": "Ivan Makarov"
    },
    {
        "name": "Mount Timpanogos Utah",
        "src": "https://s3.amazonaws.com/lds-temples/mount-timpanogos-mormon-temple75.jpg",
        "copyright": "Steven M. Reyes"
    },
    {
        "name": "Mount Timpanogos Utah",
        "src": "https://s3.amazonaws.com/lds-temples/mount-timpanogos-mormon-temple76.jpg",
        "copyright": "Steven M. Reyes"
    },
    {
        "name": "Jordan River Utah",
        "src": "https://s3.amazonaws.com/lds-temples/jordan-river-mormon-temple89.jpg",
        "copyright": "Steven M. Reyes"
    },
    {
        "name": "Logan Utah",
        "src": "https://s3.amazonaws.com/lds-temples/logan-mormon-temple8.jpg",
        "copyright": "Rick Satterfield"
    },
    {
        "name": "Logan Utah",
        "src": "https://s3.amazonaws.com/lds-temples/logan-mormon-temple2.jpg",
        "copyright": "Rick Satterfield"
    },
    {
        "name": "Logan Utah",
        "src": "https://s3.amazonaws.com/lds-temples/logan-mormon-temple13.jpg",
        "copyright": "Andy Nelson"
    }
];

Credits

Tyler Steck

Tyler Steck

0 projects • 2 followers

Comments