Showing
1 changed file
with
5 additions
and
38 deletions
... | @@ -62,42 +62,6 @@ const client = new line.Client(config); | ... | @@ -62,42 +62,6 @@ const client = new line.Client(config); |
62 | 62 | ||
63 | // register a webhook handler with middleware | 63 | // register a webhook handler with middleware |
64 | // about the middleware, please refer to doc | 64 | // about the middleware, please refer to doc |
65 | - | ||
66 | -// Creates a client | ||
67 | -var vision = require('google-vision-api-client'); | ||
68 | - | ||
69 | -var requtil = vision.requtil; | ||
70 | - | ||
71 | - | ||
72 | - | ||
73 | -//Prepare your service account from trust preview certificated project | ||
74 | - | ||
75 | -var jsonfile = '/home/ubuntu/a/LINEBOT/googlevisionapikey'; | ||
76 | - | ||
77 | - | ||
78 | - | ||
79 | -//Initialize the api | ||
80 | - | ||
81 | -vision.init(jsonfile); | ||
82 | - | ||
83 | - | ||
84 | - | ||
85 | -//Build the request payloads | ||
86 | -var d = requtil.createRequests().addRequest( | ||
87 | -requtil.createRequest('/home/ubuntu/a/LINEBOT/photo/Fancy=TWICE.jpg') | ||
88 | -.withFeature('Optical Character Recognition', 3) | ||
89 | -.build()); | ||
90 | -//Do query to the api server | ||
91 | -vision.query(d, function(e, r, d){ | ||
92 | -if(e) console.log('ERROR:', e); | ||
93 | - console.log(JSON.stringify(d)); | ||
94 | -}); | ||
95 | - | ||
96 | - | ||
97 | - | ||
98 | - | ||
99 | - | ||
100 | - | ||
101 | app.post('/webhook', line.middleware(config), (req, res) => { | 65 | app.post('/webhook', line.middleware(config), (req, res) => { |
102 | Promise | 66 | Promise |
103 | .all(req.body.events.map(handleEvent)) | 67 | .all(req.body.events.map(handleEvent)) |
... | @@ -114,9 +78,12 @@ function handleEvent(event) { | ... | @@ -114,9 +78,12 @@ function handleEvent(event) { |
114 | // ignore non-message event | 78 | // ignore non-message event |
115 | return Promise.resolve(null); | 79 | return Promise.resolve(null); |
116 | } | 80 | } |
117 | - else if(event.type == 'message' && event.message.type == 'image') | 81 | + else if (event.type == 'message'&& event.message.type == 'image') { |
118 | - { | 82 | + return new Promise((resolve,reject)=>{ |
83 | + var upload = multer({ dest: 'photo/' }) | ||
84 | + upload.single(event.message.image); | ||
119 | 85 | ||
86 | + }) | ||
120 | } | 87 | } |
121 | else if(event.type == 'message' && event.message.type == 'text') | 88 | else if(event.type == 'message' && event.message.type == 'text') |
122 | { | 89 | { | ... | ... |
-
Please register or login to post a comment