EC2 Default User

Add English version

Showing 1 changed file with 55 additions and 31 deletions
...@@ -59,14 +59,14 @@ app.post('/hook', function (req, res) { ...@@ -59,14 +59,14 @@ app.post('/hook', function (req, res) {
59 var message = eventObj.message; 59 var message = eventObj.message;
60 60
61 const foodArr = [ 61 const foodArr = [
62 - {index : 1, name: "한식"}, 62 + {index : 1, kr_name: "한식", en_name: 'Korean food'},
63 - {index : 2, name: "중식"}, 63 + {index : 2, kr_name: "중식", en_name: 'Chinese food'},
64 - {index : 3, name: "양식"}, 64 + {index : 3, kr_name: "양식", en_name: 'Western food'},
65 - {index : 4, name: "일식"}, 65 + {index : 4, kr_name: "일식", en_name: 'Japanese food'},
66 - {index : 5, name: "분식"}, 66 + {index : 5, kr_name: "분식", en_name: 'Snack food'},
67 - {index : 6, name: "아시안"}, 67 + {index : 6, kr_name: "아시안", en_name: 'Asian food'},
68 - {index: 7, name: "패스트푸드"}, 68 + {index: 7, kr_name: "패스트푸드", en_name: 'Fast food'},
69 - {index: 8, name: "학식"} 69 + {index: 8, kr_name: "학식", en_name: 'School food'}
70 ]; 70 ];
71 71
72 // request log 72 // request log
...@@ -75,31 +75,55 @@ app.post('/hook', function (req, res) { ...@@ -75,31 +75,55 @@ app.post('/hook', function (req, res) {
75 console.log('[request source] ', eventObj.source); 75 console.log('[request source] ', eventObj.source);
76 console.log('[request message]', eventObj.message); 76 console.log('[request message]', eventObj.message);
77 77
78 - var food = foodArr.find(element => element.index == message.text || element.name == message.text); 78 + var food = foodArr.find(element => element.index == message.text || element.kr_name == message.text || element.en_name == message.text);
79 79
80 console.log(food); 80 console.log(food);
81 - 81 + if (food != undefined){
82 - request.post( 82 + request.post(
83 - { 83 + {
84 - url: REPLY_TARGET_URL, 84 + url: REPLY_TARGET_URL,
85 - headers: { 85 + headers: {
86 - 'Authorization': `Bearer ${TOKEN}` 86 + 'Authorization': `Bearer ${TOKEN}`
87 - }, 87 + },
88 - json: { 88 + json: {
89 - "replyToken":eventObj.replyToken, 89 + "replyToken":eventObj.replyToken,
90 - "messages":[ 90 + "messages":[
91 - { 91 + {
92 - "type": "location", 92 + "type": "location",
93 - "title": "my location", 93 + "title": "my location",
94 - "address": "1-6-1 Yotsuya, Shinjuku-ku, Tokyo, 160-0004, Japan", 94 + "address": "1-6-1 Yotsuya, Shinjuku-ku, Tokyo, 160-0004, Japan",
95 - "latitude": 35.687574, 95 + "latitude": 35.687574,
96 - "longitude": 139.72922 96 + "longitude": 139.72922
97 - } 97 + }
98 - ] 98 + ]
99 - } 99 + }
100 - },(error, response, body) => { 100 + },(error, response, body) => {
101 - console.log(body) 101 + console.log(body)
102 - }); 102 + });
103 + }
104 + else{
105 + request.post(
106 + {
107 + url:REPLY_TARGET_URL,
108 + headers:{
109 + 'Authorization' :`Bearer ${TOKEN}`
110 + },
111 + json:{
112 + "replyToken": eventObj.replyToken,
113 + "messages":[
114 + {
115 + "type" : "text",
116 + "text":"음식을 다시 입력 해주세요."
117 + },
118 + {
119 + "type" : "text",
120 + "text":"Please enter the food again"
121 + }
122 + ]
123 + }
124 + }
125 + )
126 + }
103 127
104 res.sendStatus(200); 128 res.sendStatus(200);
105 }); 129 });
......