forked from JasonMcz/bot-express
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchange-light-color.js
More file actions
73 lines (65 loc) · 2.08 KB
/
change-light-color.js
File metadata and controls
73 lines (65 loc) · 2.08 KB
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
'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: {
type: "template",
altText: "何色にしますか?(青か赤か黄)",
template: {
type: "buttons",
text: "何色にしますか?",
actions: [
{type:"postback",label:"青",data:"青"},
{type:"postback",label:"赤",data:"赤"},
{type:"postback",label:"黄",data:"黄"}
]
}
},
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 = [{
text: "了解しましたー。"
}];
return bot.reply(messages);
},
(response) => {
return Promise.reject("Failed to change light color.");
}
);
}
};