Showing
1 changed file
with
41 additions
and
36 deletions
| ... | @@ -34,42 +34,47 @@ app.post('/message', function(req,res){ | ... | @@ -34,42 +34,47 @@ app.post('/message', function(req,res){ |
| 34 | 34 | ||
| 35 | var send = {}; | 35 | var send = {}; |
| 36 | function delay(){ | 36 | function delay(){ |
| 37 | - switch(msg){ | 37 | + return new Promise(function(resolve, reject){ |
| 38 | - case '일본' : | 38 | + switch (msg) { |
| 39 | - send = { | 39 | + case '일본': |
| 40 | - 'message' : { | 40 | + send = { |
| 41 | - 'text' : '등록된 가수 목록입니다.' | 41 | + 'message': { |
| 42 | - }, | 42 | + 'text': '등록된 가수 목록입니다.' |
| 43 | - keyboard : { | 43 | + }, |
| 44 | - 'type' : 'buttons', | 44 | + keyboard: { |
| 45 | - 'buttons' : ['Reol', '米津玄師', 'yanaginagi', 'ヨルシカ', 'ダズビ', 'Polkadot Stingray', 'Aimyong'] | 45 | + 'type': 'buttons', |
| 46 | - } | 46 | + 'buttons': ['Reol', '米津玄師', 'yanaginagi', 'ヨルシカ', 'ダズビ', 'Polkadot Stingray', 'Aimyong'] |
| 47 | - | 47 | + } |
| 48 | - }; | ||
| 49 | - break; | ||
| 50 | - case '한국' : | ||
| 51 | - send = { | ||
| 52 | - 'message' : { | ||
| 53 | - 'text' : '등록된 가수 목록입니다.' | ||
| 54 | - }, | ||
| 55 | - keyboard : { | ||
| 56 | - 'type' : 'buttons', | ||
| 57 | - 'buttons' : ['볼빨간 사춘기', 'MOT', 'Gukkasten', 'ZICO', 'DEAN', 'IU', 'Heize'] | ||
| 58 | - } | ||
| 59 | - }; | ||
| 60 | - break; | ||
| 61 | - default: | ||
| 62 | - singer.jpSinger(msg).then(function(result){ | ||
| 63 | - send = result; | ||
| 64 | - }) | ||
| 65 | - if(send == '') | ||
| 66 | - send = singer.krSinger(msg); | ||
| 67 | - break; | ||
| 68 | - } | ||
| 69 | - } | ||
| 70 | - delay().then(function(){ | ||
| 71 | - console.log(send); | ||
| 72 | 48 | ||
| 73 | - res.json(send); | 49 | + }; |
| 50 | + break; | ||
| 51 | + case '한국': | ||
| 52 | + send = { | ||
| 53 | + 'message': { | ||
| 54 | + 'text': '등록된 가수 목록입니다.' | ||
| 55 | + }, | ||
| 56 | + keyboard: { | ||
| 57 | + 'type': 'buttons', | ||
| 58 | + 'buttons': ['볼빨간 사춘기', 'MOT', 'Gukkasten', 'ZICO', 'DEAN', 'IU', 'Heize'] | ||
| 59 | + } | ||
| 60 | + }; | ||
| 61 | + break; | ||
| 62 | + default: | ||
| 63 | + singer.jpSinger(msg).then(function (result) { | ||
| 64 | + send = result; | ||
| 65 | + }) | ||
| 66 | + if (send == '') | ||
| 67 | + send = singer.krSinger(msg); | ||
| 68 | + break; | ||
| 69 | + } | ||
| 70 | + if(send){ | ||
| 71 | + resolve(send) | ||
| 72 | + } | ||
| 73 | + reject(new Error("Request is failed")); | ||
| 74 | + }); | ||
| 75 | + } | ||
| 76 | + delay().then(function(result){ | ||
| 77 | + console.log(result); | ||
| 78 | + res.json(result); | ||
| 74 | }) | 79 | }) |
| 75 | }) | 80 | }) |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment