Showing
1 changed file
with
24 additions
and
5 deletions
... | @@ -45,14 +45,33 @@ function handleEvent(event) { | ... | @@ -45,14 +45,33 @@ function handleEvent(event) { |
45 | // ignore non-text-message event | 45 | // ignore non-text-message event |
46 | return Promise.resolve(null); | 46 | return Promise.resolve(null); |
47 | } | 47 | } |
48 | + return new Promise(function(resolve, reject) { | ||
49 | + // Naver Papago Translate | ||
50 | + var options = { | ||
51 | + url: translate_api_url, | ||
52 | + // 한국어(source : ko), 영어(target: en), 카톡에서 받는 메시지(text) | ||
53 | + form: {'source':'ko', 'target':'en', 'text':event.message.text}, | ||
54 | + headers: {'X-Naver-Client-Id': client_id, 'X-Naver-Client-Secret': client_secret} | ||
55 | + }; | ||
48 | 56 | ||
57 | + // Naver Post API | ||
58 | + request.post(options, function(error, response, body){ | ||
59 | + // Translate API Sucess | ||
60 | + if(!error && response.statusCode == 200){ | ||
61 | + // JSON | ||
62 | + var objBody = JSON.parse(response.body); | ||
63 | + // Message 잘 찍히는지 확인 | ||
49 | 64 | ||
50 | - // create a echoing text message | 65 | + const result = { type: 'text', text: objBody.message.result.translatedText}; |
51 | - const echo = { type: 'text', text: event.message.text }; | 66 | + console.log(result.text); |
67 | + client.replyMessage(event.replyToken,result).then(resolve).catch(reject); | ||
68 | + } | ||
69 | + }); | ||
70 | + }); | ||
71 | + // use reply API | ||
72 | + //return client.replyMessage(event.replyToken,objBody.message.result.translatedText); | ||
73 | + } | ||
52 | 74 | ||
53 | - // use reply API | ||
54 | - return client.replyMessage(event.replyToken, echo); | ||
55 | -} | ||
56 | 75 | ||
57 | 76 | ||
58 | app.listen(3000, function () { | 77 | app.listen(3000, function () { | ... | ... |
-
Please register or login to post a comment