javascript - 使用 nexmo npm 包从服务器获取错误以发送 SMS

标签 javascript node.js google-cloud-functions vonage

我正在使用 nexmo NPM 包。我已经根据文档实现了所有内容,但我从服务器收到了此响应,但未发送 SMS。

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

我将其实现为 Firebase Cloud Function .这是代码

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});

    }
  });
});

最佳答案

我想出了问题所在。它不适用于 nexmo npm 包。问题是我在 firebase 的 spark 计划中,这个免费计划不允许我们从函数调用第三方 API。

我升级到 Blaze 计划并解决了这个问题。

关于javascript - 使用 nexmo npm 包从服务器获取错误以发送 SMS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48010920/

相关文章:

javascript - 为什么浏览器中的绘制会被推迟?

node.js - 无法使用 express 发布/错误

javascript - 期望不正确的智能感知方法

javascript - 从 header 获取 token 时,req.headers.split 不是函数

javascript - 当firebase函数从webapp代理时,如何验证当前用户?

Firebase/Firestore 查找在给定数组中具有字段的文档

javascript - Angular2 和 Gridstack.js 问题 : $(. ..).gridstack 不是函数

javascript - 多个字段的错误消息验证问题

javascript - 使用localstorage解决缓存的css和js

javascript - 为什么这个模板不能正常工作?