-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObserverAPI.js
More file actions
93 lines (86 loc) · 3.19 KB
/
ObserverAPI.js
File metadata and controls
93 lines (86 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* eslint-disable func-names */
/* eslint quote-props: ["error", "consistent"]*/
/**
* Observation API gets from a REST API for a message
* with a description which will be parsed out and
* sent to Alexa Skills Custom - "Observation API"
**/
// arn:aws:lambda:us-east-1:822556179699:function:youtubeDataAPIAlexaSkill
'use strict';
const Alexa = require('alexa-sdk');
const APP_ID = "amzn1.ask.skill.270bc5ce-2d9a-4147-ad52-6907954caeb4";
var locale;
const languageStrings = {
'en-GB': {
translation: {
HELP_MESSAGE: 'You can say scan this or what\'s around me... What can I help you with?',
HELP_REPROMPT: 'What can I help you with?',
STOP_MESSAGE: 'Goodbye!',
},
},
'en-US': {
translation: {
HELP_MESSAGE: 'You can say scan this or what\'s around me... What can I help you with?',
HELP_REPROMPT: 'What can I help you with?',
STOP_MESSAGE: 'Goodbye!',
},
},
'de-DE': {
translation: {
HELP_MESSAGE: 'Du kannst sagen, Scannen Sie diese oder was ist um mich herum... Wie kann ich dir helfen?',
HELP_REPROMPT: 'Wie kann ich dir helfen?',
STOP_MESSAGE: 'Auf Wiedersehen!',
},
},
};
const handlers = {
'LaunchRequest': function () {
this.emit('Observe');
},
'Observe': function observe() {
const http = require('http');
let getFunc = (res) => {
// console.log("Got response: " + res.statusCode);
res.setEncoding('utf8');
let rawData = '';
res.on('data', (chunk) => rawData += chunk);
res.on('end', () => {
try {
console.log(rawData);
this.emit(':tell', "hmmm..." + rawData);
} catch (e) {
console.log(e.message);
}
});
};
let getFunc2 = () => {
const speechOutput = "I'm sorry, but I failed to get a message back from my server.";
this.emit(':tell', speechOutput);
};
// -----------------------------Adjust ngrok proxy here!-----------------------------------
http.get("http://341778e3.ngrok.io/search?language=" + locale, getFunc).on('error', getFunc2);
},
'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'));
},
'SessionEndedRequest': function () {
this.emit(':tell', this.t('STOP_MESSAGE'));
},
};
exports.handler = (event, context) => {
const alexa = Alexa.handler(event, context);
alexa.APP_ID = APP_ID;
locale = event.request.locale;
// To enable string internationalization (i18n) features, set a resources object.
alexa.resources = languageStrings;
alexa.registerHandlers(handlers);
alexa.execute();
};