1

I have the following code which using Twilio automatically places calls from a number, to a number, which I set manually. My problem is that I need it to place calls to different numbers, from different numbers, at random.

I want the to: and from: to choose at random between a list of pre-set numbers. These numbers will change often. While I can do it manually in the code, I think ideally it would pull those values from a different file - one for to: and one for from:.

Thanks for the help.


var accountId = 'your acount sid here'
var accountToken = 'your account token here'

var client = twilio(accountId, accountToken)
var INTERVAL = 10000 // 10 seconds

var count = 0

var call = function() {
  return client.calls.create({
    url: 'https://<lin>',
    to: '+<target number>',
    from: '+1<source number>'
  }, function (err, res) {
    if (err) return console.error(err)
    count++
    console.log('number ', count, 'status: ', res.status)
  })
}

call()
setInterval(call, INTERVAL)
  • you can read file into variable via https://stackoverflow.com/questions/34857458/reading-local-text-file-into-a-javascript-array – Ajay Nov 18 '20 at 17:53
  • then you need to generate a random number for index https://stackoverflow.com/questions/1527803/generating-random-whole-numbers-in-javascript-in-a-specific-range – Ajay Nov 18 '20 at 17:55
  • A code example here - https://www.twilio.com/docs/runtime/quickstart/serverless-functions-run-function-widget-studio – Alan Nov 18 '20 at 18:32
  • I did read the file into the variable but now I don't know what to do. How do I make the to: and from: pull values from it? – tipsymillionaire Nov 18 '20 at 19:45

0 Answers0