2017-09-07 9 views
1

私は管理者の電話番号に警告SMSを送信し、ローカル言語バージョンのSTOP応答を元のSMSに返信しようとしていますこの番号の自動応答をオフにする)。Twilio機能:STOP要求を処理する着信SMSを送信しようとしています

以下のコードは、orignatorに応答を送信するために機能しますが、必要な番号(現在+447824636xxx)に警告SMSを送信しません。

Twilio機能でどのように動作するかについては、ヘルプドキュメント、StackOverflow、またはGoogle Twilioデベロッパーグループでは何も見つかりません。

強調表示されたコードをどのように機能させるかを教えてください。

exports.handler = function(context, event, callback) { 


console.log ("Incoming SMS") 
console.log (event.From) 
console.log (event.Body) 

if (event.Body == "STOP" || event.Body == "Stop" || event.Body == "stop") { 

console.log ("Received a STOP message") 

// ***** BELOW CODE DOES NOT SEND SMS **** 

// Send a warning message to Chloe 
let client = context.getTwilioClient() 

let c = client.messages.create({ 
     body: "We have a STOP message on Fresenius NO from ", 
     to: "+447824636xxx", 
     from: event.To 
}) 

// ***** ABOVE CODE DOES NOT SEND ANYTHING ***** 

console.log ("Sent warning to Admin") 

// Respond to the user/patient with STOP message in local language 
let twiml = new Twilio.twiml.MessagingResponse(); 
twiml.message("Du har nå meldt deg av MyFresubin og vil ikke motta flere meldinger fra dette nummeret."); 
twiml.message.to = event.From 
twiml.message.from = "+4759444xxx" 
callback(null, twiml); 
} 

else {callback(null)} 

} 

答えて

2

あなたのコードでは、あなたもすぐにコールバック関数を呼び出しているので、動作しませんし、完了することができるというTwilioのAPIを呼び出す前実行を終了します。

の作業コード:もちろん

exports.handler = function (context, event, callback) { 

    let twiml = new Twilio.twiml.MessagingResponse(); 
    twiml.message("Du har nå meldt deg av MyFresubin og vil ikke motta flere ...."); 


    let client = context.getTwilioClient(); 

    // Send a warning message to Chloe 
    client.messages 
     .create({ 
      to: '+447824636xxx', 
      from: event.To, 
      body: "We have a STOP message on Fresenius NO from " + event.From 
     }) 
     .then(message => { 
      console.log(message.sid); 

      // Respond to the user/patient with STOP message in local language 
      callback(null, twiml); 
     }); 
} 

は、あなたの元のコードでは、あなたが持っているSTOP条件文を追加して自由に感じます。

関連する問題