Sunday 18 November 2018

help with twilio and ocr.space api. I got twilio to receive the mms from a number but i can't forward the picture to ocr.space

hello guys, How do I "forward" the picture from twilio to the ocr.api then return the extracted text back to twilio phone number as sms.const fs = require('fs'); const express = require('express'); const bodyParser = require('body-parser'); const twilio = require('twilio'); const request = require('request'); const ocrSpaceApi = require('ocr-space-api'); const MessagingResponse = require('twilio').twiml.MessagingResponse;const app = express();app.use(bodyParser.urlencoded({ extended: false }));//ttps://https://ift.tt/2A2GGKE var options = { apikey: 'xxxxxxxxxxxxxxx', language: 'eng', // English imageFormat: 'image/png', // Image Type (Only png ou gif is acceptable at the moment i wrote this) isOverlayRequired: true };app.post('/sms', (req, res) => { const twiml = new MessagingResponse();if (req.body.NumMedia !== '0') { const filename = ${req.body.MessageSid}.png; const url = req.body.MediaUrl0;// Download the image. //const imageFilePath = "imageFile.jpg"; ocrSpaceApi.parseImageFromLocalFile('url', options) //passing the image from twilio text .then(function (parsedResult) { console.log('parsedText: \n', parsedResult.parsedText); console.log('ocrParsedResult: \n', parsedResult.ocrParsedResult); }).catch(function (err) { console.log('ERROR:', err); twiml.message('Thanks for the image!'); } else { twiml.message('Try sending a picture message.'); }res.send(twiml.toString()); });app.listen(3000, () => console.log('Example app listening on port 3000!'));

Submitted November 18, 2018 at 08:14AM by teddyoliver

No comments:

Post a Comment