Skip to content

Commit b13191a

Browse files
author
Bogdan Abaev
committed
minor fix
1 parent 3a026da commit b13191a

File tree

3 files changed

+264
-2
lines changed

3 files changed

+264
-2
lines changed

CLI/CLI.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const yargs = require('yargs')
22
const request = require('request')
33
const fs = require('fs');
44
//host = "http://localhost:3000";
5-
host = "http://18.233.168.151:80";
5+
host = "http://54.237.77.73:80";
66
path = "/Users/bogdanabaev/RandomProgramming/node/notes/CLI/";
77

88

CLI/alexa_lambda.js

Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
2+
const Alexa = require('ask-sdk-core');
3+
const request = require('request');
4+
const host = "http://18.233.168.151:80";
5+
6+
const sendQuery = function(query, handlerInput) {
7+
return new Promise((resolve,reject) => {
8+
const username = handlerInput.requestEnvelope.session.user.userId;
9+
request.post({
10+
headers: {
11+
'Content-Type': 'application/json',
12+
'Accept': 'application/json',
13+
},
14+
url: host + "/graphql",
15+
body: JSON.stringify({ "query": query })
16+
}, (err, result) => {
17+
if (err) {
18+
resolve(handlerInput.responseBuilder
19+
.speak("Something went wrong!")
20+
.withSimpleCard('Oops...', "Something broken on our part")
21+
.getResponse());
22+
} else {
23+
console.log("body");
24+
console.log(result.body);
25+
const data = JSON.parse(result.body).data.time;
26+
const key = Object.keys(data)[0];
27+
var output = data[`${key}`];
28+
if (handlerInput.requestEnvelope.request.intent.name == "ls"){
29+
var temp = "Your activities are: ";
30+
output.forEach((prj)=>{
31+
temp = temp + prj + ", ";
32+
});
33+
output = temp;
34+
} else if (handlerInput.requestEnvelope.request.intent.name == "report"){
35+
36+
}
37+
console.log("Result");
38+
console.log(output);
39+
resolve(handlerInput.responseBuilder
40+
.speak(output)
41+
.withSimpleCard('Got it!!!', output)
42+
.getResponse());
43+
}
44+
})
45+
});
46+
}
47+
48+
49+
50+
51+
const LaunchRequestHandler = {
52+
canHandle(handlerInput) {
53+
return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
54+
},
55+
handle(handlerInput) {
56+
const speechText = 'Describe time tracker';
57+
58+
return handlerInput.responseBuilder
59+
.speak(speechText)
60+
.reprompt(speechText)
61+
.withSimpleCard('Hello World', speechText)
62+
.getResponse();
63+
},
64+
};
65+
66+
67+
68+
const HelpIntentHandler = {
69+
canHandle(handlerInput) {
70+
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
71+
&& handlerInput.requestEnvelope.request.intent.name === 'AMAZON.HelpIntent';
72+
},
73+
handle(handlerInput) {
74+
const speechText = 'Help intent';
75+
76+
return handlerInput.responseBuilder
77+
.speak(speechText)
78+
.reprompt(speechText)
79+
.withSimpleCard('Hello World', speechText)
80+
.getResponse();
81+
},
82+
};
83+
84+
const CancelAndStopIntentHandler = {
85+
canHandle(handlerInput) {
86+
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
87+
&& (handlerInput.requestEnvelope.request.intent.name === 'AMAZON.CancelIntent'
88+
|| handlerInput.requestEnvelope.request.intent.name === 'AMAZON.StopIntent');
89+
},
90+
handle(handlerInput) {
91+
const speechText = 'Goodbye!';
92+
93+
return handlerInput.responseBuilder
94+
.speak(speechText)
95+
.withSimpleCard('Hello World', speechText)
96+
.getResponse();
97+
},
98+
};
99+
100+
// const SessionEndedRequestHandler = {
101+
// canHandle(handlerInput) {
102+
// return handlerInput.requestEnvelope.request.type === 'SessionEndedRequest';
103+
// },
104+
// handle(handlerInput) {
105+
// console.log(`Session ended with reason: ${handlerInput.requestEnvelope.request.reason}`);
106+
107+
// return handlerInput.responseBuilder.getResponse();
108+
// },
109+
// };
110+
111+
const ErrorHandler = {
112+
canHandle() {
113+
return true;
114+
},
115+
handle(handlerInput, error) {
116+
console.log(`Error handled: ${error.message}`);
117+
console.log(`Intent: ${handlerInput.requestEnvelope.request.intent.name}`);
118+
return handlerInput.responseBuilder
119+
.speak('Sorry, I can\'t understand the command. Please say again.')
120+
.reprompt('Sorry, I can\'t understand the command. Please say again.')
121+
.getResponse();
122+
},
123+
};
124+
125+
126+
127+
/////////////////////////////
128+
129+
const createProjectIntentHandler = {
130+
canHandle(handlerInput) {
131+
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
132+
&& handlerInput.requestEnvelope.request.intent.name === 'createProject';
133+
},
134+
135+
handle(handlerInput) {
136+
const project = handlerInput.requestEnvelope.request.intent.slots.projectName.value;
137+
console.log("Create project");
138+
var query = `{
139+
time(username: "username"){
140+
create(projectName: "${project}")
141+
}
142+
}`;
143+
return sendQuery(query,handlerInput);
144+
}
145+
};
146+
147+
const startProjectIntentHandler = {
148+
canHandle(handlerInput) {
149+
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
150+
&& handlerInput.requestEnvelope.request.intent.name === 'startProject';
151+
},
152+
handle(handlerInput) {
153+
console.log("Start project");
154+
const project = handlerInput.requestEnvelope.request.intent.slots.projectName.value;
155+
var query = `{
156+
time(username: "username"){
157+
start(projectName: "${project}")
158+
}
159+
}`;
160+
return sendQuery(query,handlerInput);
161+
}
162+
};
163+
164+
165+
const finishProjectIntentHandler = {
166+
canHandle(handlerInput) {
167+
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
168+
&& handlerInput.requestEnvelope.request.intent.name === 'finishProject';
169+
},
170+
handle(handlerInput) {
171+
console.log("Finish project");
172+
var query = `{
173+
time(username: "username"){
174+
end
175+
}
176+
}`;
177+
return sendQuery(query,handlerInput);
178+
}
179+
};
180+
181+
182+
const deleteProjectIntentHandler = {
183+
canHandle(handlerInput) {
184+
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
185+
&& handlerInput.requestEnvelope.request.intent.name === 'deleteProject';
186+
},
187+
handle(handlerInput) {
188+
console.log("Delete project");
189+
const project = handlerInput.requestEnvelope.request.intent.slots.projectName.value;
190+
var query = `{
191+
time(username: "username"){
192+
remove(projectName: "${project}")
193+
}
194+
}`;
195+
return sendQuery(query,handlerInput);
196+
}
197+
};
198+
199+
200+
const lsIntentHandler = {
201+
canHandle(handlerInput) {
202+
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
203+
&& handlerInput.requestEnvelope.request.intent.name === 'ls';
204+
},
205+
handle(handlerInput) {
206+
console.log("Ls");
207+
var query = `{
208+
time(username: "username"){
209+
ls
210+
}
211+
}`;
212+
return sendQuery(query,handlerInput);
213+
}
214+
};
215+
216+
const currentIntentHandler = {
217+
canHandle(handlerInput) {
218+
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
219+
&& handlerInput.requestEnvelope.request.intent.name === 'current';
220+
},
221+
handle(handlerInput) {
222+
console.log("Current project");
223+
var query = `{
224+
time(username: "username"){
225+
current
226+
}
227+
}`;
228+
return sendQuery(query,handlerInput);
229+
}
230+
};
231+
232+
233+
const reportIntentHandler = {
234+
canHandle(handlerInput) {
235+
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
236+
&& handlerInput.requestEnvelope.request.intent.name === 'report';
237+
},
238+
handle(handlerInput) {
239+
return sendQuery(query,handlerInput);
240+
}
241+
};
242+
243+
244+
245+
const skillBuilder = Alexa.SkillBuilders.custom();
246+
247+
exports.handler = skillBuilder
248+
.addRequestHandlers(
249+
LaunchRequestHandler,
250+
HelpIntentHandler,
251+
CancelAndStopIntentHandler,
252+
//SessionEndedRequestHandler,
253+
createProjectIntentHandler,
254+
startProjectIntentHandler,
255+
finishProjectIntentHandler,
256+
reportIntentHandler,
257+
lsIntentHandler,
258+
currentIntentHandler,
259+
deleteProjectIntentHandler
260+
)
261+
.addErrorHandlers(ErrorHandler)
262+
.lambda();

server/mongoUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
const { MongoClient} = require('mongodb');
33

4-
const connectionUrl = 'mongodb://mongo:27017/';
4+
const connectionUrl = process.env.DB_URL? process.env.DB_URL: 'mongodb://127.0.0.1:27017/';
55
//const connectionUrl = 'mongodb://127.0.0.1:27017';
66

77
const database = 'task_manager'

0 commit comments

Comments
 (0)