은승우

Update app.js

Showing 1 changed file with 6 additions and 17 deletions
......@@ -5,7 +5,7 @@ var request = require('request');
var https=require('https');
var http=require('http');
var mime=require('mime-types');
var png=require('png-js');
var fs = require("fs");
var httpsOptions = {
......@@ -80,7 +80,7 @@ async function handleEvent(event) {
// ignore non-message event
return Promise.resolve(null);
}
else if (event.type == 'message'&& event.message.type == 'image') {
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) {
return new Promise(async(resolve,reject)=>{
await client.getMessageContent(event.message.id)
......@@ -89,18 +89,9 @@ async function handleEvent(event) {
await stream.on('data', (chunk) => {
console.log(typeof(chunk));
fs.writeFileSync("./photo/1.png",chunk);
var PNG = require('png-js');
var myimage = new PNG(chunk);
var width = myimage.width;
var height = myimage.height;
myimage.decode(function (pixels) {
//Pixels is a 1D array containing pixel data
var cheerio = require('cheerio');
var cheerio = require('cheerio');
var uriBase = 'https://koreacentral.api.cognitive.microsoft.com/vision/v2.1/ocr';
var imageUrl=event.message.text;
var options = {
uri: uriBase,
qs: {
......@@ -111,11 +102,11 @@ myimage.decode(function (pixels) {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': '979dc5d63344438fa4701c62feebb7dc'
},
body: myimage
body:'{"url": ' + '"' + imageUrl + '"}',
};
request.post(options, function (error, response, body) {
var data=options.body;
var data=body;
console.log(data);
var text='';
while(data.indexOf('text\\')!=-1)
......@@ -149,8 +140,6 @@ myimage.decode(function (pixels) {
});
});
});
......