임승현

Merge branch 'master' into 'master'

Add Chatbot Demo!



See merge request !38
1 +require('chromedriver');
2 +const request = require('request');
3 +const cheerio = require('cheerio');
4 +const puppeteer = require('puppeteer');
5 +
6 +const async = require('async');
7 +let express = require('express');
8 +let app = express();
9 +let bodyParser = require('body-parser');
10 +const { timeout } = require('async');
11 +
12 +const {Builder,until} = require('selenium-webdriver'); //모듈 불러오기
13 +const webdriver = require('selenium-webdriver');
14 +const chrome = require('selenium-webdriver/chrome');
15 +const { delayed } = require('selenium-webdriver/lib/promise');
16 +const By = webdriver.By;
17 +
18 +app.use(bodyParser.urlencoded({ extended: false }));
19 +app.use(bodyParser.json());
20 +
21 +const url_movies = "https://www.cgv.co.kr/movies/?lt=1&ft=0"; //끝의 쿼리 0은 개봉 전 영화도 포함하는 것. 예매율 순위 가져오기
22 +const url_theaters = "https://www.cgv.co.kr/theaters/"; //영화관 정보 가져오는 링크.
23 +const url_ticketing = "https://www.cgv.co.kr/ticket/"; //상영중인 영화 정보 가져오는 링크.
24 +
25 +let cgv_theaters = []; //영화관과 영화관 고유 코드를 담는 배열
26 +let cgv_movies = []; //예매율 상위 19위까지의 영화 정보(CGVMovieInfo Class의 인스턴스)들을 담는 배열.
27 +let cgv_accessible_movies = []; //선택한 일자, 영화관에서 예매할 수 있는 영화 이름과 영화 고유 코드를 담는 배열.
28 +
29 +//예매율 Top19위까지의 영화 정보를 관리하는 Class
30 +class CGVMovieInfo {
31 + constructor(title, rank, score, GoldenEgg, movieCode){
32 + this.title = title;
33 + this.rank = rank;
34 + this.score = score;
35 + this.GoldenEgg = GoldenEgg;
36 + this.movieCode = movieCode;
37 + }
38 +
39 + getTitle() { return this.title; }
40 + setTitle(title) { this.title = title; }
41 + getRank() { return this.rank; }
42 + setRank(rank) { this.rank = rank; }
43 + getScore() { return this.score; }
44 + setScore(score) { this.score = score; }
45 + getGoldenEgg() { return this.GoldenEgg; }
46 + setGoldenEgg(GoldenEgg) { this.GoldenEgg = GoldenEgg; }
47 + getMovieCode() { return this.movieCode; }
48 + setMovieCode(movieCode) { this.movieCode = movieCode; }
49 +
50 + printMovieInfo(){
51 + return {
52 + 'rank': this.rank + " : " + this.title,
53 + 'score': "예매율 : " + this.score + "%",
54 + 'goldenEgg': "골든에그지수 : " + this.GoldenEgg,
55 + 'movieCode': "영화코드 : " + this.movieCode
56 + };
57 + }
58 +
59 +}
60 +
61 +exports.init = () => {async.waterfall([
62 + async () => {
63 + //크롬 설정을 담은 객체 생성
64 + const driver_theaters = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();
65 + driver_theaters.get(url_theaters);
66 +
67 + //9개 권역별로 영화관 list들을 list의 element로 넣기.
68 + let selector = '#contents > div.sect-common > div > div.sect-city > ul > li:nth-child({}) > div > ul > li > a';
69 + let area = [];
70 + for(let i = 1; i <= 9; i++){
71 + let region = await driver_theaters.wait(until.elementsLocated(By.css(selector.replace("{}", i))));
72 + area.push(region);
73 + }
74 +
75 + //영화관 및 영화관에 대응되는 영화관별 고유 코드 가져오기.
76 + for (const theaters_by_area of area) {
77 + let theaters_info_by_area = [];
78 + for (const theater of theaters_by_area){
79 + let theater_info = {
80 + "theater_name" : await theater.getAttribute('title'),
81 + "theater_code" : await theater.getAttribute('href')
82 + };
83 + theater_info.theater_name = theater_info.theater_name.replace("CGV", "")
84 + theater_info.theater_code = theater_info.theater_code.replace(/(.+(?<=theaterCode=))|(.+(?<=theatercode=))/, "").substring(0,4);
85 + theaters_info_by_area.push(theater_info);
86 + }
87 + cgv_theaters.push(theaters_info_by_area);
88 + }
89 + driver_theaters.close();
90 + },
91 + async () => {
92 + const driver_movies = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();
93 + driver_movies.get(url_movies);
94 + //예매율 Top19까지의 영화의 정보를 가져옴.
95 +
96 + const rank = await driver_movies.wait(until.elementsLocated(By.css("strong.rank")));
97 + const title = await driver_movies.wait(until.elementsLocated(By.css("strong.title")));
98 + const score = await driver_movies.wait(until.elementsLocated(By.css("strong.percent")));
99 + const GoldenEgg = await driver_movies.wait(until.elementsLocated(By.css("span.percent")));
100 + const link = await driver_movies.wait(until.elementsLocated(By.css("a.link-reservation")));
101 +
102 + //영화 제목, 순위, 예매율, 영화 코드, 골든에그 지수를 가져와 CGVMovieInfo 객체 생성자에 파라미터로 넘겨주고, 인스턴스를 받아옴.
103 + for (let i = 0; i < rank.length; i++) {
104 + const newTitle = await title[i].getText();
105 + const newRank = await rank[i].getText();
106 + const newScore = await score[i].getText();
107 + const newCode = await link[i].getAttribute("href");
108 + const newMovie = new CGVMovieInfo(newTitle, parseInt(newRank.replace("No.", "")), newScore.replace("예매율", "").replace("%", ""), await GoldenEgg[i].getText(), newCode.replace(/[^0-9]/g, "").substring(0,8));
109 + cgv_movies.push(newMovie);
110 + }
111 + driver_movies.close();
112 + }
113 +])}
114 +
115 +app.get('/cgv_theaters', (req, res) => {
116 + res.send(cgv_theaters[0]);
117 +});
118 +
119 +/*
120 +app.post('/ticketing', async (req, res, next) => {
121 + //영화관 이름과 날짜를 가져옴.
122 + const theaterName = req.body.theaterName;
123 + const date = req.body.date;
124 + const LocateQuery = "?PLAY_YMD={}".replace("{}", date);
125 +
126 + //입력된 영화관에 맞는 지역 코드와 영화관 고유코드 찾기
127 + let regionCode = 0, theaterCode = "";
128 + for(let i = 0; i < 9; i++){
129 + for(const elem of cgv_theaters[i]){
130 + if(elem.theater_name == theaterName){
131 + regionCode = i;
132 + theaterCode = elem.theater_code;
133 + break;
134 + }
135 + }
136 + }
137 +
138 + //예매 가능한 영화 리스트를 얻기 위해 빠른 예매 사이트로 이동.
139 + const driver_ticketing = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options()).build();
140 + driver_ticketing.get(url_ticketing + LocateQuery);
141 + driver_ticketing.switchTo().frame("ticket_iframe"); //Frame 전환
142 + //setTimeout(() => {}, 1000);
143 +
144 + //지역 코드에 맞게 list element click
145 + const selected_areas_list = await driver_ticketing.wait(until.elementsLocated(By.css("#theater_area_list > ul > li > a > span.name")));
146 + await selected_areas_list[regionCode].click();
147 + //setTimeout(() => {}, 5000);
148 +
149 + //선택한 지역에 대응되는 영화관 정보 가져오기
150 + const selected_theaters_list = await driver_ticketing.wait(until.elementsLocated(By.css("#theater_area_list > ul > li.selected > div > ul > li")));
151 +
152 + //프로그램 내부에서 가지고 있는 영화관코드와 웹에서 받아온 영화관코드가 일치하는 경우, selected_theaters_list element 클릭
153 + for (const theater_element of selected_theaters_list){
154 + if(await theater_element.getAttribute("theater_cd") == theaterCode){
155 + await theater_element.click();
156 + //setTimeout(() => {}, 5000);
157 + break;
158 + }
159 + }
160 +
161 + //선택한 영화관에서, 선택한 일자에 상영하는 영화 목록 들고오기
162 + await driver_ticketing.sleep(1000);
163 + const selected_movies_list = await driver_ticketing.wait(until.elementsLocated(By.css("#movie_list > ul > li > a > span.text")));
164 + const codes_of_selected_movies = await driver_ticketing.wait(until.elementsLocated(By.css("#movie_list > ul > li")));
165 +
166 + //선택불가를 제외한 영화 제목 및 영화 코드 가져오기.
167 + for(let i = 0; i < selected_movies_list.length; i++){
168 + //setTimeout(() => {}, 1000);
169 + const movie_enabled = await codes_of_selected_movies[i].getAttribute("class");
170 + if(movie_enabled.endsWith("dimmed"))
171 + break;
172 + const accessible_movie = {
173 + "movie_title": await selected_movies_list[i].getText(),
174 + "movie_code" : await codes_of_selected_movies[i].getAttribute("movie_cd_group")
175 + }
176 + cgv_accessible_movies.push(accessible_movie);
177 + }
178 + driver_ticketing.close();
179 +
180 + res.send(cgv_accessible_movies);
181 +});
182 +*/
183 +
184 +exports.getMovieChart = async(rank) => {
185 + let movie_chart = [];
186 + for(const movie_info of cgv_movies){
187 + if(movie_info.getRank() > rank)
188 + break;
189 + const top19_movie = {
190 + "rank" : movie_info.getRank(),
191 + "title" : movie_info.getTitle(),
192 + "code" : movie_info.getMovieCode()
193 + };
194 + movie_chart.push(top19_movie);
195 + }
196 + return movie_chart;
197 +}
198 +
199 +exports.getTheaterCode = async(theaterName) => {
200 + let theaterCode = "";
201 + for(let i = 0; i < 9; i++){
202 + for(const elem of cgv_theaters[i]){
203 + if(elem.theater_name == theaterName){
204 + theaterCode = elem.theater_code;
205 + break;
206 + }
207 + }
208 + }
209 + return theaterCode;
210 +}
211 +
212 +exports.getAccessibleMovies = async(theaterName, date) => {
213 + //영화관 이름과 날짜를 가져옴.
214 +
215 + //입력된 영화관에 맞는 지역 코드와 영화관 고유코드 찾기
216 + let regionCode = 0, theaterCode = "";
217 + for(let i = 0; i < 9; i++){
218 + for(const elem of cgv_theaters[i]){
219 + if(elem.theater_name == theaterName){
220 + regionCode = i;
221 + theaterCode = elem.theater_code;
222 + break;
223 + }
224 + }
225 + }
226 +
227 + const baseMovieCode = cgv_movies[0].getMovieCode();
228 + const LocateQuery = "?MOVIE_CD={0}&MOVIE_CD_GROUP={1}&THEATER_CD={2}&PLAY_YMD={3}".replace("{0}", baseMovieCode).replace("{1}", baseMovieCode).replace("{2}", theaterCode).replace("{3}", date);
229 +
230 + //예매 가능한 영화 리스트를 얻기 위해 빠른 예매 사이트로 이동.
231 + const driver_ticketing = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().addArguments("--headless")).build();
232 + driver_ticketing.get(url_ticketing + LocateQuery);
233 + await driver_ticketing.switchTo().frame("ticket_iframe"); //Frame 전환
234 +
235 + /*
236 + //setTimeout(() => {}, 1000);
237 +
238 + //지역 코드에 맞게 list element click
239 + const selected_areas_list = await driver_ticketing.wait(until.elementsLocated(By.css("#theater_area_list > ul > li > a > span.name")));
240 + await selected_areas_list[regionCode].click();
241 + //setTimeout(() => {}, 5000);
242 +
243 + //선택한 지역에 대응되는 영화관 정보 가져오기
244 + const selected_theaters_list = await driver_ticketing.wait(until.elementsLocated(By.css("#theater_area_list > ul > li.selected > div > ul > li")));
245 +
246 + //프로그램 내부에서 가지고 있는 영화관코드와 웹에서 받아온 영화관코드가 일치하는 경우, selected_theaters_list element 클릭
247 + for (const theater_element of selected_theaters_list){
248 + if(await theater_element.getAttribute("theater_cd") == theaterCode){
249 + await theater_element.click();
250 + //setTimeout(() => {}, 5000);
251 + break;
252 + }
253 + }
254 +
255 + //선택한 영화관에서, 선택한 일자에 상영하는 영화 목록 들고오기
256 + await driver_ticketing.sleep(1000);
257 + const selected_movies_list = await driver_ticketing.wait(until.elementsLocated(By.css("#movie_list > ul > li > a > span.text")));
258 + const codes_of_selected_movies = await driver_ticketing.wait(until.elementsLocated(By.css("#movie_list > ul > li")));
259 + */
260 +
261 + //선택불가를 제외한 영화 제목 및 영화 코드 가져오기.
262 + //const selected_movies_list = await driver_ticketing.wait(until.elementsLocated(By.css("strong")));
263 +
264 + //await driver_ticketing.sleep(1000);
265 +
266 + //선택한 영화관에서, 선택한 일자에 상영하는 영화 목록 들고오기
267 + //await driver_ticketing.sleep(1000);
268 + const selected_movies_list = await driver_ticketing.wait(until.elementsLocated(By.css("#movie_list > ul > li > a > span.text")));
269 + const codes_of_selected_movies = await driver_ticketing.wait(until.elementsLocated(By.css("#movie_list > ul > li")));
270 +
271 + //선택불가를 제외한 영화 제목 및 영화 코드 가져오기.
272 + for(let i = 0; i < selected_movies_list.length; i++){
273 + //setTimeout(() => {}, 1000);
274 + const movie_enabled = await codes_of_selected_movies[i].getAttribute("class");
275 + if(movie_enabled.endsWith("dimmed"))
276 + break;
277 + const accessible_movie = {
278 + "movie_title": await selected_movies_list[i].getText(),
279 + "movie_code" : await codes_of_selected_movies[i].getAttribute("movie_cd_group")
280 + }
281 + cgv_accessible_movies.push(accessible_movie);
282 + }
283 + return cgv_accessible_movies;
284 +}
285 +
286 +app.listen(23017);
...\ No newline at end of file ...\ No newline at end of file
1 +const chatbot = require("./app.js");
2 +const request = require('request');
3 +const cheerio = require('cheerio');
4 +const puppeteer = require('puppeteer');
5 +require('chromedriver');
6 +const {Builder,until} = require('selenium-webdriver'); //모듈 불러오기
7 +var webdriver = require('selenium-webdriver');
8 +var By = webdriver.By;
9 +const chrome = require('selenium-webdriver/chrome');//크롬 사용시
10 +const async = require('async')
11 +let express = require('express');
12 +let app = express();
13 +let bodyParser = require('body-parser');
14 +const { timeout } = require('async');
15 +app.use(bodyParser.urlencoded({ extended: false }));
16 +app.use(bodyParser.json());
17 +const booking_url = "https://megabox.co.kr/booking?";
18 +exports.booking_url = booking_url;
19 +const rate_url = "https://www.megabox.co.kr/movie";
20 +let r =0;
21 +let movie_data = [];
22 +exports.movie_data = movie_data;
23 +let location_data = [];
24 +exports.location_data = location_data;
25 +let index = 0;
26 +exports.init = ()=>{async.waterfall([//for 동기적 처리
27 + async () => {
28 + const driver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();//
29 + driver.get(booking_url);
30 + driver.switchTo().frame(0)//frameBokdMBooking 프레임 가져옴
31 + let seoul = await driver.wait(until.elementsLocated(By.css('#mCSB_4_container>ul>li>#btn')));
32 + let Gyeonggi = await driver.wait(until.elementsLocated(By.css('#mCSB_5_container>ul>li>#btn')));
33 + const Incheon = await driver.wait(until.elementsLocated(By.css('#mCSB_6_container>ul>li>#btn')));
34 + const DCS = await driver.wait(until.elementsLocated(By.css('#mCSB_7_container>ul>li>#btn')));//Daejeon Chungcheong Sejong
35 + const BDG = await driver.wait(until.elementsLocated(By.css('#mCSB_8_container>ul>li>#btn')));//Busan Daegu Gyeongsang
36 + const GJ= await driver.wait(until.elementsLocated(By.css('#mCSB_9_container>ul>li>#btn')));//gwangju_jeonla
37 + const Gangwon = await driver.wait(until.elementsLocated(By.css('#mCSB_10_container>ul>li>#btn')));
38 + const location_list = [seoul, Gyeonggi, Incheon, DCS, BDG, GJ, Gangwon]//
39 + for(let i = 0; i < location_list.length; i++){
40 + for (item of location_list[i]) {
41 + location_data[index++] = {
42 + 'LocationName':await item.getAttribute("brch-nm"),
43 + 'LocationNum' : await item.getAttribute("brch-no")
44 + }
45 + // let location_name = await item.getAttribute("brch-nm");
46 + // let location_num = await item.getAttribute("brch-no");
47 + // let obj = {};
48 + // obj[location_name]= location_num
49 + // location_data[index++] = obj;
50 + }
51 + }
52 + let movie_list = await driver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn')));
53 + r = 0;
54 + for (item of movie_list) {
55 + //Using getAttribute to get the data
56 + movie_data[r++] = {
57 + 'rank' : r,
58 + 'title' : await item.getAttribute("movie-nm"),
59 + 'movie_num':await item.getAttribute("movie-no"),
60 + }
61 + }
62 +
63 + driver.close();
64 +
65 + },
66 + async () => {
67 + r = 0;
68 + const browser = await puppeteer.launch({
69 + headless: true
70 + });
71 + const page = await browser.newPage();
72 + await page.goto(rate_url);
73 + const content = await page.content();
74 +
75 + const $ = cheerio.load(content);
76 + const $rate_lists = $("ol.list>li");
77 + $rate_lists.each((index, list) => {
78 + const name = $(list).find('div.tit-area > p.tit').attr('title');
79 + const rate = $(list).find('div.rate-date > span.rate').text();
80 +
81 + if(movie_data[r].title === name){
82 + movie_data[r++]['rate'] = rate;
83 + }
84 + });
85 + for(i of movie_data){
86 + if(Object.keys(i).length==3){
87 + movie_data[r++]['rate'] = '예매율 0%';
88 + }
89 + }
90 +
91 + browser.close();
92 + console.log("Comepleted!");
93 + },
94 +
95 +])}
96 +
97 +let appdriver;
98 +exports.using_PlayingMovieURL = async(PlayingMovieURL) => {
99 + appdriver = new webdriver.Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();
100 + appdriver.get(PlayingMovieURL);
101 + //appdriver.switchTo().frame(0)
102 + //frameBokdMBooking 프레임 가져옴
103 +}
104 +exports.geting_PlayingMovie= async() => {
105 + let movie_list = await appdriver.wait(until.elementsLocated(By.css('#mCSB_1_container>ul>li>.btn')));
106 + let n = 0;
107 + console.log(movie_list);
108 + for (item of movie_list) {
109 + movie_data[n++]['running'] = await item.getAttribute('form-at');
110 + }
111 + console.log("Completed get Running");
112 +}
113 +
114 +app.listen(5000);
...\ No newline at end of file ...\ No newline at end of file
1 +const MEGABOX = require('./Megabox.js');
2 +const CGV = require('./CGVTicketing.js');
3 +//const SearchingTheaterAPI = require('./SearchingTheaterAPI');
4 +const async = require('async');
5 +MEGABOX.init(); //메가박스 코드 시작(영화관 리스트 가져오기)
6 +CGV.init(); //CGV 코드 시작
7 +const PUSH_TARGET_URL = 'https://api.line.me/v2/bot/message/push'
8 +const REPLY_TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
9 +const asyncHandler = require('express-async-handler')
10 +const bodyParser = require('body-parser');
11 +const request = require('request');
12 +const moment = require("moment");
13 +const HTTPS = require('https');
14 +const path = require('path');
15 +const fs = require('fs');
16 +const sslport = 23023;
17 +var express = require('express');
18 +var app = express();
19 +app.use(bodyParser.json());
20 +/////////////////////////////////////////////////
21 +// commit 할때 지워야 할것들
22 +const USER_ID = '';
23 +const TOKEN = '';
24 +const domain = '';
25 +const KAKAO_KEY = '';
26 +/////////////////////////////////////////////////
27 +let initFlag = false; //브랜드 선택 flag
28 +/////////////////////////////////////////////////
29 +// CGV 변수 초기화 부분
30 +let CGV_flag = -1; //진행 단계
31 +let CGV_date = ""; //날짜
32 +let CGV_RequestedLocation = ""; //사용자가 입력한 장소
33 +let CGV_RespondedTheaters = []; //API를 통해 받아온 영화관들 및 카카오맵 연결 링크
34 +let CGV_SelectedTheater = ""; //사용자가 설정한 영화관 이름
35 +let CGV_SelectedTheaterCode = ""; //영화관 고유코드
36 +let CGV_accessible_movies = []; //상영 날짜와 상영관에 따라 예매할 수 있는 영화 목록
37 +let CGV_movie_chart = [];
38 +let CGV_url_web = "https://www.cgv.co.kr/ticket/";
39 +let CGV_url_mobile = "https://m.cgv.co.kr/WebApp/Reservation/quickResult.aspx";
40 +/////////////////////////////////////////////////
41 +// LotteCinema 변수 초기화 부분
42 +let LOTTE_flag = -1;
43 +////////////////////////////////////////////////
44 +// Megabox 변수 초기화 부분
45 +let MEGA_date;
46 +let MEGA_TheaterLocation;
47 +let MEGA_TheaterLocationCode;
48 +let MEGA_PlayingMovieList = [];
49 +let MEGA_title;
50 +let MEGA_PlayingMovieURL;
51 +let MEGA_flag = -1; //메가박스 인지 확인하는 flag
52 +let MEGA_count; //메가박스에서 영화관 판단하는 count
53 +let MEGA_AbleLocationList = []; //메가박스에서 영화관 이름 매치하는 것 저장하는 list
54 +let MegaboxKakaoResultTheater = [];
55 +exports.MEGA_PlayingMovieURL = MEGA_PlayingMovieURL;
56 +////////////////////////////////////////////////
57 +//처음 영화관을 가져오는 것까지 대략 30초가 걸림 => 30초 기다리고 메세지 전송
58 +
59 +setTimeout(function () {
60 + PushSingleMessage("원하시는 브랜드의 번호를 입력해주세요.\n1: CGV\n2: LotteCinema\n3: Megabox\n언제든 브랜드를 바꾸고 싶으시다면 '브랜드'를 입력해주세요.");
61 +}, 30000);
62 +
63 +//app.post('/hook', function (req, res) {
64 +app.post('/hook', asyncHandler(async (req, res, next) => {
65 + var eventObj = req.body.events[0];
66 + var source = eventObj.source;
67 + var message = eventObj.message;
68 + // request log
69 + console.log('======================', new Date(), '======================');
70 + console.log('[request]', req.body);
71 + console.log('[request source] ', eventObj.source);
72 + console.log('[request message]', eventObj.message);
73 + //어느 순간에서든 "브랜드"를 입력해 원하는 브랜드 선택
74 + //initFlag : false ==> 브랜드 선택 전
75 + //initFlag : true ==> 브랜드 선택 됨
76 + if (eventObj.message.text == "브랜드") {
77 + initFlag = false;
78 + MEGA_flag = -1;
79 + PushSingleMessage("원하시는 브랜드의 번호를 입력해주세요.\n1: CGV\n2: LotteCinema\n3: Megabox\n언제든 브랜드를 바꾸고 싶으시다면 '브랜드'를 입력해주세요.");
80 + }
81 +
82 + if (initFlag == false && eventObj.message.text == "1") { //브랜드 선택- CGV 인 경우: CGV_flag를 0으로 두어 메가박스 임을 확인
83 + initFlag = true;
84 + CGV_flag = 0;
85 + } else if (initFlag == false && eventObj.message.text == "2") { //브랜드 선택- 롯데시네마 인 경우: LOTTE_flag를 0으로 두어 메가박스 임을 확인
86 + initFlag = true;
87 + LOTTE_flag = 0;
88 + } else if (initFlag == false && eventObj.message.text == "3") { //브랜드 선택- 메가박스 인 경우: MEGA_flag를 0으로 두어 메가박스 임을 확인
89 + initFlag = true;
90 + MEGA_flag = 0;
91 + }
92 +
93 + if (initFlag == true && CGV_flag != -1) { //씨지브이로 브랜드 선택된 경우
94 + if (CGV_flag === 0) {
95 + const text1 = "영화관 위치를 입력해주세요";
96 + const text2 = "ex) 강남"
97 + SendMessage(eventObj, text1, text2);
98 + CGV_flag++;
99 + }
100 + else if (CGV_flag === 1) {
101 + CGV_RespondedTheaters = [];
102 + CGV_RequestedLocation = message.text;
103 + GetCGVKakaoLocalAPI(CGV_RequestedLocation);
104 + setTimeout(function () {
105 + if (CGV_RespondedTheaters.length == 0)
106 + PushSingleMessage("검색 결과가 없습니다. 다시 입력해주세요.");
107 + else {
108 + if (CGV_RespondedTheaters.length == 1) {
109 + CGV_SelectedTheater = CGV_RespondedTheaters[0].theater_name;
110 + CGV_SelectedTheaterCode = CGV.getTheaterCode(CGV_SelectedTheater);
111 + setTimeout(function () {
112 + CGV_flag = 2;
113 + }, 2000);
114 + }
115 + else {
116 + let CGV_OutputString = "원하시는 상영관의 번호를 정확히 입력해주세요\n";
117 + for (let i = 0; i < CGV_RespondedTheaters.length; i++) {
118 + CGV_OutputString += String(i + 1) + ": " + CGV_RespondedTheaters[i].theater_name + "\n";
119 + }
120 + CGV_OutputString += String(CGV_RespondedTheaters.length + 1) + ": 다시 검색하기";
121 + PushSingleMessage(CGV_OutputString);
122 + CGV_flag = 101;
123 + }
124 + }
125 + }, 2000);
126 +
127 + }
128 + else if (CGV_flag == 101 && CGV_RespondedTheaters.length != 0) {
129 + let selection = parseInt(message.text);
130 + if (selection > 0 && selection < CGV_RespondedTheaters.length + 1) {
131 + CGV_SelectedTheater = CGV_RespondedTheaters[selection - 1].theater_name;
132 + CGV_SelectedTheaterCode = await CGV.getTheaterCode(CGV_SelectedTheater);
133 + CGV_flag = 2;
134 + }
135 + else {
136 + const text1 = "영화관 위치를 입력해주세요";
137 + const text2 = "ex) 강남"
138 + SendMessage(eventObj, text1, text2);
139 + CGV_flag = 1;
140 + }
141 +
142 + }
143 + ////날짜 입력 받기
144 + if (CGV_flag === 2) {
145 + const text1 = "선택한 영화관은 CGV" + CGV_SelectedTheater + "입니다.\n 영화를 관람할 날짜를 선택해 주세요.";
146 + const text2 = "ex)20020409, YYYYMMDD";
147 + SendMessage(eventObj, text1, text2);
148 + CGV_flag = 3;
149 + }
150 + //날짜 확인 및 날짜, 장소에 대해 상영중인 영화 리스트 가져오기
151 + if (moment(message.text, "YYYYMMDD", true).isValid() && CGV_flag == 3) {
152 + CGV_date = message.text;
153 + let today = GettingToday();//오늘 이후인지 확인하기 위해 날짜 가져옴
154 + //console.log(MEGA_date, MEGA_TheaterLocation);
155 + if (today <= CGV_date && CGV_date && CGV_SelectedTheater) {
156 + CGV_accessible_movies = await CGV.getMovieChart(5);
157 + const text1 = "현재상영작을 가져오는 중입니다.";
158 + const text2 = "잠시만 기다려주세요.";
159 + PushMessage(text1, text2);
160 + console.log(CGV_accessible_movies);
161 + CGV_flag++;
162 + } else {
163 + const text1 = "영화를 보실 날짜를 다시 입력해주세요.";
164 + const text2 = "ex)20020409";
165 + SendMessage(eventObj, text1, text2);
166 + }
167 + //원본 코드
168 + // MEGA_date = parseInt(eventObj.message.text);
169 + // if (MEGA_date && MEGA_TheaterLocationCode) {
170 + // MEGA_PlayingMovieURL = "https://megabox.co.kr/on/oh/ohb/SimpleBooking/simpleBookingPage.do" + '?brchNo1=' + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
171 + // console.log(MEGA_PlayingMovieURL)
172 + // async.waterfall[
173 + // megabox.using_PlayingMovieURL(MEGA_PlayingMovieURL),
174 + // megabox.geting_PlayingMovie()
175 + // ]
176 + // MEGA_flag++
177 + // console.log(MEGA_flag);
178 + // }
179 + }
180 + if (CGV_flag === 4) {
181 + let AccessibleMovieText = "-- 예매 가능한 상영작 --\n\n";
182 + if (CGV_accessible_movies.length == 0) {
183 + PushMessage("현재상영작이 없습니다.", "영화관 선택 단계로 이동합니다.");
184 + setTimeout(function () {
185 + PushMessage("영화관 위치를 입력해주세요", "ex1) 강남");
186 + }, 1000);
187 + CGV_flag = 1;
188 + }
189 + else if (CGV_accessible_movies.length == 1) {
190 + AccessibleMovieText += ("1. " + CGV_accessible_movies[0].title);
191 + const SelectedMovieCode = CGV_accessible_movies[0].code;
192 + PushMessage(AccessibleMovieText, "바로 링크가 전송됩니다.");
193 + setTimeout(function () {
194 + const finalURL_web = CGV_url_web + "?MOVIE_CD=" + SelectedMovieCode + "&MOVIE_CD_GROUP=" + SelectedMovieCode + "&THEATER_CD=" + CGV_SelectedTheaterCode + "&PLAY_YMD=" + CGV_date;
195 + const finalURL_mobile = CGV_url_mobile + "?mgc=" + SelectedMovieCode + "&tc=" + CGV_SelectedTheaterCode + "&ymd=" + CGV_date;
196 + //console.log(finalURL_web);
197 + //PushMessage(finalURL_web, "링크를 누르면 예매 창으로 바로 이동합니다.");
198 + PushURLMessage(finalURL_web, finalURL_mobile);
199 + }, 1000);
200 + }
201 + else {
202 + setTimeout(function () {
203 + let rank = 1;
204 + for (const elem of CGV_accessible_movies) {
205 + AccessibleMovieText += (rank.toString() + ". " + elem.title);
206 + AccessibleMovieText += "\n";
207 + rank++;
208 + }
209 + console.log(AccessibleMovieText);
210 + PushMessage(AccessibleMovieText, "예매할 영화 번호를 입력해주세요.\n ex)1 (영화 앞 숫자만 입력)");
211 + CGV_flag = 5;
212 + }, 1000);
213 + }
214 + }
215 + if (CGV_flag === 5) {
216 + const index = parseInt(message.text) - 1;
217 + if (index < 0 || index > 4) {
218 + PushSingleMessage("다시 입력해주세요!");
219 + } else {
220 + const SelectedMovieCode = CGV_accessible_movies[index].code;
221 + const finalURL_web = CGV_url_web + "?MOVIE_CD=" + SelectedMovieCode + "&MOVIE_CD_GROUP=" + SelectedMovieCode + "&THEATER_CD=" + CGV_SelectedTheaterCode + "&PLAY_YMD=" + CGV_date;
222 + const finalURL_mobile = CGV_url_mobile + "?mgc=" + SelectedMovieCode + "&tc=" + CGV_SelectedTheaterCode + "&ymd=" + CGV_date;
223 + //console.log(finalURL_web);
224 + //PushMessage(finalURL_web, "링크를 누르면 예매 창으로 바로 이동합니다.");
225 + PushURLMessage(finalURL_web, finalURL_mobile);
226 + setTimeout(function () {
227 + initFlag = false;
228 + CGV_flag = -1;
229 + PushSingleMessage("원하시는 브랜드의 번호를 입력해주세요.\n1: CGV\n2: LotteCinema\n3: Megabox\n언제든 브랜드를 바꾸고 싶으시다면 '브랜드'를 입력해주세요.");
230 + }, 1000);
231 + }
232 + }
233 + } else if (initFlag == true && LOTTE_flag != -1) { //롯데시네마로 브랜드 선택된 경우
234 + PushMessage("현재 롯데시네마는 AWS 서버 문제로 지원되지 않습니다!\n다른 브랜드를 선택해주세요.\n롯데시네마의 예매 링크 사이트는 https://www.lottecinema.co.kr/NLCHS/Ticketing 입니다.", "원하시는 브랜드의 번호를 입력해주세요.\n1: CGV\n2: LotteCinema\n3: Megabox\n언제든 브랜드를 바꾸고 싶으시다면 '브랜드'를 입력해주세요.");
235 + initFlag = false;
236 + LOTTE_flag = -1;
237 + }
238 + else if (initFlag == true && MEGA_flag != -1) { //메가박스로 브랜드 선택된 경우
239 + if (MEGA_flag == 0) {
240 + const text1 = "영화관 위치를 입력해주세요";
241 + const text2 = "ex1)강남";
242 + SendMessage(eventObj, text1, text2);
243 + MEGA_flag++;
244 + //PusbuttonhMessage("https://developers.line.biz/en/reference/messaging-api/#message-common-properties");
245 + //console.log(MEGA_flag)
246 + } else if (MEGA_flag === 1) {
247 + MEGA_count = 0; //MEGA_count 초기화
248 + MEGA_AbleLocationList.length = 0; //MEGA_AbleLocationList 초기화
249 + for (i of MEGABOX.location_data) {
250 + if (i['LocationName'].includes(message.text)) {
251 + MEGA_AbleLocationList[MEGA_count++] = i;
252 + }
253 + }
254 +
255 + if (MEGA_count == 1) { //결과 1개 => 바로 다음 단계 넘어가기
256 + MEGA_TheaterLocation = MEGA_AbleLocationList[0].LocationName;
257 + MEGA_TheaterLocationCode = MEGA_AbleLocationList[0].LocationNum;
258 + console.log(MEGA_TheaterLocation, MEGA_TheaterLocationCode);
259 + MEGA_flag++;
260 + } else if (MEGA_count > 1) { //결과 2개 이상 => 리스트 출력해주고 번호로 입력받아 넘어가기
261 + console.log(MEGA_AbleLocationList[0], MEGA_AbleLocationList[1]);
262 + let MEGA_OutputString = "원하시는 상영관의 번호를 정확히 입력해주세요\n"; //메가박스 영화관 가능 정보 string
263 + //PushSingleMessage("원하시는 상영관의 번호를 정확히 입력해주세요");
264 + for (let x = 0; x < MEGA_count; x++) {
265 + //PushSingleMessage(String(x + 1) + ": " + MEGA_AbleLocationList[x].LocationName);
266 + MEGA_OutputString += String(x + 1) + ": " + MEGA_AbleLocationList[x].LocationName + "\n";
267 + console.log(String(x + 1), MEGA_AbleLocationList[x].LocationName);
268 + }
269 + MEGA_OutputString += String(MEGA_count + 1) + ": 다시 검색하기";
270 + PushSingleMessage(MEGA_OutputString);
271 + MEGA_flag = 101;
272 + } else {
273 + PushSingleMessage("다시 입력해주세요.");
274 + }
275 + //원본 코드
276 + //console.log(MEGA_flag);
277 + // for (i of MEGABOX.location_data) {
278 + // if (i['LocationName'] === message.text) {
279 + // MEGA_TheaterLocationCode = i['LocationNUm'];
280 + // console.log(MEGA_TheaterLocationCode);
281 + // MEGA_flag++;
282 + // console.log(MEGA_flag)
283 + // break;
284 + // }
285 + // }
286 + } else if (MEGA_flag == 101) {
287 + // 0< input || input > MEGA_count+1 : 다시 검색
288 + let tempNum = parseInt(message.text);
289 + if (tempNum > 0 && tempNum < MEGA_count + 1) {
290 + //번호에 맞는 LocationCode 전달
291 + MEGA_TheaterLocation = MEGA_AbleLocationList[tempNum - 1].LocationName;
292 + MEGA_TheaterLocationCode = MEGA_AbleLocationList[tempNum - 1].LocationNum;
293 + console.log(MEGA_TheaterLocation, MEGA_TheaterLocationCode);
294 + MEGA_flag = 2;
295 + } else {
296 + //다시 장소 입력받기
297 + const text1 = "영화관 위치를 입력해주세요";
298 + const text2 = "ex1)강남";
299 + SendMessage(eventObj, text1, text2);
300 + MEGA_flag = 1;
301 + }
302 + }
303 + //날짜 입력 받기
304 + if (MEGA_flag == 2) {
305 + const text1 = "현재 영화관은 " + MEGA_TheaterLocation + " 입니다.\n영화를 보실 날짜를 입력해주세요.";
306 + const text2 = "ex)20020409";
307 + SendMessage(eventObj, text1, text2);
308 + MEGA_flag = 3;
309 + }
310 + //날짜 확인 및 날짜, 장소에 대해 상영중인 영화 리스트 가져오기
311 + if (moment(message.text, "YYYYMMDD", true).isValid() && MEGA_flag == 3) {
312 + MEGA_date = parseInt(message.text);
313 + let today = GettingToday();//오늘 이후인지 확인하기 위해 날짜 가져옴
314 + //console.log(MEGA_date, MEGA_TheaterLocation);
315 + if (today <= MEGA_date && MEGA_date && MEGA_TheaterLocationCode) {
316 + const text1 = "현재상영작을 가져오는 중입니다.";
317 + const text2 = "잠시만 기다려주세요.";
318 + PushMessage(text1, text2);
319 + MEGA_PlayingMovieURL = "https://megabox.co.kr/on/oh/ohb/SimpleBooking/simpleBookingPage.do" + '?brchNo1=' + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
320 + MEGABOX.using_PlayingMovieURL(MEGA_PlayingMovieURL);
321 + await MEGABOX.geting_PlayingMovie();
322 + console.log(MEGA_PlayingMovieURL, MEGABOX.movie_data);
323 + MEGA_flag = 4;
324 + }
325 + else {
326 + const text1 = "영화를 보실 날짜를 다시 입력해주세요.";
327 + const text2 = "ex)20020409";
328 + SendMessage(eventObj, text1, text2);
329 + }
330 + //원본 코드
331 + // MEGA_date = parseInt(eventObj.message.text);
332 + // if (MEGA_date && MEGA_TheaterLocationCode) {
333 + // MEGA_PlayingMovieURL = "https://megabox.co.kr/on/oh/ohb/SimpleBooking/simpleBookingPage.do" + '?brchNo1=' + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
334 + // console.log(MEGA_PlayingMovieURL)
335 + // async.waterfall[
336 + // MEGABOX.using_PlayingMovieURL(MEGA_PlayingMovieURL),
337 + // MEGABOX.geting_PlayingMovie()
338 + // ]
339 + // MEGA_flag++
340 + // console.log(MEGA_flag);
341 + // }
342 + }
343 + if (MEGA_flag == 4) {
344 + let obj = {};
345 + let n;
346 + let PlayingMovie = "-현재 상영작-\n\n";
347 + let movietitle;
348 + console.log(MEGABOX.movie_data);
349 + for (n = 0; n < Object.keys(MEGABOX.movie_data).length; n++) {
350 + if (MEGABOX.movie_data[n].running == 'Y') {
351 + console.log(MEGABOX.movie_data[n]);
352 + movietitle = MEGABOX.movie_data[n].title;
353 + MEGA_PlayingMovieList[movietitle] = MEGABOX.movie_data[n].movie_num;
354 + }
355 + }
356 + console.log(Object.keys(MEGA_PlayingMovieList).length);
357 + if (Object.keys(MEGA_PlayingMovieList).length == 0) {
358 + PushSingleMessage("현재상영작이 없습니다.\n영화관 선택 단계로 이동합니다.");
359 + setTimeout(function () {
360 + PushMessage("영화관 위치를 입력해주세요", "ex1)강남");
361 + }, 1000);
362 + MEGA_flag = 1;
363 + } else if (Object.keys(MEGA_PlayingMovieList).length == 1) {
364 + PlayingMovie += '1: ' + Object.keys(MEGA_PlayingMovieList)[0];
365 + PushMessage(PlayingMovie, "바로 링크가 보내집니다.");
366 + MEGA_title = MEGA_PlayingMovieList[Object.keys(MEGA_PlayingMovieList)[0]];
367 + setTimeout(function () {
368 + const PC_final_URL = "https://www.megabox.co.kr/booking?rpstMovieNo=" + MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
369 + const Smartphone_final_URL = "https://m.megabox.co.kr/booking/movie?movieNo=" + MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
370 + PushURLMessage(PC_final_URL, Smartphone_final_URL);
371 + setTimeout(function () {
372 + initFlag = false;
373 + MEGA_flag = -1;
374 + MEGA_PlayingMovieList = [];
375 + PushSingleMessage("원하시는 브랜드의 번호를 입력해주세요.\n1: CGV\n2: LotteCinema\n3: Megabox\n언제든 브랜드를 바꾸고 싶으시다면 '브랜드'를 입력해주세요.");
376 + }, 1000);
377 + }, 1000);
378 + } else {
379 + let index = 0;
380 + for (let playingmovie = 0; playingmovie < Object.keys(MEGA_PlayingMovieList).length; playingmovie++) {
381 + PlayingMovie += (playingmovie + 1).toString() + '. ' + Object.keys(MEGA_PlayingMovieList)[index++];
382 + PlayingMovie += "\n";
383 + }
384 + console.log(PlayingMovie);
385 + await PushMessage(PlayingMovie, "예매할 영화 번호를 입력해주세요.\n ex)1 (영화 앞 숫자만 입력)");
386 + MEGA_flag = 5;
387 + }
388 + } else if (MEGA_flag == 5) {
389 + const index = parseInt(message.text) - 1;
390 + console.log(Object.keys(MEGA_PlayingMovieList).length);
391 + if (index < 0 || index > Object.keys(MEGA_PlayingMovieList).length - 1) {
392 + PushSingleMessage("다시 입력해주세요!");
393 + } else {
394 + MEGA_title = MEGA_PlayingMovieList[Object.keys(MEGA_PlayingMovieList)[index]];
395 + const PC_final_URL = "https://www.megabox.co.kr/booking?rpstMovieNo=" + MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
396 + const Smartphone_final_URL = "https://m.megabox.co.kr/booking/movie?movieNo=" + MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
397 + console.log(PC_final_URL, Smartphone_final_URL);
398 + PushURLMessage(PC_final_URL, Smartphone_final_URL);
399 + MEGA_PlayingMovieList = []; //영화 리스트 초기화
400 + MegaboxKakaoResultTheater = [];
401 + GetMegaboxKakaoMapURL(MEGA_TheaterLocation);
402 + setTimeout(function () {
403 + console.log(MegaboxKakaoResultTheater[0]);
404 + let MegaboxKakaoResultTheaterNAME = MegaboxKakaoResultTheater[0]['theater_name'];
405 + let MegaboxKakaoResultTheaterURL = MegaboxKakaoResultTheater[0]['theater_url'];
406 + console.log(MegaboxKakaoResultTheaterNAME, MegaboxKakaoResultTheaterURL);
407 + PushMessage(MegaboxKakaoResultTheaterURL, "카카오맵으로 검색한 " + MegaboxKakaoResultTheaterNAME + "의 위치입니다.");
408 + setTimeout(function () {
409 + //EGA_PlayingMovieList = [];
410 + initFlag = false;
411 + MEGA_flag = -1;
412 + PushSingleMessage("원하시는 브랜드의 번호를 입력해주세요.\n1: CGV\n2: LotteCinema\n3: Megabox\n언제든 브랜드를 바꾸고 싶으시다면 '브랜드'를 입력해주세요.");
413 + }, 1000);
414 + }, 2000);
415 + }
416 + }
417 + }
418 + res.sendStatus(200);
419 +}))
420 +//});
421 +try {
422 + const option = {
423 + ca: fs.readFileSync('/etc/letsencrypt/live/' + domain + '/fullchain.pem'),
424 + key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain + '/privkey.pem'), 'utf8').toString(),
425 + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain + '/cert.pem'), 'utf8').toString(),
426 + };
427 + HTTPS.createServer(option, app).listen(sslport, () => {
428 + console.log(`[HTTPS] Server is started on port ${sslport}`);
429 + });
430 +} catch (error) {
431 + console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
432 + console.log(error);
433 +}
434 +//오늘 날짜 구하기
435 +function GettingToday() {
436 + var today = new Date();
437 + var year = today.getFullYear();
438 + var month = ('0' + (today.getMonth() + 1)).slice(-2);
439 + var day = ('0' + today.getDate()).slice(-2);
440 + var dateString = year + month + day;
441 + var dateInt = parseInt(dateString);
442 + console.log(dateInt);
443 + return dateInt;
444 +}
445 +
446 +//24시간마다 데이터 초기화
447 +var dayInMilliseconds = 1000 * 60 * 60 * 24;
448 +setInterval(function () { MEGABOX.init(); console.log("success") }, dayInMilliseconds);
449 +
450 +//CGV - Kakao API로 영화관 위치 찾기
451 +function GetCGVKakaoLocalAPI(location) {
452 + let kakaoOptions = {
453 + url: "https://dapi.kakao.com/v2/local/search/keyword",
454 + method: "GET",
455 + headers: {
456 + 'Authorization': `KakaoAK ${KAKAO_KEY}`
457 + },
458 + qs: {
459 + 'query': `CGV ${location}`,
460 + //'category_group_code' : 'CT1',
461 + 'size': 5
462 + },
463 + encoding: 'UTF-8'
464 + };
465 + request(kakaoOptions, function (err, res, body) {
466 + info_list = JSON.parse(body).documents;
467 + if (!err && res.statusCode == 200) {
468 + info_list.forEach(info => {
469 + if (info.category_name.endsWith("CGV")) {
470 + const theater_info = {
471 + "theater_name": info.place_name.replace("CGV ", ""),
472 + "theater_url": info.place_url
473 + };
474 + CGV_RespondedTheaters.push(theater_info);
475 + console.log(theater_info);
476 + }
477 + });
478 + }
479 + });
480 +
481 +}
482 +
483 +//Megabox - Kakao API로 영화관 위치 찾기
484 +GetMegaboxKakaoMapURL = async (LOCATE) => {
485 + let KAKAOOPTION = {
486 + url: "https://dapi.kakao.com/v2/local/search/keyword",
487 + method: "GET",
488 + headers: {
489 + 'Authorization': `KakaoAK ${KAKAO_KEY}` // commit 할때 지워야 할것
490 + },
491 + qs: {
492 + 'query': '메가박스 ' + LOCATE, // 메가박스 영화관이름
493 + //'category_group_code' : 'CT1',
494 + 'size': 5
495 + },
496 + encoding: 'UTF-8'
497 + };
498 + let selectable_theaters = [];
499 + request(KAKAOOPTION, function (err, res, body) {
500 + info_list = JSON.parse(body).documents;
501 +
502 + if (!err && res.statusCode == 200) {
503 + info_list.forEach(info => {
504 + //console.log(info.category_name);
505 + if (info.category_name.endsWith("메가박스")) {
506 + const theater_info = {
507 + "theater_name": info.place_name,
508 + "theater_url": info.place_url
509 + };
510 + //console.log(theater_info);
511 + //return theater_info;
512 + selectable_theaters.push(theater_info);
513 + }
514 + });
515 + }
516 + console.log(selectable_theaters);
517 + MegaboxKakaoResultTheater = selectable_theaters;
518 + return;
519 + });
520 +
521 +}
522 +
523 +//메세지 전송하는 function 모음
524 +function SendMessage(eventObj, text1, text2 = "") { //reply message
525 + request.post(
526 + {
527 + url: REPLY_TARGET_URL,
528 + headers: {
529 + 'Authorization': `Bearer ${TOKEN}`
530 + },
531 + json: {
532 + "replyToken": eventObj.replyToken,
533 + "messages": [
534 + {
535 + "type": "text",
536 + "text": text1
537 + },
538 + {
539 + "type": "text",
540 + "text": text2
541 + }
542 + ]
543 + }
544 + }, (error, response, body) => {
545 + console.log(body);
546 + });
547 +}
548 +function PushMessage(text1, text2 = "") { //push two message
549 + request.post(
550 + {
551 + url: PUSH_TARGET_URL,
552 + headers: {
553 + 'Authorization': `Bearer ${TOKEN}`
554 + },
555 + json: {
556 + "to": `${USER_ID}`,
557 + "messages": [
558 + {
559 + "type": "text",
560 + "text": text1
561 + },
562 + {
563 + "type": "text",
564 + "text": text2
565 + }
566 + ]
567 + }
568 + }, (error, response, body) => {
569 + console.log(body)
570 + });
571 +}
572 +function PushSingleMessage(text1) {//push single message
573 + request.post(
574 + {
575 + url: PUSH_TARGET_URL,
576 + headers: {
577 + 'Authorization': `Bearer ${TOKEN}`
578 + },
579 + json: {
580 + "to": `${USER_ID}`,
581 + "messages": [
582 + {
583 + "type": "text",
584 + "text": text1
585 + }
586 + ]
587 + }
588 + }, (error, response, body) => {
589 + console.log(body)
590 + });
591 +}
592 +function PushURLMessage(pcurl, smartphoneurl) {//push single message
593 + request.post(
594 + {
595 + url: PUSH_TARGET_URL,
596 + headers: {
597 + 'Authorization': `Bearer ${TOKEN}`
598 + },
599 + json: {
600 + "to": `${USER_ID}`,
601 + "messages": [
602 + {
603 + "type": "text",
604 + "text": "pc버전 url입니다\n\n" + pcurl
605 + },
606 + {
607 + "type": "text",
608 + "text": "mobile버전 url입니다\n\n" + smartphoneurl
609 + }
610 + ]
611 + }
612 + }, (error, response, body) => {
613 + console.log(body)
614 + });
615 +}
1 +{
2 + "name": "chatbotdemo",
3 + "version": "1.0.0",
4 + "description": "",
5 + "main": "app.js",
6 + "scripts": {
7 + "test": "echo \"Error: no test specified\" && exit 1"
8 + },
9 + "keywords": [],
10 + "author": "",
11 + "license": "ISC",
12 + "dependencies": {
13 + "async": "^3.2.3",
14 + "body-parser": "^1.20.0",
15 + "cheerio": "^1.0.0-rc.11",
16 + "chromedriver": "^101.0.0",
17 + "express": "^4.18.1",
18 + "express-async-handler": "^1.2.0",
19 + "moment": "^2.29.3",
20 + "puppeteer": "^14.1.1",
21 + "request": "^2.88.2",
22 + "selenium-webdriver": "^4.1.2"
23 + }
24 +}