Toggle navigation
Toggle navigation
This project
Loading...
Sign in
은승우
/
LINEBOT
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
은승우
2019-12-05 19:17:57 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a849ebd999f08c334e6c9f2badee7493fe45acd1
a849ebd9
1 parent
b21ae402
Update app.js
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
16 deletions
app.js
app.js
View file @
a849ebd
...
...
@@ -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
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) {
});
});
});
...
...
Please
register
or
login
to post a comment