mirror of
https://github.com/r-ca/kidshift-skills.git
synced 2024-10-25 17:14:03 +00:00
仮置き
This commit is contained in:
parent
d848f04b4e
commit
4b28dca1e4
38
src/index.ts
38
src/index.ts
|
@ -7,6 +7,8 @@ import AuthService from './service/AuthService';
|
|||
import TaskService from './service/TaskService';
|
||||
import { TaskListResponse } from './models/Task';
|
||||
import AttributeUtils from './AttributeUtils';
|
||||
import { ChildListResponse } from './models/Child';
|
||||
import ChildService from './service/ChildService';
|
||||
|
||||
const LaunchRequestHandler = {
|
||||
canHandle(handlerInput: Alexa.HandlerInput) {
|
||||
|
@ -81,10 +83,42 @@ const KidShiftTaskCompleteIntentHandler = {
|
|||
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'KidShiftTaskCompleteIntent';
|
||||
},
|
||||
async handle(handlerInput: Alexa.HandlerInput) {
|
||||
return handlerInput.responseBuilder // Placeholder
|
||||
.speak('WIP')
|
||||
|
||||
const taskList: TaskListResponse = await TaskService.getTasks()
|
||||
|
||||
const childList: ChildListResponse = await ChildService.getChildList();
|
||||
|
||||
const taskName = Alexa.getSlotValue(handlerInput.requestEnvelope, 'taskName');
|
||||
|
||||
const childName = Alexa.getSlotValue(handlerInput.requestEnvelope, 'childName');
|
||||
|
||||
const task = taskList.list.find((task) => task.name === taskName);
|
||||
if (!task) {
|
||||
return handlerInput.responseBuilder
|
||||
.speak('Task not found')
|
||||
.getResponse();
|
||||
}
|
||||
|
||||
const child = childList.list.find((child) => child.name === childName);
|
||||
if (!child) {
|
||||
return handlerInput.responseBuilder
|
||||
.speak('Child not found')
|
||||
.getResponse();
|
||||
}
|
||||
|
||||
const attributeUtils = new AttributeUtils(handlerInput);
|
||||
TaskService.setToken(await attributeUtils.getToken());
|
||||
|
||||
TaskService.completeTask(task.id, child.id).then(() => {
|
||||
return handlerInput.responseBuilder
|
||||
.speak('Task completed')
|
||||
.getResponse();
|
||||
}).catch(() => {
|
||||
return handlerInput.responseBuilder
|
||||
.speak('Task completion failed')
|
||||
.getResponse();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user