-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathchange-light-color.js
81 lines (73 loc) · 2.57 KB
/
change-light-color.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
'use strict';
let Promise = require('bluebird');
let hue = require('../sample_service/hue');
const COLOR_MAPPINGS = [
{label: "青",code: "5068FF"},
{label: "赤",code: "FF7B7B"},
{label: "黄",code: "FFFA6A"}
];
/*
** Change the color of LED lighting of Hue.
*/
module.exports = class SkillChangeLightColor {
constructor() {
this.required_parameter = {
color: {
message_to_confirm: {
line: {
type: "template",
altText: "何色にしますか?(青か赤か黄)",
template: {
type: "buttons",
text: "何色にしますか?",
actions: [
{type:"postback",label:"青",data:"青"},
{type:"postback",label:"赤",data:"赤"},
{type:"postback",label:"黄",data:"黄"}
]
}
},
facebook: {
text: "何色にしますか?",
quick_replies: [
{content_type:"text",title:"青",payload:"青"},
{content_type:"text",title:"赤",payload:"赤"},
{content_type:"text",title:"黄",payload:"黄"}
]
}
},
parse: this.parse_color
}
};
}
// サポートする色かどうかを判別しカラーコードに変化する
parse_color(value){
if (value === null || value == ""){
return false;
}
let parsed_value = {};
let found_color = false;
for (let color_mapping of COLOR_MAPPINGS){
if (value.replace("色", "") == color_mapping.label){
parsed_value = color_mapping.code;
found_color = true;
}
}
if (!found_color){
return false
}
return parsed_value;
}
// IFTTT経由でHueのカラーを変更する
finish(bot, bot_event, context){
return hue.change_color(context.confirmed.color).then(
(response) => {
let messages = [bot.create_message("了解しましたー。", "text")];
return bot.reply(bot_event, messages);
},
(response) => {
return Promise.reject("Failed to change light color.");
}
);
}
};