EC2 Default User

Fix app.js

Showing 1 changed file with 34 additions and 35 deletions
......@@ -3,7 +3,6 @@ const request = require('request');
const PUSH_TARGET_URL = 'https://api.line.me/v2/bot/message/push'
const REPLY_TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
const TOKEN = 'Zd+BLpi6wLHMngB3EK74S1W7ApnAXuYZ86xGIi60JKrSW0xI0JyXlCzpunYxk9fxtOkH4y2/CNrb6K7WYldpXBwUkCKNIyEQ04AUpQKQ1EzS6C3qm6y5sBm0zs/Gmzn6n1v1jLfmSpxyLir7VqHk5wdB04t89/1O/w1cDnyilFU='
const USER_ID = 'Uaa6ee8ae309532533aead588d062180d'
const fs = require('fs');
const path = require('path');
const HTTPS = require('https');
......@@ -14,14 +13,40 @@ const bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.json());
request.post(
const foodArr = [
{index : 1, kr_name: "한식", en_name: 'korean food'},
{index : 2, kr_name: "중식", en_name: 'chinese food'},
{index : 3, kr_name: "양식", en_name: 'western food'},
{index : 4, kr_name: "일식", en_name: 'japanese food'},
{index : 5, kr_name: "분식", en_name: 'snack food'},
{index : 6, kr_name: "아시안", en_name: 'asian food'},
{index: 7, kr_name: "패스트푸드", en_name: 'fast food'},
{index: 8, kr_name: "학식", en_name: 'school food'}
];
app.post('/hook', function (req, res) {
var eventObj = req.body.events[0];
var source = eventObj.source;
var message = eventObj.message;
// request log
console.log('======================', new Date() ,'======================');
console.log('[request]', req.body);
console.log('[request source] ', eventObj.source);
console.log('[request message]', eventObj.message);
var food = foodArr.find(element => element.index == message.text || element.kr_name == message.text || element.en_name == message.text.toLowerCase());
if (message.text == "안내" || message.text.toLowerCase() == "guide"){
request.post(
{
url: PUSH_TARGET_URL,
url: REPLY_TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"to": `${USER_ID}`,
"replyToken":eventObj.replyToken,
"messages":[
{
"type":"sticker",
......@@ -51,39 +76,13 @@ request.post(
},(error, response, body) => {
console.log(body)
});
app.post('/hook', function (req, res) {
var eventObj = req.body.events[0];
var source = eventObj.source;
var message = eventObj.message;
const foodArr = [
{index : 1, kr_name: "한식", en_name: 'Korean food'},
{index : 2, kr_name: "중식", en_name: 'Chinese food'},
{index : 3, kr_name: "양식", en_name: 'Western food'},
{index : 4, kr_name: "일식", en_name: 'Japanese food'},
{index : 5, kr_name: "분식", en_name: 'Snack food'},
{index : 6, kr_name: "아시안", en_name: 'Asian food'},
{index: 7, kr_name: "패스트푸드", en_name: 'Fast food'},
{index: 8, kr_name: "학식", en_name: 'School food'}
];
// request log
console.log('======================', new Date() ,'======================');
console.log('[request]', req.body);
console.log('[request source] ', eventObj.source);
console.log('[request message]', eventObj.message);
var food = foodArr.find(element => element.index == message.text || element.kr_name == message.text || element.en_name == message.text);
console.log(food);
if (food != undefined){
}
else if (food != undefined){
request.post(
{
url: REPLY_TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
Authorization: `Bearer ${TOKEN}`
},
json: {
"replyToken":eventObj.replyToken,
......@@ -92,8 +91,8 @@ app.post('/hook', function (req, res) {
"type": "location",
"title": "my location",
"address": "1-6-1 Yotsuya, Shinjuku-ku, Tokyo, 160-0004, Japan",
"latitude": 35.687574,
"longitude": 139.72922
"latitude": 37.5666805,
"longitude": 126.9784147
}
]
}
......