Twilio功能 - 阻止垃圾邮件/ 800#s

时间:2018-06-16 17:43:49

标签: twilio twilio-api twilio-functions

我试图使用twilio函数一次性阻止垃圾邮件和800#s,但它无效......

1 个答案:

答案 0 :(得分: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);
};




相关问题