Skip to content

Commit

Permalink
v5
Browse files Browse the repository at this point in the history
  • Loading branch information
cazziwork committed Dec 27, 2019
1 parent 73e89e7 commit 2d0b530
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 15 deletions.
4 changes: 4 additions & 0 deletions src/helper/date-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ module.exports = class DateUtil {

case '今日':
case 'きょう':
case '明日':
case 'あした':
case '次の日':
case 'つぎのひ':
return '今日';

case '全て':
Expand Down
11 changes: 11 additions & 0 deletions src/helper/db-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ module.exports = class DAO {
this.attributesManager = attributesManager;
}

async getTemplateActionMode() {
let persistentAttributes = await this.attributesManager.getPersistentAttributes();
return persistentAttributes.template_action;
}

async setTemplateActionMode(mode) {
let persistentAttributes = await this.attributesManager.getPersistentAttributes();
persistentAttributes.template_action = mode;
this.save(persistentAttributes);
}

async getData() {
let persistentAttributes = await this.attributesManager.getPersistentAttributes();
return persistentAttributes.data;
Expand Down
19 changes: 10 additions & 9 deletions src/intent/SwitchActionModeIntent.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// const _ = require('lodash');
// const util = require('util');
const util = require('util');

// const DAO = require('../helper/db-access');
// const DateUtil = require('../helper/date-util');
const DAO = require('../helper/db-access');
const Message = require('../message');

const SwitchActionModeIntentHandler = {
Expand All @@ -13,13 +11,16 @@ const SwitchActionModeIntentHandler = {
async handle(handlerInput) {

const slots = handlerInput.requestEnvelope.request.intent.slots;
const flag = slots.flag.resolutions.resolutionsPerAuthority[0].values[0].value.id;
console.log('flag:', flag);

// フラグをDynamoDBに突っ込む
const id = slots.mode.resolutions.resolutionsPerAuthority[0].values[0].value.id;
const name = slots.mode.resolutions.resolutionsPerAuthority[0].values[0].value.name;

console.log('mode:', name);

const dynamo = new DAO(handlerInput);
await dynamo.setTemplateActionMode(Number(id));

return handlerInput.responseBuilder
.speak('スウィッチ')
.speak(util.format(Message.SWITCH_COMPLETE, name))
.withShouldEndSession(true)
.getResponse();
}
Expand Down
5 changes: 3 additions & 2 deletions src/intent/TellMeIntent.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ const TellMeIntentHandler = {
}

const { slots } = handlerInput.requestEnvelope.request.intent;
const day_of_week = DateUtil.cleansing(slots.day_of_week.value);
console.log('slots:', slots);

const day_of_week = DateUtil.cleansing(slots.day_of_week.value || '今日');
if ('' === day_of_week) {
let intentObj = handlerInput.requestEnvelope.request.intent;
intentObj.confirmationStatus = "IN_PROGRESS";
Expand All @@ -35,7 +37,6 @@ const TellMeIntentHandler = {
}

if ('今日' === day_of_week) {
// 曜日指定がない場合は今日と明日のゴミを返す
const today_list = DateUtil.getItemList(garbage_data, DateUtil.getToday());
const tommorow_list = DateUtil.getItemList(garbage_data, DateUtil.getTommorow());
let speechText = this.getGarbageWord(today_list, tommorow_list);
Expand Down
23 changes: 19 additions & 4 deletions src/intent/default/LaunchRequest.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@

const DAO = require('../../helper/db-access');
const DateUtil = require('../../helper/date-util');
const Message = require('../../message');

const LaunchRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
},
handle(handlerInput) {
async handle(handlerInput) {

// TODO 本当はここでDynamoを見に行ってデータが登録済みならいきなりゴミの日を知らせようとおもったけど、
// フレームワークの作りとしてできないため断念。
// 今後の機能拡張を期待してTODOのままとしておく。
console.log('userId:', handlerInput.requestEnvelope.context.System.user.userId);

const dynamo = new DAO(handlerInput);
const template_mode = await dynamo.getTemplateActionMode();
console.log('mode:', template_mode);

if (template_mode) {
// TellMeIntentへ
return handlerInput.responseBuilder
.addDelegateDirective({
name: 'TellMeIntent',
confirmationStatus: 'NONE',
slots: {}
})
.speak(DateUtil.getHourGreeting((new Date().getHours())))
.getResponse();
}

let speechText = DateUtil.getHourGreeting((new Date().getHours()));
speechText += Message.LAUNCH;
Expand Down
3 changes: 3 additions & 0 deletions src/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ module.exports = {
DELETE_AFTER: '続けて削除したい場合は<break time="0.3s"/>削除して<break time="0.3s"/>といってください。',
DELETE_ANOTHER: '他の曜日を削除したい場合は、たとえば<break time="0.3s"/>月曜を削除して<break time="0.3s"/>のように言ってください。',

// Switch
SWITCH_COMPLETE: '定型アクションモードを %s にしました。',

// etc
TODAYS_GARBAGE: '今日のゴミは',
TOMMOROW_GARBAGE: '明日のゴミは',
Expand Down

0 comments on commit 2d0b530

Please sign in to comment.