adrien
Created October 26, 2016 © GPL3+

My Meteo Alert

Every day, before starting activity or on demand, it is helpful to get alert info read by Vocal Device like Amazon ECHO (DOT)

BeginnerFull instructions provided4 hours167

Things used in this project

Hardware components

Amazon Echo
Amazon Alexa Amazon Echo
only one among these is required
×1
Amazon Tap
Amazon Alexa Amazon Tap
only one among these is required
×1
Echo Dot
Amazon Alexa Echo Dot
only one among these is required
×1

Software apps and online services

Alexa Skills Kit
Amazon Alexa Alexa Skills Kit
AWS Lambda
Amazon Web Services AWS Lambda
AWS DynamoDB
Amazon Web Services AWS DynamoDB
Amazon API Gateway

Story

Read more

Schematics

My Meteo Alert Vocal User Interface

describes the interactions between Amazon ECHO device(s) and the Alexa Flash Briefing Skill(s)

Code

Node JS index file

JavaScript
it implements the lambda function
// index.js
// author : adrien chan
//

'use strict';

// load modules : aws and dynamodb
var AWS = require("aws-sdk");
var dynamodb = new AWS.DynamoDB({apiVersion: '2012-08-10'});

console.log('Loading function');

exports.handler = (event, context, callback) => {

 // init current sign from event params or event config
    var currentSign;
    if (event.params !== undefined && event.params.querystring !== undefined) {
       currentSign = event.params.querystring.astrosign;
    }
    else
    if (event.astrosign !== undefined && event.astroSign !== '') {
        //console.log('astrosign noparam:'+event.astrosign);
        currentSign = event.astrosign;
    }

// guid dynamic    
function generateQuickGuid() {
    return Math.random().toString(36).substring(2, 15) +
        Math.random().toString(36).substring(2, 15);
}    

// onScan processes all records of table and generates horoscopes in json format
  function onScan(err, data) {
    if (err) {
        context.done(null, flash);
    } else {
        var horoscopes = [];
        data.Items.forEach(function(horoscope) {
            horoscopes.push({ uid: generateQuickGuid(), updateDate: now, titleText: horoscope.ThemeId.S +" Astro Meteo", mainText: horoscope.Content.S});
        });
        context.done(null, horoscopes);
    }
  }

  // init some variables
    var now = new Date().toISOString();
      var title = "my daily astro meteo ";
      var content ='astrology info extraction processing. Please retry after 10 mn.';
      var flash = { uid: generateQuickGuid(), updateDate: now, titleText: title, mainText:content};

// if no currentsign defined then call onScan for all records of table	  
if (currentSign === undefined || currentSign === '') {
  dynamodb.scan({ TableName: 'FlashBriefing' }, onScan);
}
else {
// get single record for currentSign
var params = { 
    TableName: "FlashBriefing",
    Key: {
        "ThemeId": {
          "S": currentSign
      },
    }
};

// then generates json data for currentSign
dynamodb.getItem(params, function(err, data) {
    if (err) {
        console.log(JSON.stringify(err, null, 2));
        context.done(null,flash);
    }
    else {
        console.log(JSON.stringify(data, null, 2));
        flash = { uid: generateQuickGuid(), updateDate: now, titleText: data.Item.ThemeId.S +" Astro Meteo", mainText:data.Item.ThemeId.S + " : "+data.Item.Content.S};
        context.done(null,flash);
    }
});    
}

};

Credits

adrien

adrien

4 projects • 3 followers
interested in technologies : android, azure, bots, amazon (AWS, ECHO,...), iot

Comments