Pexip Service BYOC Simplified Phone Dialer Macro (updated to fix ERM deployment bug - 03_24_23)

Phone dialer macro for Pexip Service registered endpoints calling via BYOC with dial string prefix normalization logic for in country dialing.

The version below is currently configured for calls within the United States, including dial strings starting with 1, 91, 9).

The prefix normalization ensures that dialed SIP audio call’s actual dial string that is sent to the Pexip Service and the BYOC carrier/voice environment correctly is converted to +1 (or whatever country code that is configured to match BYOC rules).

For international calls it assumes end users will dial + and the country code (basically anything that doesn’t match the specified in country dialing pattern specified).

In line 35 of the macro, change the
const AUDIO_DOMAIN = '@pexip_service_domain.com' to whichever domain your is used by your endpoints for SIP registration to the Pexip Service.

If you aren’t using on an endpoint in the United States, on line 31 change the 1|91|9 in const REGEXP_NUMERICDIALERLOCAL = /^(1|91|9)?(\d{10})$/ to whatever in country or local dial prefixes might exist, and change on line 34 the +1 in const DIALPREFIX_LOCAL = '+1' to the desired in country prefix to match the configured Pexip Service BYOC prefix.

And for any dial strings that don’t match the regex logic (for example if some other symbol other than + was used for the prefix, or if the dial string is too long) the macro won’t even attempt the call, but instead will reload the dial interface and display the message “You typed in an invalid number. Please try again”


Currently the macro uses the below stock Cisco phone icon/button and has a greenish teal color.
The button UI extension is built into the macro.
phone call button


Here’s a screenshot of the dial interface. You can edit the labels and instructional language in the macro to be whatever you want.




And, here’s the macro! Enjoy!
(Big thank yous to Nick Warfield and Kevin Roarty for help with the logic and cleanup of the macro!)

const xapi = require('xapi');

xapi.Command.UserInterface.Extensions.Panel.Save({ PanelId: 'audiocall' }, `<Extensions> 
  <Version>1.0</Version>
  <Panel>
    <PanelId>audiocall</PanelId>
    <Origin>local</Origin>
    <Type>Home</Type>
    <Icon>Handset</Icon>
    <Color>#00d6a2</Color>
    <Name>Phone Call</Name>
  </Panel>
</Extensions>`);

const KEYBOARD_TYPES = {
      NUMERIC     :   'Numeric'
    , SINGLELINE  :   'SingleLine'
    , PASSWORD    :   'Password'
    , PIN         :   'PIN'
}
const CALL_TYPES = {
      AUDIO     :   'Audio'
    , VIDEO     :   'Video'
}

const DIALPAD_ID = 'dialpad';
const INROOMCONTROL_AUDIOCONTROL_PANELID = 'audiocall';

/* Use these to check that its a valid number (depending on what you want to allow users to call) */
const REGEXP_NUMERICDIALERINTL =  /^([+])([0-9]{10,15})$/; /* Use this one if you want to limit calls to numeric only. In this example, require number to be between 3 and 10 digits. */
const REGEXP_NUMERICDIALERLOCAL =  /^(1|91|9)?(\d{10})$/; /* Currently configured for USA and Canada, if this is for use in a different country, change the 1|91|9 logic here to map to the country specific dial prefix const */

const DIALPREFIX_INTL = '+';
const DIALPREFIX_LOCAL = '+1'; /* change the number to match the local country code, it needs to keep the '+' before the country code in this case since we are mapping to the '+'' prefix in BYOC */
const AUDIO_DOMAIN = '@pexip_service_domain.com'; /* change this to match endpoint's Pexip Service registration domain */

function showDialPad(text){

         xapi.command("UserInterface Message TextInput Display", {
               InputType: KEYBOARD_TYPES.NUMERIC
             , Placeholder: "Use keypad to enter number" 
             , Title: "Audio Call"
             , Text: text
             , SubmitText: "Call" 
             , FeedbackId: DIALPAD_ID
         }).catch((error) => { console.error(error); });
}

/* This is the listener for the in-room control panel button that will trigger the dial panel to appear */
xapi.event.on('UserInterface Extensions Panel Clicked', (event) => {
    if(event.PanelId === INROOMCONTROL_AUDIOCONTROL_PANELID){
         showDialPad("Enter the phone number you want to dial:" );
    }
});


/* Event listener for the dial pad been posted */

xapi.event.on('UserInterface Message TextInput Response', (event) => {
    switch(event.FeedbackId){
        case DIALPAD_ID:
            
            var regex = REGEXP_NUMERICDIALERINTL; 
            var match = regex.exec(event.Text);
            var regex2 = REGEXP_NUMERICDIALERLOCAL; 
            var match2 = regex2.exec(event.Text);     
            if (match !== null) {
                var numbertodial = match[2];
                numbertodial = DIALPREFIX_INTL + numbertodial + AUDIO_DOMAIN; // Here you can do some massaging of the number to dial, e.g. if it need prefixing or postfixing 
                 xapi.command("dial", {Number: numbertodial, CallType: CALL_TYPES.AUDIO}).catch((error) => { console.error(error); });
            }
            else if(match2 !== null) {
                var numbertodial = match2[2];
                numbertodial = DIALPREFIX_LOCAL + numbertodial + AUDIO_DOMAIN; // Here you can do some massaging of the number to dial, e.g. if it need prefixing or postfixing 
                 xapi.command("dial", {Number: numbertodial, CallType: CALL_TYPES.AUDIO}).catch((error) => { console.error(error); });
            }
            else {
                showDialPad("You typed in an invalid number. Please try again." );
            }
            break;
    }
});
1 Like

This macro failed to save to device when pushing from ERM. Had to remove the trailing 3 apostrophes.

Thanks for the heads up! Corrected. Aside from that, @dbwest is the macro working for you?

Yes it is. Thanks James

1 Like