은승우

Update app.js

Showing 1 changed file with 6 additions and 11 deletions
...@@ -81,12 +81,8 @@ async function handleEvent(event) { ...@@ -81,12 +81,8 @@ async function handleEvent(event) {
81 return Promise.resolve(null); 81 return Promise.resolve(null);
82 } 82 }
83 else if (event.type == 'message'&& event.message.type == 'image') { 83 else if (event.type == 'message'&& event.message.type == 'image') {
84 - return new Promise(async(resolve,reject)=>{ 84 + return new Promise(async(resolve,reject)=>{
85 - client.getMessageContent(event.message.id) 85 + fs.writeFileSync('./photo/image.png',event.message.image)
86 - .then((stream) => {
87 - stream.on('data', (chunk) => {
88 - client.replyMessage(event.replyToken,chunk).then(resolve).catch(reject);
89 - /*
90 var cheerio = require('cheerio'); 86 var cheerio = require('cheerio');
91 87
92 var uriBase = 'https://koreacentral.api.cognitive.microsoft.com/vision/v2.1/ocr'; 88 var uriBase = 'https://koreacentral.api.cognitive.microsoft.com/vision/v2.1/ocr';
...@@ -101,11 +97,11 @@ async function handleEvent(event) { ...@@ -101,11 +97,11 @@ async function handleEvent(event) {
101 'Content-Type': 'application/octet-stream', 97 'Content-Type': 'application/octet-stream',
102 'Ocp-Apim-Subscription-Key': '979dc5d63344438fa4701c62feebb7dc' 98 'Ocp-Apim-Subscription-Key': '979dc5d63344438fa4701c62feebb7dc'
103 }, 99 },
104 - body: chunk 100 + body: fs.readFileSync('./photo/image.png')
105 }; 101 };
106 102
107 request.post(options, function (error, response, body) { 103 request.post(options, function (error, response, body) {
108 - 104 + data=body;
109 var text=''; 105 var text='';
110 while(data.indexOf('text\\')!=-1) 106 while(data.indexOf('text\\')!=-1)
111 { 107 {
...@@ -137,10 +133,9 @@ async function handleEvent(event) { ...@@ -137,10 +133,9 @@ async function handleEvent(event) {
137 } 133 }
138 client.replyMessage(event.replyToken,result).then(resolve).catch(reject); 134 client.replyMessage(event.replyToken,result).then(resolve).catch(reject);
139 }); 135 });
140 - });*/ 136 + });
137 +
141 }); 138 });
142 - });
143 - })
144 } 139 }
145 else if(event.type == 'message' && event.message.type == 'text') 140 else if(event.type == 'message' && event.message.type == 'text')
146 { 141 {
......