-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
60 lines (44 loc) · 1.76 KB
/
main.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
const googlehome = require('google-home-notifier');
const googlehome_name = 'Your Google Home Name'; // Google Homeの名前(なんでもいい)
const googlehome_ip = '192.168.11.5'; // Google HomeのIPアドレス
const language = 'ja'; // Google Homeに喋らせたい言語(usで英語です)
const message = 'てすと'; // 喋らせたい内容
var config = require('config');
console.log(config);
config.userList.forEach(item => {
console.log(item.user.userId);
});
//config.
var http = require('http');
http.createServer(function (request, response) {
let post_data = '';
request.on('data', function (chunk) {
post_data += chunk;
});
request.on('end', function () {
console.log('post_data : ' + post_data);
const webhook = JSON.parse(post_data).events[0];
if (webhook.type != 'message' || webhook.message.type != 'text') {
return;
}
let userName ="";
if (webhook.source.userId === "XXXX") {
userName = "NAME1";
} else if(webhook.source.userId === "YYYY") {
userName = "NAME2";
}
// 特定の人からのメッセージのみ発話
let str = userName + "です。" + webhook.message.text;
//const data_text = webhook.message.text;
// googlehome_speak(config.beginning_sentence + data_text);
googlehome.device(googlehome_name, language);
googlehome.ip(googlehome_ip);
googlehome.notify(str, (res) => {
console.log(res);
});
response.writeHead(200, { 'Content-Type': 'text/plain' });
response.end();
});
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello Hosomichi!\n');
}).listen(3000, '127.0.0.1');