Idea

jayson-vacaro avatar image
jayson-vacaro Posted ·

Any one created NodeJS Version of sending Fax? (Not a browser base)

topic-default
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Comment

· Write a Comment
Phong Vu avatar image
Phong Vu Posted ·
Hi Jayson,

Here you go. Just install the RingCentral Node JS SDK and the dotenv packages. Specify your app and login credentials in the .env file and run this code:

var RC = require('ringcentral')
require('dotenv').load()
var rcsdk = new RC({
  server: process.env.SERVER,
  appKey: process.env.APP_KEY,
  appSecret: process.env.APP_SECRET
})
var platform = rcsdk.platform()
login()
function login(){
  platform.login({
    username: process.env.USERNAME,
    password: process.env.PASSWORD
  })
  .then(function(resp){
    sendFAXMessage()
  })
  .catch(function(e){
    throw e
  })
}
function sendFAXMessage() {
  var toNumber = 'valid fax phone number'
  var FormData = require('form-data');
  formData = new FormData();
  var body = {
      to: [{'phoneNumber': toNumber}],
      faxResolution: 'High',
      coverPageText: "This is a demo Fax page"
  }
  // This is the mandatory part, the name and type should always be as follows
  formData.append('json', new Buffer(JSON.stringify(body)), {filename: 'request.json', contentType: 'application/json'});
  var fs = require('fs');
  var sendFile = 'test.jpg'
  formData.append('attachment', fs.createReadStream(sendFile));
  return platform
    .post('/account/~/extension/~/fax', formData)
    .then(function (response) {
        console.log("FAX sent")
    })
    .catch(function(e) {
        console.error(e);
        throw e;
    });
}

Hope this helps!

+ Phong
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Write a Comment

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Your Opinion Counts

Share your great idea, or help out by voting for other people's ideas.