은승우

Update app.js

Showing 1 changed file with 6 additions and 17 deletions
...@@ -5,7 +5,7 @@ var request = require('request'); ...@@ -5,7 +5,7 @@ var request = require('request');
5 var https=require('https'); 5 var https=require('https');
6 var http=require('http'); 6 var http=require('http');
7 var mime=require('mime-types'); 7 var mime=require('mime-types');
8 -var png=require('png-js'); 8 +
9 var fs = require("fs"); 9 var fs = require("fs");
10 10
11 var httpsOptions = { 11 var httpsOptions = {
...@@ -80,7 +80,7 @@ async function handleEvent(event) { ...@@ -80,7 +80,7 @@ async function handleEvent(event) {
80 // ignore non-message event 80 // ignore non-message 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 == "text"&&event.message.text.indexOf('https://')!=-1&&event.message.text.indexOf('png')!=-1&&event.message.text.indexOf('jpg')!=-1) {
84 return new Promise(async(resolve,reject)=>{ 84 return new Promise(async(resolve,reject)=>{
85 85
86 await client.getMessageContent(event.message.id) 86 await client.getMessageContent(event.message.id)
...@@ -89,18 +89,9 @@ async function handleEvent(event) { ...@@ -89,18 +89,9 @@ async function handleEvent(event) {
89 await stream.on('data', (chunk) => { 89 await stream.on('data', (chunk) => {
90 console.log(typeof(chunk)); 90 console.log(typeof(chunk));
91 fs.writeFileSync("./photo/1.png",chunk); 91 fs.writeFileSync("./photo/1.png",chunk);
92 - 92 + var cheerio = require('cheerio');
93 - var PNG = require('png-js');
94 -
95 -var myimage = new PNG(chunk);
96 -
97 -var width = myimage.width;
98 -var height = myimage.height;
99 -
100 -myimage.decode(function (pixels) {
101 - //Pixels is a 1D array containing pixel data
102 - var cheerio = require('cheerio');
103 var uriBase = 'https://koreacentral.api.cognitive.microsoft.com/vision/v2.1/ocr'; 93 var uriBase = 'https://koreacentral.api.cognitive.microsoft.com/vision/v2.1/ocr';
94 + var imageUrl=event.message.text;
104 var options = { 95 var options = {
105 uri: uriBase, 96 uri: uriBase,
106 qs: { 97 qs: {
...@@ -111,11 +102,11 @@ myimage.decode(function (pixels) { ...@@ -111,11 +102,11 @@ myimage.decode(function (pixels) {
111 'Content-Type': 'application/json', 102 'Content-Type': 'application/json',
112 'Ocp-Apim-Subscription-Key': '979dc5d63344438fa4701c62feebb7dc' 103 'Ocp-Apim-Subscription-Key': '979dc5d63344438fa4701c62feebb7dc'
113 }, 104 },
114 - body: myimage 105 + body:'{"url": ' + '"' + imageUrl + '"}',
115 }; 106 };
116 107
117 request.post(options, function (error, response, body) { 108 request.post(options, function (error, response, body) {
118 - var data=options.body; 109 + var data=body;
119 console.log(data); 110 console.log(data);
120 var text=''; 111 var text='';
121 while(data.indexOf('text\\')!=-1) 112 while(data.indexOf('text\\')!=-1)
...@@ -149,8 +140,6 @@ myimage.decode(function (pixels) { ...@@ -149,8 +140,6 @@ myimage.decode(function (pixels) {
149 }); 140 });
150 }); 141 });
151 142
152 -});
153 -
154 143
155 144
156 145
......