-1

我正在尝试使用 twilio 功能一次性阻止垃圾邮件和 800#s,但它不起作用......

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 回答