백승욱

Add main module

1 +{
2 + "TOKEN" : "Insert user token value",
3 + "KOFIC_KEY" : "Insert user key value",
4 + "domain" : "Insert user domain"
5 +}
...\ No newline at end of file ...\ No newline at end of file
1 +//=============================================================
2 +var express = require('express');
3 +const request = require('request');
4 +const config = require('./config.json');
5 +const dailyBoxOfficeList = require('./DailyBoxOfficeList.js');
6 +//=============================================================
7 +const LINE_URL = 'https://api.line.me/v2/bot/message/reply'
8 +const TOKEN = config.TOKEN;
9 +const BOXOFFICE_URL = 'http://www.kobis.or.kr/kobisopenapi/webservice/rest/boxoffice/searchDailyBoxOfficeList.json'
10 +const KOFIC_KEY = config.KOFIC_KEY;
11 +//=============================================================
12 +const fs = require('fs');
13 +const path = require('path');
14 +const HTTPS = require('https');
15 +const domain = config.domain;
16 +const sslport = 23023;
17 +const bodyParser = require('body-parser');
18 +var app = express();
19 +app.use(bodyParser.json());
20 +//=============================================================
21 +
22 +
23 +// RECEIVE MESSAGE
24 +app.post('/hook', function (req, res) {
25 +
26 + var eventObj = req.body.events[0];
27 +
28 + // console.log for debugging
29 + console.log('======================', new Date() ,'======================');
30 + console.log('[request]', req.body);
31 + console.log('[request source] ', eventObj.source);
32 + console.log('[request message]', eventObj.message);
33 +
34 + ClassifyMessage(eventObj.replyToken, eventObj.message.text);
35 +
36 + res.sendStatus(200);
37 +});
38 +
39 +
40 +// CLASSIFY MESSAGE
41 +function ClassifyMessage(replyToken, imessage){
42 +
43 + var message = String(imessage);
44 +
45 + // 사용자가 보낸 라인 메시지 문자열 안에 특정 문자열이 있으면, 특정 함수 실행
46 + if(message.includes('최신') || message.includes('순위') || message.includes('오늘') || message.includes('추천')) {
47 + dailyBoxOfficeList.ShowYesterdayRank(replyToken);
48 + } else if (message.includes('줄거리')) {
49 + // (예시) 영화 줄거리 출력
50 + }
51 + else if (message.includes('목록')) {
52 + // (예시) 영화 목록 출력
53 + }
54 +}
55 +
56 +
57 +// ※ WARNING: DO NOT TOUCH THIS CODE SECTION ※
58 +try {
59 + const option = {
60 + ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'),
61 + key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(),
62 + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(),
63 + };
64 +
65 + HTTPS.createServer(option, app).listen(sslport, () => {
66 + console.log(`[HTTPS] Server is started on port ${sslport}`);
67 + });
68 +} catch (error) {
69 + console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
70 + console.log(error);
71 +}
...\ No newline at end of file ...\ No newline at end of file
This diff is collapsed. Click to expand it.
1 +{
2 + "name": "trans",
3 + "version": "1.0.0",
4 + "description": "",
5 + "main": "app.js",
6 + "scripts": {
7 + "test": "echo \"Error: no test specified\" && exit 1"
8 + },
9 + "author": "",
10 + "license": "ISC",
11 + "dependencies": {
12 + "express": "^4.17.1",
13 + "request": "^2.88.2"
14 + }
15 +}