2017-12-28 7 views
2

NPMパッケージnexmoを使用しています。私はドキュメントに従ってすべてのものを実装しましたが、私はこの応答をサーバーから取得しており、SMSは配信されません。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}); 

    } 
    }); 
}); 
+0

あなたはどのURLを指しているのですか?このURLを指す必要があります 'https:// rest.nexmo.com/sms/json' – Hackerman

+0

私はこのhttps://developer.nexmo.com/messaging/sms/に従います。概要応答が何であるか、あなたはこれが応答{ "コード" であるres.jsonに –

+0

: "ENOTFOUND"、 "エラー番号": "ENOTFOUND"、 "システムコール": "のgetaddrinfo"、 「ホスト名":" rest.nexmo.com "、 " host ":" rest.nexmo.com "、 " port ":443 } –

答えて

1

私は問題が何かを理解しました。 nexmo npmパッケージではありません。問題は私がfirebaseの計画を立てていることにあり、このフリープランでは、サードパーティのAPIを関数から呼び出すことはできません。

Blazeプランにアップグレードして問題を修正しました。

関連する問題