app.js
10.5 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
const express = require('express');
const line = require('@line/bot-sdk');
const config = {
channelAccessToken: 'L+RJ15lZgeSoWgeHf9BqgEhm8lYh11qALzPlDV85VGXHfmiKqj3CX1V9DvqakFeJqwWgfQRejsUIWqf/kJuTLQcRC5ws2pyJJbr0VFEXptoYicgiRDzuA51W91dTcFL6/olvLNS1zAf1xO2wxpTGvQdB04t89/1O/w1cDnyilFU=',
channelSecret: 'e8e139b4cf31d22ed234d62a9b336e74'
};
const app = express();
app.post('/webhook', line.middleware(config), (req, res) => {
Promise
.all(req.body.events.map(handleEvent))
.then((result) => res.json(result));
});
const client = new line.Client(config);
function handleEvent(event) {
if (event.type !== 'message' || event.message.type !== 'text') {
return Promise.resolve(null);
}
return client.replyMessage(event.replyToken, {
type: 'text',
text: event.message.text
});
}
app.listen(3000);
/*
var express = require('express');
var app = express();
const line = require('@line/bot-sdk');
const config = {
channelAccessToken: 'L+RJ15lZgeSoWgeHf9BqgEhm8lYh11qALzPlDV85VGXHfmiKqj3CX1V9DvqakFeJqwWgfQRejsUIWqf/kJuTLQcRC5ws2pyJJbr0VFEXptoYicgiRDzuA51W91dTcFL6/olvLNS1zAf1xO2wxpTGvQdB04t89/1O/w1cDnyilFU=',
channelSecret: 'e8e139b4cf31d22ed234d62a9b336e74',
};
<<<<<<< HEAD
const app = express();
app.post('https://bots.dialogflow.com/line/d1584d25-0e52-48da-b6cc-20e021dc5e70/webhook', line.middleware(config), (req,res)=>{
promise
.all(req.body.events.map(handleEvent))
.then((result)=>res.json(result));
});
const clinet = new line.Client(config);
function handleEvent(event){
if(event.type !== 'message' || event.message.type != 'text'){
return Promise.resolve(null);
}
return client.replyMessage(event.replyToken,{
type:'text',
text: event.message.text
});
}
=======
// create LINE SDK client
const client = new line.Client(config);
// create Express app
// about Express itself: https://expressjs.com/
// register a webhook handler with middleware
// about the middleware, please refer to doc
app.post('https://mylinebottest1.herokuapp.com/callback', line.middleware(config), (req, res) => {
Promise
.all(req.body.events.map(handleEvent))
.then((result) => res.json(result))
.catch((err) => { //error handling
console.error(err);
res.status(200).end();
});
});
// event handler
function handleEvent(event) {
if (event.type !== 'message' || event.message.type !== 'text') {
// ignore non-text-message event
return Promise.resolve(null);
}
return new Promise(function (resolve, reject) {
//내가 짠 것
function getup(shour, smin, ampm) {//몇시에 자려고 할 때 언제 일어나면 좋을지
if (shour != '(hour)' && smin != '(minute)') {
//; //탈출
var setTime = new Date();
if (shour == 12) {
shour = 0;
}
if (ampm == "AM") {
setTime.setHours(shour);
}
else if (ampm == "PM") {
setTime.setHours(shour + 12);
}
setTime.setMinutes(smin);
var gres1 = new Date(setTime.getTime() - 270 * 60000);
var gres2 = new Date(res1.getTime() - 90 * 60000);
var gres3 = new Date(res2.getTime() - 90 * 60000);
var gres4 = new Date(res3.getTime() - 90 * 60000);
function retDate(dateObj) {
var formatted = '';
var pm = false;
if (dateObj.getHours() > 12) {
formatted = dateObj.getHours() - 12;
pm = true;
}
else if (dateObj.getHours() < 12 && dateObj.getHours() != 0) {
formatted = dateObj.getHours();
}
else if (dateObj.getHours() == 0) {
formatted = "12";
}
else if (dateObj.getHours() == 12) {
formatted = "12";
pm = true;
}
if (dateObj.getMinutes() < 10) {
formatted = formatted + ":0" + dateObj.getMinutes();
}
else {
formatted = formatted + ":" + dateObj.getMinutes();
}
if (pm == true) {
formatted = formatted + " PM";
}
else {
formatted = formatted + " AM";
}
return formatted;
}
console.log(String(retDate(gres1)));
console.log(String(retDate(gres2)));
console.log(String(retDate(gres3)));
console.log(String(retDate(gres4)));
$('#results').fadeIn();
$('#feedback').fadeIn();
$('#ad').fadeIn();
} // end hour/minute check if
else {
alert("Please select an hour and a minute before trying to calculate!");
} // end not-filled check
};// end calculate
})};
function sleep(ghour, gmin, ampm) { //몇시에 일어나려고 할 때 언제 자면 좋을지
//$('#start').hide();
var zDate = new Date();
var sres1 = new Date(zDate.getTime() + 104*60000);
var sres2 = new Date(res1.getTime() + 90*60000);
var sres3 = new Date(res2.getTime() + 90*60000);
var sres4 = new Date(res3.getTime() + 90*60000);
var sres5 = new Date(res4.getTime() + 90*60000);
var sres6 = new Date(res5.getTime() + 90*60000);
function retDate(dateObj) {
var formatted = '';
var pm = false;
if(dateObj.getHours() > 12) {
formatted = dateObj.getHours() - 12;
pm = true;
} else if(dateObj.getHours() < 12 && dateObj.getHours() != 0) {
formatted = dateObj.getHours();
} else if(dateObj.getHours() == 0) {
formatted = "12";
} else if(dateObj.getHours() == 12) {
formatted = "12";
pm = true;
}
if(dateObj.getMinutes() < 10) {
formatted = formatted + ":0" + dateObj.getMinutes();
} else {
formatted = formatted + ":" + dateObj.getMinutes();
}
if(pm == true) {
formatted = formatted + " PM";
} else {
formatted = formatted + " AM";
}
return formatted;
}
console.log(String(retDate(sres1)));
console.log(String(retDate(sres2)));
console.log(String(retDate(sres3)));
console.log(String(retDate(sres4)));
console.log(String(retDate(sres5)));
console.log(String(retDate(sres6)));
$('#resultsNow').fadeIn();
$('#feedback').fadeIn();
$('#ad').fadeIn();
};
*/
/*
//sleep 함수
console.log("You should try to fall asleep at one of the following times: ");
"sres1" title="Six Cycles: Nine Hours of Sleep"
or
"sres2" title="Five Cycles: Seven and a half Hours of Sleep"
or
"sres3" title="Four Cycles: Six Hours of Sleep"
or
"sres4" title="Three Cycles: Four and a half Hours of Sleep">
console.log("Please keep in mind that you should be falling asleep at these times.");
console.log("The average human takes fourteen minutes to fall asleep, so plan accordingly!");
console.log("꿀잠봇 works by counting backwards in sleep cycles.");
console.log("Waking up in the middle of a sleep cycle leaves you feeling tired and groggy, but waking up in between cycles wakes you up feeling refreshed and alert!");
console.log("A good night's sleep consists of 5-6 complete sleep cycles.");
//getup 함수
console.log("If you head to bed right now, you should try to wake up at one of the following times:");
"gres1" title="One Cycle: One and a half Hours of Sleep"
or
"gres2" title="Two Cycles: Three Hours of Sleep"
or
"gres3" title="Three Cycles: Four and a half Hours of Sleep"
or
"gres4" title="Four Cycles: Six Hours of Sleep"
or
"gres5" title="Five Cycles: Seven and a half Hours of Sleep"
or
"gres6" title="Six Cycles: Nine Hours of Sleep"
console.log("Please keep in mind that you should try to wake up at one of these times.");
console.log("The average human takes fourteen minutes to fall asleep, so plan accordingly!");
console.log("꿀잠봇 works by counting backwards in sleep cycles.");
console.log("Waking up in the middle of a sleep cycle leaves you feeling tired and groggy, but waking up in between cycles wakes you up feeling refreshed and alert!");
console.log("A good night's sleep consists of 5-6 complete sleep cycles.");
*/
/*
//언어 감지 option
var detect_options = {
url : languagedetect_api_url,
form : {'query': event.message.text},
headers: {'X-Naver-Client-Id': client_id, 'X-Naver-Client-Secret': client_secret}
};
//papago 언어 감지
request.post(detect_options,function(error,response,body){
console.log(response.statusCode);
if(!error && response.statusCode == 200){
var detect_body = JSON.parse(response.body);
var source = '';
var target = '';
var result = { type: 'text', text:''};
//언어 감지가 제대로 됐는지 확인
console.log(detect_body.langCode);
//번역은 한국어->영어 / 영어->한국어만 지원
if(detect_body.langCode == 'ko'||detect_body.langCode == 'en'){
source = detect_body.langCode == 'ko' ? 'ko':'en';
target = source == 'ko' ? 'en':'ko';
//papago 번역 option
var options = {
url: translate_api_url,
// 한국어(source : ko), 영어(target: en), 카톡에서 받는 메시지(text)
form: {'source':source, 'target':target, 'text':event.message.text},
headers: {'X-Naver-Client-Id': client_id, 'X-Naver-Client-Secret': client_secret}
};
// Naver Post API
request.post(options, function(error, response, body){
// Translate API Sucess
if(!error && response.statusCode == 200){
// JSON
var objBody = JSON.parse(response.body);
// Message 잘 찍히는지 확인
result.text = objBody.message.result.translatedText;
console.log(result.text);
//번역된 문장 보내기
client.replyMessage(event.replyToken,result).then(resolve).catch(reject);
}
});
}
// 메시지의 언어가 영어 또는 한국어가 아닐 경우
else{
result.text = '언어를 감지할 수 없습니다. \n 번역 언어는 한글 또는 영어만 가능합니다.';
client.replyMessage(event.replyToken,result).then(resolve).catch(reject);
}
}
});
*/
>>>>>>> heroku
app.listen(3000, function () {
console.log('Linebot listening on port 3000!');
});