Showing
1 changed file
with
33 additions
and
6 deletions
1 | var express = require('express'); | 1 | var express = require('express'); |
2 | const request = require('request'); | 2 | const request = require('request'); |
3 | const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' | 3 | const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' |
4 | -const TOKEN = 'zVAczqoJ+L9oykqhEj7HoP7f6Nyb+R3T1TntHXQhYihI+KIxH4SZDGpKu0jKsMXMHKBVXpmbybA+oaV8u/dfLppKe3NHXU9AdBVypy9NgfWiFPLlcwm3GdkVPAZGoS4nvOCXWDKUb+ixPKWjlbnChAdB04t89/1O/w1cDnyilFU=' | 4 | +const TOKEN = '' |
5 | const fs = require('fs'); | 5 | const fs = require('fs'); |
6 | const path = require('path'); | 6 | const path = require('path'); |
7 | const HTTPS = require('https'); | 7 | const HTTPS = require('https'); |
... | @@ -21,13 +21,12 @@ app.post('/hook', function (req, res) { | ... | @@ -21,13 +21,12 @@ app.post('/hook', function (req, res) { |
21 | 21 | ||
22 | // request log | 22 | // request log |
23 | console.log('======================', new Date(), '======================'); | 23 | console.log('======================', new Date(), '======================'); |
24 | - | ||
25 | // mwsql | 24 | // mwsql |
26 | var mysql = require('mysql'); | 25 | var mysql = require('mysql'); |
27 | var db = mysql.createConnection({ | 26 | var db = mysql.createConnection({ |
28 | host: 'chatbot.c7fzgftc3yrm.us-east-1.rds.amazonaws.com', | 27 | host: 'chatbot.c7fzgftc3yrm.us-east-1.rds.amazonaws.com', |
29 | user: 'chatbot', | 28 | user: 'chatbot', |
30 | - password: '11111111', | 29 | + password: '', |
31 | database: 'chatbot', | 30 | database: 'chatbot', |
32 | port: '3306' | 31 | port: '3306' |
33 | }); | 32 | }); |
... | @@ -38,8 +37,15 @@ app.post('/hook', function (req, res) { | ... | @@ -38,8 +37,15 @@ app.post('/hook', function (req, res) { |
38 | if (error) { | 37 | if (error) { |
39 | console.log(error); | 38 | console.log(error); |
40 | } | 39 | } |
41 | - for (var i = 0; i < results.length; i++) | 40 | + var index = 0; |
41 | + var istrue = false; | ||
42 | + for (var i = 0; i < results.length; i++) { | ||
42 | if (results[i].ingredients === message.text) { | 43 | if (results[i].ingredients === message.text) { |
44 | + index = i; | ||
45 | + istrue = true; | ||
46 | + } | ||
47 | + } | ||
48 | + if (istrue) { | ||
43 | request.post( | 49 | request.post( |
44 | { | 50 | { |
45 | url: TARGET_URL, | 51 | url: TARGET_URL, |
... | @@ -51,11 +57,31 @@ app.post('/hook', function (req, res) { | ... | @@ -51,11 +57,31 @@ app.post('/hook', function (req, res) { |
51 | "messages": [ | 57 | "messages": [ |
52 | { | 58 | { |
53 | "type": "text", | 59 | "type": "text", |
54 | - "text": `메뉴는 "${results[i].menu}" 입니다.` | 60 | + "text": `메뉴는 "${results[index].menu}" 입니다.` |
61 | + }, | ||
62 | + { | ||
63 | + "type": "text", | ||
64 | + "text": `레시피\n${results[index].recipe}` | ||
65 | + } | ||
66 | + ] | ||
67 | + } | ||
68 | + }, (error, response, body) => { | ||
69 | + console.log(body) | ||
70 | + }); | ||
71 | + } | ||
72 | + else { | ||
73 | + request.post( | ||
74 | + { | ||
75 | + url: TARGET_URL, | ||
76 | + headers: { | ||
77 | + 'Authorization': `Bearer ${TOKEN}` | ||
55 | }, | 78 | }, |
79 | + json: { | ||
80 | + "replyToken": eventObj.replyToken, | ||
81 | + "messages": [ | ||
56 | { | 82 | { |
57 | "type": "text", | 83 | "type": "text", |
58 | - "text": `레시피\n${results[i].recipe}` | 84 | + "text": `재료를 다시 입력해주세요.` |
59 | } | 85 | } |
60 | ] | 86 | ] |
61 | } | 87 | } |
... | @@ -83,3 +109,4 @@ try { | ... | @@ -83,3 +109,4 @@ try { |
83 | console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'); | 109 | console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'); |
84 | console.log(error); | 110 | console.log(error); |
85 | } | 111 | } |
112 | + | ... | ... |
-
Please register or login to post a comment