Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alexa translations #2707

Merged
merged 7 commits into from
Sep 11, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 39 additions & 39 deletions lib/api/alexa/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ var _ = require('lodash');
function configure (app, wares, ctx, env) {
var entries = ctx.entries;
var express = require('express')
, api = express.Router( )
;
, api = express.Router( );
var translate = ctx.language.translate;

// invoke common middleware
api.use(wares.sendJSONStatus);
Expand Down Expand Up @@ -43,7 +43,16 @@ function configure (app, wares, ctx, env) {
});

api.post('/alexa', ctx.authorization.isPermitted('api:*:read'), function (req, res, next) {
console.log('Incoming request from Alexa');
console.log('Incoming request from Alexa');
var locale = req.body.request.locale;
if(locale){
if(locale.length > 2) {
locale = locale.substr(0, 2);
}
ctx.language.set(locale);
moment.locale(locale);
}

switch (req.body.request.type) {
case 'IntentRequest':
onIntent(req.body.request.intent, function (title, response) {
Expand All @@ -67,57 +76,48 @@ function configure (app, wares, ctx, env) {
});

ctx.alexa.addToRollup('Status', function bgRollupHandler(slots, sbx, callback) {
entries.list({count: 1}, function(err, records) {
var direction = '';
if (records[0].direction === 'FortyFiveDown') {
direction = ' and slightly dropping';
} else if (records[0].direction === 'FortyFiveUp') {
direction = ' and slightly rising';
} else if (records[0].direction === 'Flat') {
direction = ' and holding';
} else if (records[0].direction === 'SingleUp') {
direction = ' and rising';
} else if (records[0].direction === 'SingleDown') {
direction = ' and dropping';
} else if (records[0].direction === 'DoubleDown') {
direction = ' and rapidly dropping';
} else if (records[0].direction === 'DoubleUp') {
direction = ' and rapidly rising';
entries.list({count: 1}, function (err, records) {
var direction;
if (translate(records[0].direction)) {
direction = translate(records[0].direction);
} else {
direction = records[0].direction;
}
var status = sbx.scaleMgdl(records[0].sgv) + direction + ' as of ' + moment(records[0].date).from(moment(sbx.time)) + '.';
var status = translate('alexaStatus', {
params: [
sbx.scaleMgdl(records[0].sgv),
direction,
moment(records[0].date).from(moment(sbx.time))
]
});
//var status = sbx.scaleMgdl(records[0].sgv) + direction + ' as of ' + moment(records[0].date).from(moment(sbx.time)) + '.';
callback(null, {results: status, priority: -1});
});
// console.log('BG results called');
// callback(null, 'BG results');
}, 'BG Status');

ctx.alexa.configureIntentHandler('MetricNow', function (callback, slots, sbx) {
ctx.alexa.configureIntentHandler('MetricNow', function ( callback, slots, sbx, locale) {
entries.list({count: 1}, function(err, records) {
var direction = '';
if (records[0].direction === 'FortyFiveDown') {
direction = ' and slightly dropping';
} else if (records[0].direction === 'FortyFiveUp') {
direction = ' and slightly rising';
} else if (records[0].direction === 'Flat') {
direction = ' and holding';
} else if (records[0].direction === 'SingleUp') {
direction = ' and rising';
} else if (records[0].direction === 'SingleDown') {
direction = ' and dropping';
} else if (records[0].direction === 'DoubleDown') {
direction = ' and rapidly dropping';
} else if (records[0].direction === 'DoubleUp') {
direction = ' and rapidly rising';
var direction;
if(translate(records[0].direction)){
direction = translate(records[0].direction);
} else {
direction = records[0].direction;
}
var status = sbx.scaleMgdl(records[0].sgv) + direction + ' as of ' + moment(records[0].date).from(moment(sbx.time));
var status = translate('alexaStatus', {
params: [
sbx.scaleMgdl(records[0].sgv),
direction,
moment(records[0].date).from(moment(sbx.time))]
});
//var status = sbx.scaleMgdl(records[0].sgv) + direction + ' as of ' + moment(records[0].date).from(moment(sbx.time));
callback('Current blood glucose', status);
});
}, 'metric', ['bg', 'blood glucose', 'number']);

ctx.alexa.configureIntentHandler('NSStatus', function(callback, slots, sbx) {
ctx.alexa.getRollup('Status', sbx, slots, function (status) {
ctx.alexa.configureIntentHandler('NSStatus', function(callback, slots, sbx, locale) {
ctx.alexa.getRollup('Status', sbx, slots, locale, function (status) {
callback('Full status', status);
});
});
Expand Down
Loading