Connecting LQ SIP to Twilio

Twilio is a decent choice for SIP Account provider for our LQ product, and dialing in from an external device, dialing out through the LQ web GUI, from the Telephone Directory in DynamEC, and via a speed dial in Eclipse works well.

TwiML for inbound calling looks like this:

<?xml version="1.0" encoding="UTF-8"?> 






The clearcom-lq information should be updated as necessary.

For dialing out, basic TwiML looks like this:

<?xml version="1.0" encoding="UTF-8"?> 


  <Dial callerId="+5103376660">{{#e164}}{{To}}{{/e164}}</Dial>



The caller ID will have to be a valid number for your Twilio installation or the call will be rejected (as can be seen via the Debugger. 

Dialing out via a panel through Twilio


Devices which send a sequence of numbers individually (rather than all at one time) such as V-Series and I-Stations will not be understood by Twilio.

Instead we use Programmable Voice > Functions > Classic Functions to provide a handler on our SIP account - remember to change the callerId to something valid:

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

let numberOfDigitsNeeded = 10;

let callerId =  +17729996375;

let wavURL = "";

 let twiml = new Twilio.twiml.VoiceResponse();

 let digitsSoFar = event.To;

 console.log("To: " + digitsSoFar);

 let sipAtSignIndex = digitsSoFar.indexOf("@");

 var remainingDigits = numberOfDigitsNeeded - (sipAtSignIndex-4); // minus whatever we already have

let dialedNumber = ""; 

 if(sipAtSignIndex > 0)


    dialedNumber = digitsSoFar.substring(4, sipAtSignIndex);

 } else {

     console.log("No dialed number detected - waiting for ten digits");

     remainingDigits = numberOfDigitsNeeded;


 console.log("Dialed number so far " + dialedNumber);

 if((event.Digits === undefined) && (remainingDigits > 0))


    // we are trying to get DTMF tones

    console.log("First time into Call Forward for this call");

    console.log("We still need to find " + remainingDigits + " digits");

    const gather = twiml.gather(


        input: "dtmf",

        numDigits: remainingDigits,

        finishOnKey: "#"



   gather.say(remainingDigits + " more digits");




    { // we have DTMF tones and just need to call them

      let phoneNumber = dialedNumber;

      if(event.Digits !== undefined)


          phoneNumber = dialedNumber + event.Digits


      console.log("We have digits - " +  phoneNumber);

        let dialParams = {};

        dialParams.callerId = callerId;


        twiml.say(phoneNumber.split("").join(" "));

        // above line is a hack but say-as interpret as telephone didn't work

        twiml.dial(dialParams, phoneNumber);


  // return the TwiML

  callback(null, twiml);