代码之家  ›  专栏  ›  技术社区  ›  Shaharyar Kirmani

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

  •  2
  • Shaharyar Kirmani  · 技术社区  · 8 年前

    我正在使用 nexmo NPM包。我已经根据文档实现了每件事,但我从服务器得到了响应,短信没有发送。

    {
      "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});
    
        }
      });
    });
    
    1 回复  |  直到 8 年前
        1
  •  1
  •   Shaharyar Kirmani    8 年前

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

    我升级到Blaze plan,它解决了这个问题。