From 4b28dca1e4e984690a51a7bb6a0c7ec629f4abc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Wed, 17 Jul 2024 14:02:52 +0900 Subject: [PATCH] =?UTF-8?q?=E4=BB=AE=E7=BD=AE=E3=81=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 4dd94e0..996a168 100644 --- a/src/index.ts +++ b/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,9 +83,41 @@ 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(); + }); } };