-1

twilio 機能を使ってスパムと 800# を一発でブロックしようとしていますが、うまくいきません...

4

1 に答える 1

0

以下のように関数を変更できます。

exports.handler = function(context, event, callback) {
  // set-up the variables that this Function will use to forward a phone call using TwiML
  
  // REQUIRED - you must set this to the number you want calls forwarded to
  let phoneNumber = event.PhoneNumber || "+16787801234";  
  
  // OPTIONAL
  let callerId =  event.CallerId || null;
  // OPTIONAL
  let timeout = event.Timeout || null;
  // OPTIONAL +266696687 = ANONYMOUS Callers
  let blacklistedCallers = event.blacklistedCallers || ["+14073601234","+15185001234", "+266696687"];
  
  // generate the TwiML to tell Twilio how to forward this call
  let twiml = new Twilio.twiml.VoiceResponse();
  
  console.log(event.From.substring(0,5));
  
  let allowedThrough = false;
  if (blacklistedCallers.length > 0) {
    if ((blacklistedCallers.indexOf(event.From) === -1) && (event.From.substring(0,5) != "+1800")) {
      allowedThrough = true;    
    }
  }

  let dialParams = {};
  if (callerId) {
    dialParams.callerId = callerId;
  }
  if (timeout) {
    dialParams.timeout = timeout;
  }
  
  if (allowedThrough) {
    twiml.dial(dialParams, phoneNumber);
  }
  else {
    twiml.reject({reason: 'rejected'});
  }
  
  // return the TwiML
  callback(null, twiml);
};

于 2018-06-17T13:58:06.500 に答える