From 5b948f105a4c00ade4144164d77a7924547025c8 Mon Sep 17 00:00:00 2001 From: rca Date: Wed, 17 Jul 2024 09:19:25 +0900 Subject: [PATCH] =?UTF-8?q?TaskList=E3=81=AE=E3=83=8F=E3=83=B3=E3=83=89?= =?UTF-8?q?=E3=83=A9=E5=AE=9F=E8=A3=85,=20Complete=E4=BB=AE=E7=BD=AE?= =?UTF-8?q?=E3=81=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/index.ts b/src/index.ts index 3de9446..8bc71d6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,6 +4,9 @@ import * as DynamoDBPersistantAttributesAdapter from 'ask-sdk-dynamodb-persisten import { DialogState } from 'ask-sdk-model'; import MetaService from './service/MetaService'; import AuthService from './service/AuthService'; +import TaskService from './service/TaskService'; +import { TaskListResponse } from './models/Task'; +import AttributeUtils from './AttributeUtils'; const LaunchRequestHandler = { canHandle(handlerInput: Alexa.HandlerInput) { @@ -55,6 +58,34 @@ const KidShiftAuthIntentHandler = { } }; +const KidShiftTaskListIntentHandler = { + canHandle(handlerInput: Alexa.HandlerInput) { + return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' + && Alexa.getIntentName(handlerInput.requestEnvelope) === 'KidShiftTaskListIntent'; + }, + async handle(handlerInput: Alexa.HandlerInput) { + const attributeUtils = new AttributeUtils(handlerInput); + TaskService.setToken(await attributeUtils.getToken()); + + const taskList: TaskListResponse = await TaskService.getTasks(); + return handlerInput.responseBuilder + .speak(taskList.list.map((task) => task.name).join(', ')) + .getResponse(); + } +}; + +const KidShiftTaskCompleteIntentHandler = { + canHandle(handlerInput: Alexa.HandlerInput) { + return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' + && Alexa.getIntentName(handlerInput.requestEnvelope) === 'KidShiftTaskCompleteIntent'; + }, + async handle(handlerInput: Alexa.HandlerInput) { + return handlerInput.responseBuilder // Placeholder + .speak('WIP') + .getResponse(); + } +}; + const KidShiftMetaIntentHandler = { canHandle(handlerInput: Alexa.HandlerInput) { @@ -164,6 +195,8 @@ exports.handler = Alexa.SkillBuilders.custom() LaunchRequestHandler, HelloWorldIntentHandler, KidShiftAuthIntentHandler, + KidShiftTaskListIntentHandler, + KidShiftTaskCompleteIntentHandler, KidShiftMetaIntentHandler, HelpIntentHandler, CancelAndStopIntentHandler,