简体   繁体   中英

Getting error from server using nexmo npm package to send SMS

I am using nexmo NPM package. I have implemented every thing according to the docs but I am getting this response from the server and SMS is not delivered.

{
  "code": "ENOTFOUND",
  "errno": "ENOTFOUND",
  "syscall": "getaddrinfo",
  "hostname": "rest.nexmo.com",
  "host": "rest.nexmo.com",
  "port": 443
}

I am implementing this as a Firebase Cloud Function . This is the code

exports.SMS = functions.https.onRequest((request, response) => {

  console.log("This is the function");
  console.log(request.body);
  var json = JSON.parse(request.body);
  const phone = json.phone;

  console.log(phone);

  const nexmo = new Nexmo({
    apiKey: '******',
    apiSecret: '*********'
  });


  const from = '12017016978';
  const to = phone;
  const text = 'Thank You for using TPV Express. Please use the following link to download our voice-enabled Android app for Third Party Verification.  https://play.google.com/store/apps/details?id=com.patientdatascience.tpvexpress&hl=en';

  nexmo.message.sendSms(from, to, text, (error, res) => {
    if(error) {
      // throw error;
      console.log(error);
      response.json({success: false,data: error});
    } else if(res.messages[0].status != '0') {
      console.error(res);
      response.json({success: false,data: res});
      // throw 'Nexmo returned back a non-zero status';
    } else {
      console.log(res);
      response.json({success: true,data: res});

    }
  });
});

I figured out what the issue is. It is not with nexmo npm package. The issue is i am on spark plan of firebase and this free plan does not allow us to call third party API's from the function.

I upgraded to Blaze plan and it fixed the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM