ShinSeungMin

Add Chatbot Demo!

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 +const USER_ID = 'Uc2471a2b23fdd1ba92cfaefc5109ae66';
27 +const TOKEN = 'dnQaNDicvCKG/BJdsuI0/48ep9UTKuHFjW3L4+uCketz+HhXJI4RhfBMFwuKljG4pKyVahGIxhU0mby+wUvmOlgqHwCs5Hs8wM+ztYvcxo5PDOldHjikU4spRsgLy35Hok2QdqbARcZuupInqeWt3AdB04t89/1O/w1cDnyilFU=';
28 +const domain = '2021105612.osschatbot2022.ml';
29 +const KAKAO_KEY = 'e5051f82023ae6c9893a9755339971ac';
30 +/////////////////////////////////////////////////
31 +let initFlag = false; //브랜드 선택 flag
32 +/////////////////////////////////////////////////
33 +// CGV 변수 초기화 부분
34 +let CGV_flag = -1; //진행 단계
35 +let CGV_date = ""; //날짜
36 +let CGV_RequestedLocation = ""; //사용자가 입력한 장소
37 +let CGV_RespondedTheaters = []; //API를 통해 받아온 영화관들 및 카카오맵 연결 링크
38 +let CGV_SelectedTheater = ""; //사용자가 설정한 영화관 이름
39 +let CGV_SelectedTheaterCode = ""; //영화관 고유코드
40 +let CGV_accessible_movies = []; //상영 날짜와 상영관에 따라 예매할 수 있는 영화 목록
41 +let CGV_movie_chart = [];
42 +let CGV_url_web = "https://www.cgv.co.kr/ticket/";
43 +let CGV_url_mobile = "https://m.cgv.co.kr/WebApp/Reservation/quickResult.aspx";
44 +/////////////////////////////////////////////////
45 +// LotteCinema 변수 초기화 부분
46 +let LOTTE_flag = -1;
47 +////////////////////////////////////////////////
48 +// Megabox 변수 초기화 부분
49 +let MEGA_date;
50 +let MEGA_TheaterLocation;
51 +let MEGA_TheaterLocationCode;
52 +let MEGA_PlayingMovieList = [];
53 +let MEGA_title;
54 +let MEGA_PlayingMovieURL;
55 +let MEGA_flag = -1; //메가박스 인지 확인하는 flag
56 +let MEGA_count; //메가박스에서 영화관 판단하는 count
57 +let MEGA_AbleLocationList = []; //메가박스에서 영화관 이름 매치하는 것 저장하는 list
58 +let MegaboxKakaoResultTheater = [];
59 +exports.MEGA_PlayingMovieURL = MEGA_PlayingMovieURL;
60 +////////////////////////////////////////////////
61 +//처음 영화관을 가져오는 것까지 대략 30초가 걸림 => 30초 기다리고 메세지 전송
62 +
63 +setTimeout(function () {
64 + PushSingleMessage("원하시는 브랜드의 번호를 입력해주세요.\n1: CGV\n2: LotteCinema\n3: Megabox\n언제든 브랜드를 바꾸고 싶으시다면 '브랜드'를 입력해주세요.");
65 +}, 30000);
66 +
67 +//app.post('/hook', function (req, res) {
68 +app.post('/hook', asyncHandler(async (req, res, next) => {
69 + var eventObj = req.body.events[0];
70 + var source = eventObj.source;
71 + var message = eventObj.message;
72 + // request log
73 + console.log('======================', new Date(), '======================');
74 + console.log('[request]', req.body);
75 + console.log('[request source] ', eventObj.source);
76 + console.log('[request message]', eventObj.message);
77 + //어느 순간에서든 "브랜드"를 입력해 원하는 브랜드 선택
78 + //initFlag : false ==> 브랜드 선택 전
79 + //initFlag : true ==> 브랜드 선택 됨
80 + if (eventObj.message.text == "브랜드") {
81 + initFlag = false;
82 + MEGA_flag = -1;
83 + PushSingleMessage("원하시는 브랜드의 번호를 입력해주세요.\n1: CGV\n2: LotteCinema\n3: Megabox\n언제든 브랜드를 바꾸고 싶으시다면 '브랜드'를 입력해주세요.");
84 + }
85 +
86 + if (initFlag == false && eventObj.message.text == "1") { //브랜드 선택- CGV 인 경우: CGV_flag를 0으로 두어 메가박스 임을 확인
87 + initFlag = true;
88 + CGV_flag = 0;
89 + } else if (initFlag == false && eventObj.message.text == "2") { //브랜드 선택- 롯데시네마 인 경우: LOTTE_flag를 0으로 두어 메가박스 임을 확인
90 + initFlag = true;
91 + LOTTE_flag = 0;
92 + } else if (initFlag == false && eventObj.message.text == "3") { //브랜드 선택- 메가박스 인 경우: MEGA_flag를 0으로 두어 메가박스 임을 확인
93 + initFlag = true;
94 + MEGA_flag = 0;
95 + }
96 +
97 + if (initFlag == true && CGV_flag != -1) { //씨지브이로 브랜드 선택된 경우
98 + if (CGV_flag === 0) {
99 + const text1 = "영화관 위치를 입력해주세요";
100 + const text2 = "ex) 강남"
101 + SendMessage(eventObj, text1, text2);
102 + CGV_flag++;
103 + }
104 + else if (CGV_flag === 1) {
105 + CGV_RespondedTheaters = [];
106 + CGV_RequestedLocation = message.text;
107 + GetCGVKakaoLocalAPI(CGV_RequestedLocation);
108 + setTimeout(function () {
109 + if (CGV_RespondedTheaters.length == 0)
110 + PushSingleMessage("검색 결과가 없습니다. 다시 입력해주세요.");
111 + else {
112 + if (CGV_RespondedTheaters.length == 1) {
113 + CGV_SelectedTheater = CGV_RespondedTheaters[0].theater_name;
114 + CGV_SelectedTheaterCode = CGV.getTheaterCode(CGV_SelectedTheater);
115 + setTimeout(function () {
116 + CGV_flag = 2;
117 + }, 2000);
118 + }
119 + else {
120 + let CGV_OutputString = "원하시는 상영관의 번호를 정확히 입력해주세요\n";
121 + for (let i = 0; i < CGV_RespondedTheaters.length; i++) {
122 + CGV_OutputString += String(i + 1) + ": " + CGV_RespondedTheaters[i].theater_name + "\n";
123 + }
124 + CGV_OutputString += String(CGV_RespondedTheaters.length + 1) + ": 다시 검색하기";
125 + PushSingleMessage(CGV_OutputString);
126 + CGV_flag = 101;
127 + }
128 + }
129 + }, 2000);
130 +
131 + }
132 + else if (CGV_flag == 101 && CGV_RespondedTheaters.length != 0) {
133 + let selection = parseInt(message.text);
134 + if (selection > 0 && selection < CGV_RespondedTheaters.length + 1) {
135 + CGV_SelectedTheater = CGV_RespondedTheaters[selection - 1].theater_name;
136 + CGV_SelectedTheaterCode = await CGV.getTheaterCode(CGV_SelectedTheater);
137 + CGV_flag = 2;
138 + }
139 + else {
140 + const text1 = "영화관 위치를 입력해주세요";
141 + const text2 = "ex) 강남"
142 + SendMessage(eventObj, text1, text2);
143 + CGV_flag = 1;
144 + }
145 +
146 + }
147 + ////날짜 입력 받기
148 + if (CGV_flag === 2) {
149 + const text1 = "선택한 영화관은 CGV" + CGV_SelectedTheater + "입니다.\n 영화를 관람할 날짜를 선택해 주세요.";
150 + const text2 = "ex)20020409, YYYYMMDD";
151 + SendMessage(eventObj, text1, text2);
152 + CGV_flag = 3;
153 + }
154 + //날짜 확인 및 날짜, 장소에 대해 상영중인 영화 리스트 가져오기
155 + if (moment(message.text, "YYYYMMDD", true).isValid() && CGV_flag == 3) {
156 + CGV_date = message.text;
157 + //console.log(MEGA_date, MEGA_TheaterLocation);
158 + if (CGV_date && CGV_SelectedTheater) {
159 + CGV_accessible_movies = await CGV.getMovieChart(5);
160 + const text1 = "현재상영작을 가져오는 중입니다.";
161 + const text2 = "잠시만 기다려주세요.";
162 + PushMessage(text1, text2);
163 + console.log(CGV_accessible_movies);
164 + CGV_flag++;
165 + }
166 + //원본 코드
167 + // MEGA_date = parseInt(eventObj.message.text);
168 + // if (MEGA_date && MEGA_TheaterLocationCode) {
169 + // MEGA_PlayingMovieURL = "https://megabox.co.kr/on/oh/ohb/SimpleBooking/simpleBookingPage.do" + '?brchNo1=' + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
170 + // console.log(MEGA_PlayingMovieURL)
171 + // async.waterfall[
172 + // megabox.using_PlayingMovieURL(MEGA_PlayingMovieURL),
173 + // megabox.geting_PlayingMovie()
174 + // ]
175 + // MEGA_flag++
176 + // console.log(MEGA_flag);
177 + // }
178 + }
179 + if (CGV_flag === 4) {
180 + let AccessibleMovieText = "-- 예매 가능한 상영작 --\n\n";
181 + if (CGV_accessible_movies.length == 0) {
182 + PushMessage("현재상영작이 없습니다.", "영화관 선택 단계로 이동합니다.");
183 + setTimeout(function () {
184 + PushMessage("영화관 위치를 입력해주세요", "ex1) 강남");
185 + }, 1000);
186 + CGV_flag = 1;
187 + }
188 + else if (CGV_accessible_movies.length == 1) {
189 + AccessibleMovieText += ("1. " + CGV_accessible_movies[0].title);
190 + const SelectedMovieCode = CGV_accessible_movies[0].code;
191 + PushMessage(AccessibleMovieText, "바로 링크가 전송됩니다.");
192 + setTimeout(function () {
193 + const finalURL_web = CGV_url_web + "?MOVIE_CD=" + SelectedMovieCode + "&MOVIE_CD_GROUP=" + SelectedMovieCode + "&THEATER_CD=" + CGV_SelectedTheaterCode + "&PLAY_YMD=" + CGV_date;
194 + const finalURL_mobile = CGV_url_mobile + "?mgc=" + SelectedMovieCode + "&tc=" + CGV_SelectedTheaterCode + "&ymd=" + CGV_date;
195 + //console.log(finalURL_web);
196 + //PushMessage(finalURL_web, "링크를 누르면 예매 창으로 바로 이동합니다.");
197 + PushURLMessage(finalURL_web, finalURL_mobile);
198 + }, 1000);
199 + }
200 + else {
201 + setTimeout(function () {
202 + let rank = 1;
203 + for (const elem of CGV_accessible_movies) {
204 + AccessibleMovieText += (rank.toString() + ". " + elem.title);
205 + AccessibleMovieText += "\n";
206 + rank++;
207 + }
208 + console.log(AccessibleMovieText);
209 + PushMessage(AccessibleMovieText, "예매할 영화 번호를 입력해주세요.\n ex)1 (영화 앞 숫자만 입력)");
210 + CGV_flag = 5;
211 + }, 1000);
212 + }
213 + }
214 + if (CGV_flag === 5) {
215 + const index = parseInt(message.text) - 1;
216 + if (index < 0 || index > 4) {
217 + PushSingleMessage("다시 입력해주세요!");
218 + } else {
219 + const SelectedMovieCode = CGV_accessible_movies[index].code;
220 + const finalURL_web = CGV_url_web + "?MOVIE_CD=" + SelectedMovieCode + "&MOVIE_CD_GROUP=" + SelectedMovieCode + "&THEATER_CD=" + CGV_SelectedTheaterCode + "&PLAY_YMD=" + CGV_date;
221 + const finalURL_mobile = CGV_url_mobile + "?mgc=" + SelectedMovieCode + "&tc=" + CGV_SelectedTheaterCode + "&ymd=" + CGV_date;
222 + //console.log(finalURL_web);
223 + //PushMessage(finalURL_web, "링크를 누르면 예매 창으로 바로 이동합니다.");
224 + PushURLMessage(finalURL_web, finalURL_mobile);
225 + setTimeout(function () {
226 + initFlag = false;
227 + CGV_flag = -1;
228 + PushSingleMessage("원하시는 브랜드의 번호를 입력해주세요.\n1: CGV\n2: LotteCinema\n3: Megabox\n언제든 브랜드를 바꾸고 싶으시다면 '브랜드'를 입력해주세요.");
229 + }, 1000);
230 + }
231 + }
232 + } else if (initFlag == true && LOTTE_flag != -1) { //롯데시네마로 브랜드 선택된 경우
233 + PushMessage("현재 롯데시네마는 AWS 서버 문제로 지원되지 않습니다!\n다른 브랜드를 선택해주세요.\n롯데시네마의 예매 링크 사이트는 https://www.lottecinema.co.kr/NLCHS/Ticketing 입니다.", "원하시는 브랜드의 번호를 입력해주세요.\n1: CGV\n2: LotteCinema\n3: Megabox\n언제든 브랜드를 바꾸고 싶으시다면 '브랜드'를 입력해주세요.");
234 + initFlag = false;
235 + LOTTE_flag = -1;
236 + }
237 + else if (initFlag == true && MEGA_flag != -1) { //메가박스로 브랜드 선택된 경우
238 + if (MEGA_flag == 0) {
239 + const text1 = "영화관 위치를 입력해주세요";
240 + const text2 = "ex1)강남";
241 + SendMessage(eventObj, text1, text2);
242 + MEGA_flag++;
243 + //PusbuttonhMessage("https://developers.line.biz/en/reference/messaging-api/#message-common-properties");
244 + //console.log(MEGA_flag)
245 + } else if (MEGA_flag === 1) {
246 + MEGA_count = 0; //MEGA_count 초기화
247 + MEGA_AbleLocationList.length = 0; //MEGA_AbleLocationList 초기화
248 + for (i of MEGABOX.location_data) {
249 + if (i['LocationName'].includes(message.text)) {
250 + MEGA_AbleLocationList[MEGA_count++] = i;
251 + }
252 + }
253 +
254 + if (MEGA_count == 1) { //결과 1개 => 바로 다음 단계 넘어가기
255 + MEGA_TheaterLocation = MEGA_AbleLocationList[0].LocationName;
256 + MEGA_TheaterLocationCode = MEGA_AbleLocationList[0].LocationNum;
257 + console.log(MEGA_TheaterLocation, MEGA_TheaterLocationCode);
258 + MEGA_flag++;
259 + } else if (MEGA_count > 1) { //결과 2개 이상 => 리스트 출력해주고 번호로 입력받아 넘어가기
260 + console.log(MEGA_AbleLocationList[0], MEGA_AbleLocationList[1]);
261 + let MEGA_OutputString = "원하시는 상영관의 번호를 정확히 입력해주세요\n"; //메가박스 영화관 가능 정보 string
262 + //PushSingleMessage("원하시는 상영관의 번호를 정확히 입력해주세요");
263 + for (let x = 0; x < MEGA_count; x++) {
264 + //PushSingleMessage(String(x + 1) + ": " + MEGA_AbleLocationList[x].LocationName);
265 + MEGA_OutputString += String(x + 1) + ": " + MEGA_AbleLocationList[x].LocationName + "\n";
266 + console.log(String(x + 1), MEGA_AbleLocationList[x].LocationName);
267 + }
268 + MEGA_OutputString += String(MEGA_count + 1) + ": 다시 검색하기";
269 + PushSingleMessage(MEGA_OutputString);
270 + MEGA_flag = 101;
271 + } else {
272 + PushSingleMessage("다시 입력해주세요.");
273 + }
274 + //원본 코드
275 + //console.log(MEGA_flag);
276 + // for (i of MEGABOX.location_data) {
277 + // if (i['LocationName'] === message.text) {
278 + // MEGA_TheaterLocationCode = i['LocationNUm'];
279 + // console.log(MEGA_TheaterLocationCode);
280 + // MEGA_flag++;
281 + // console.log(MEGA_flag)
282 + // break;
283 + // }
284 + // }
285 + } else if (MEGA_flag == 101) {
286 + // 0< input || input > MEGA_count+1 : 다시 검색
287 + let tempNum = parseInt(message.text);
288 + if (tempNum > 0 && tempNum < MEGA_count + 1) {
289 + //번호에 맞는 LocationCode 전달
290 + MEGA_TheaterLocation = MEGA_AbleLocationList[tempNum - 1].LocationName;
291 + MEGA_TheaterLocationCode = MEGA_AbleLocationList[tempNum - 1].LocationNum;
292 + console.log(MEGA_TheaterLocation, MEGA_TheaterLocationCode);
293 + MEGA_flag = 2;
294 + } else {
295 + //다시 장소 입력받기
296 + const text1 = "영화관 위치를 입력해주세요";
297 + const text2 = "ex1)강남";
298 + SendMessage(eventObj, text1, text2);
299 + MEGA_flag = 1;
300 + }
301 + }
302 + //날짜 입력 받기
303 + if (MEGA_flag == 2) {
304 + const text1 = "현재 영화관은 " + MEGA_TheaterLocation + " 입니다.\n영화를 보실 날짜를 입력해주세요.";
305 + const text2 = "ex)20020409";
306 + SendMessage(eventObj, text1, text2);
307 + MEGA_flag = 3;
308 + }
309 + //날짜 확인 및 날짜, 장소에 대해 상영중인 영화 리스트 가져오기
310 + if (moment(message.text, "YYYYMMDD", true).isValid() && MEGA_flag == 3) {
311 + MEGA_date = parseInt(message.text);
312 + let today = GettingToday();//오늘 이후인지 확인하기 위해 날짜 가져옴
313 + //console.log(MEGA_date, MEGA_TheaterLocation);
314 + if (today <= MEGA_date && MEGA_date && MEGA_TheaterLocationCode) {
315 + const text1 = "현재상영작을 가져오는 중입니다.";
316 + const text2 = "잠시만 기다려주세요.";
317 + PushMessage(text1, text2);
318 + MEGA_PlayingMovieURL = "https://megabox.co.kr/on/oh/ohb/SimpleBooking/simpleBookingPage.do" + '?brchNo1=' + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
319 + MEGABOX.using_PlayingMovieURL(MEGA_PlayingMovieURL);
320 + await MEGABOX.geting_PlayingMovie();
321 + console.log(MEGA_PlayingMovieURL, MEGABOX.movie_data);
322 + MEGA_flag = 4;
323 + }
324 + else {
325 + const text1 = "영화를 보실 날짜를 다시 입력해주세요.";
326 + const text2 = "ex)20020409";
327 + SendMessage(eventObj, text1, text2);
328 + }
329 + //원본 코드
330 + // MEGA_date = parseInt(eventObj.message.text);
331 + // if (MEGA_date && MEGA_TheaterLocationCode) {
332 + // MEGA_PlayingMovieURL = "https://megabox.co.kr/on/oh/ohb/SimpleBooking/simpleBookingPage.do" + '?brchNo1=' + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
333 + // console.log(MEGA_PlayingMovieURL)
334 + // async.waterfall[
335 + // MEGABOX.using_PlayingMovieURL(MEGA_PlayingMovieURL),
336 + // MEGABOX.geting_PlayingMovie()
337 + // ]
338 + // MEGA_flag++
339 + // console.log(MEGA_flag);
340 + // }
341 + }
342 + if (MEGA_flag == 4) {
343 + let obj = {};
344 + let n;
345 + let PlayingMovie = "-현재 상영작-\n\n";
346 + let movietitle;
347 + console.log(MEGABOX.movie_data);
348 + for (n = 0; n < Object.keys(MEGABOX.movie_data).length; n++) {
349 + if (MEGABOX.movie_data[n].running == 'Y') {
350 + console.log(MEGABOX.movie_data[n]);
351 + movietitle = MEGABOX.movie_data[n].title;
352 + MEGA_PlayingMovieList[movietitle] = MEGABOX.movie_data[n].movie_num;
353 + }
354 + }
355 + console.log(Object.keys(MEGA_PlayingMovieList).length);
356 + if (Object.keys(MEGA_PlayingMovieList).length == 0) {
357 + PushSingleMessage("현재상영작이 없습니다.\n영화관 선택 단계로 이동합니다.");
358 + setTimeout(function () {
359 + PushMessage("영화관 위치를 입력해주세요", "ex1)강남");
360 + }, 1000);
361 + MEGA_flag = 1;
362 + } else if (Object.keys(MEGA_PlayingMovieList).length == 1) {
363 + PlayingMovie += '1: ' + Object.keys(MEGA_PlayingMovieList)[0];
364 + PushMessage(PlayingMovie, "바로 링크가 보내집니다.");
365 + MEGA_title = MEGA_PlayingMovieList[Object.keys(MEGA_PlayingMovieList)[0]];
366 + setTimeout(function () {
367 + const PC_final_URL = "https://www.megabox.co.kr/booking?rpstMovieNo=" + MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
368 + const Smartphone_final_URL = "https://m.megabox.co.kr/booking/movie?movieNo=" + MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
369 + PushURLMessage(PC_final_URL, Smartphone_final_URL);
370 + setTimeout(function () {
371 + initFlag = false;
372 + MEGA_flag = -1;
373 + MEGA_PlayingMovieList = [];
374 + PushSingleMessage("원하시는 브랜드의 번호를 입력해주세요.\n1: CGV\n2: LotteCinema\n3: Megabox\n언제든 브랜드를 바꾸고 싶으시다면 '브랜드'를 입력해주세요.");
375 + }, 1000);
376 + }, 1000);
377 + } else {
378 + let index = 0;
379 + for (let playingmovie = 0; playingmovie < Object.keys(MEGA_PlayingMovieList).length; playingmovie++) {
380 + PlayingMovie += (playingmovie + 1).toString() + '. ' + Object.keys(MEGA_PlayingMovieList)[index++];
381 + PlayingMovie += "\n";
382 + }
383 + console.log(PlayingMovie);
384 + await PushMessage(PlayingMovie, "예매할 영화 번호를 입력해주세요.\n ex)1 (영화 앞 숫자만 입력)");
385 + MEGA_flag = 5;
386 + }
387 + } else if (MEGA_flag == 5) {
388 + const index = parseInt(message.text) - 1;
389 + console.log(Object.keys(MEGA_PlayingMovieList).length);
390 + if (index < 0 || index > Object.keys(MEGA_PlayingMovieList).length - 1) {
391 + PushSingleMessage("다시 입력해주세요!");
392 + } else {
393 + MEGA_title = MEGA_PlayingMovieList[Object.keys(MEGA_PlayingMovieList)[index]];
394 + const PC_final_URL = "https://www.megabox.co.kr/booking?rpstMovieNo=" + MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
395 + const Smartphone_final_URL = "https://m.megabox.co.kr/booking/movie?movieNo=" + MEGA_title + "&brchNo1=" + MEGA_TheaterLocationCode + '&playDe=' + MEGA_date;
396 + console.log(PC_final_URL, Smartphone_final_URL);
397 + PushURLMessage(PC_final_URL, Smartphone_final_URL);
398 + MEGA_PlayingMovieList = []; //영화 리스트 초기화
399 + MegaboxKakaoResultTheater = [];
400 + GetMegaboxKakaoMapURL(MEGA_TheaterLocation);
401 + setTimeout(function () {
402 + console.log(MegaboxKakaoResultTheater[0]);
403 + let MegaboxKakaoResultTheaterNAME = MegaboxKakaoResultTheater[0]['theater_name'];
404 + let MegaboxKakaoResultTheaterURL = MegaboxKakaoResultTheater[0]['theater_url'];
405 + console.log(MegaboxKakaoResultTheaterNAME, MegaboxKakaoResultTheaterURL);
406 + PushMessage(MegaboxKakaoResultTheaterURL, "카카오맵으로 검색한 " + MegaboxKakaoResultTheaterNAME + "의 위치입니다.");
407 + setTimeout(function () {
408 + //EGA_PlayingMovieList = [];
409 + initFlag = false;
410 + MEGA_flag = -1;
411 + PushSingleMessage("원하시는 브랜드의 번호를 입력해주세요.\n1: CGV\n2: LotteCinema\n3: Megabox\n언제든 브랜드를 바꾸고 싶으시다면 '브랜드'를 입력해주세요.");
412 + }, 1000);
413 + }, 2000);
414 + }
415 + }
416 + }
417 + res.sendStatus(200);
418 +}))
419 +//});
420 +try {
421 + const option = {
422 + ca: fs.readFileSync('/etc/letsencrypt/live/' + domain + '/fullchain.pem'),
423 + key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain + '/privkey.pem'), 'utf8').toString(),
424 + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain + '/cert.pem'), 'utf8').toString(),
425 + };
426 + HTTPS.createServer(option, app).listen(sslport, () => {
427 + console.log(`[HTTPS] Server is started on port ${sslport}`);
428 + });
429 +} catch (error) {
430 + console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
431 + console.log(error);
432 +}
433 +//오늘 날짜 구하기
434 +function GettingToday() {
435 + var today = new Date();
436 + var year = today.getFullYear();
437 + var month = ('0' + (today.getMonth() + 1)).slice(-2);
438 + var day = ('0' + today.getDate()).slice(-2);
439 + var dateString = year + month + day;
440 + var dateInt = parseInt(dateString);
441 + console.log(dateInt);
442 + return dateInt;
443 +}
444 +
445 +//24시간마다 데이터 초기화
446 +var dayInMilliseconds = 1000 * 60 * 60 * 24;
447 +setInterval(function () { MEGABOX.init(); console.log("success") }, dayInMilliseconds);
448 +
449 +//CGV - Kakao API로 영화관 위치 찾기
450 +function GetCGVKakaoLocalAPI(location) {
451 + let kakaoOptions = {
452 + url: "https://dapi.kakao.com/v2/local/search/keyword",
453 + method: "GET",
454 + headers: {
455 + 'Authorization': `KakaoAK ${KAKAO_KEY}`
456 + },
457 + qs: {
458 + 'query': `CGV ${location}`,
459 + //'category_group_code' : 'CT1',
460 + 'size': 5
461 + },
462 + encoding: 'UTF-8'
463 + };
464 + request(kakaoOptions, function (err, res, body) {
465 + info_list = JSON.parse(body).documents;
466 + if (!err && res.statusCode == 200) {
467 + info_list.forEach(info => {
468 + if (info.category_name.endsWith("CGV")) {
469 + const theater_info = {
470 + "theater_name": info.place_name.replace("CGV ", ""),
471 + "theater_url": info.place_url
472 + };
473 + CGV_RespondedTheaters.push(theater_info);
474 + console.log(theater_info);
475 + }
476 + });
477 + }
478 + });
479 +
480 +}
481 +
482 +//Megabox - Kakao API로 영화관 위치 찾기
483 +GetMegaboxKakaoMapURL = async (LOCATE) => {
484 + let KAKAOOPTION = {
485 + url: "https://dapi.kakao.com/v2/local/search/keyword",
486 + method: "GET",
487 + headers: {
488 + 'Authorization': `KakaoAK ${KAKAO_KEY}` // commit 할때 지워야 할것
489 + },
490 + qs: {
491 + 'query': '메가박스 ' + LOCATE, // 메가박스 영화관이름
492 + //'category_group_code' : 'CT1',
493 + 'size': 5
494 + },
495 + encoding: 'UTF-8'
496 + };
497 + let selectable_theaters = [];
498 + request(KAKAOOPTION, function (err, res, body) {
499 + info_list = JSON.parse(body).documents;
500 +
501 + if (!err && res.statusCode == 200) {
502 + info_list.forEach(info => {
503 + //console.log(info.category_name);
504 + if (info.category_name.endsWith("메가박스")) {
505 + const theater_info = {
506 + "theater_name": info.place_name,
507 + "theater_url": info.place_url
508 + };
509 + //console.log(theater_info);
510 + //return theater_info;
511 + selectable_theaters.push(theater_info);
512 + }
513 + });
514 + }
515 + console.log(selectable_theaters);
516 + MegaboxKakaoResultTheater = selectable_theaters;
517 + return;
518 + });
519 +
520 +}
521 +
522 +//메세지 전송하는 function 모음
523 +function SendMessage(eventObj, text1, text2 = "") { //reply message
524 + request.post(
525 + {
526 + url: REPLY_TARGET_URL,
527 + headers: {
528 + 'Authorization': `Bearer ${TOKEN}`
529 + },
530 + json: {
531 + "replyToken": eventObj.replyToken,
532 + "messages": [
533 + {
534 + "type": "text",
535 + "text": text1
536 + },
537 + {
538 + "type": "text",
539 + "text": text2
540 + }
541 + ]
542 + }
543 + }, (error, response, body) => {
544 + console.log(body);
545 + });
546 +}
547 +function PushMessage(text1, text2 = "") { //push two message
548 + request.post(
549 + {
550 + url: PUSH_TARGET_URL,
551 + headers: {
552 + 'Authorization': `Bearer ${TOKEN}`
553 + },
554 + json: {
555 + "to": `${USER_ID}`,
556 + "messages": [
557 + {
558 + "type": "text",
559 + "text": text1
560 + },
561 + {
562 + "type": "text",
563 + "text": text2
564 + }
565 + ]
566 + }
567 + }, (error, response, body) => {
568 + console.log(body)
569 + });
570 +}
571 +function PushSingleMessage(text1) {//push single message
572 + request.post(
573 + {
574 + url: PUSH_TARGET_URL,
575 + headers: {
576 + 'Authorization': `Bearer ${TOKEN}`
577 + },
578 + json: {
579 + "to": `${USER_ID}`,
580 + "messages": [
581 + {
582 + "type": "text",
583 + "text": text1
584 + }
585 + ]
586 + }
587 + }, (error, response, body) => {
588 + console.log(body)
589 + });
590 +}
591 +function PushURLMessage(pcurl, smartphoneurl) {//push single message
592 + request.post(
593 + {
594 + url: PUSH_TARGET_URL,
595 + headers: {
596 + 'Authorization': `Bearer ${TOKEN}`
597 + },
598 + json: {
599 + "to": `${USER_ID}`,
600 + "messages": [
601 + {
602 + "type": "text",
603 + "text": "pc버전 url입니다\n\n" + pcurl
604 + },
605 + {
606 + "type": "text",
607 + "text": "mobile버전 url입니다\n\n" + smartphoneurl
608 + }
609 + ]
610 + }
611 + }, (error, response, body) => {
612 + console.log(body)
613 + });
614 +}
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 +}