Telephone system:Space state

From Hackerspace ACKspace
Jump to: navigation, search

This script sets the spacestate variable according to what the webservice API returns. It then can be used in the dialplan to, for example, play a sound file or do call forwarding. Currently it is used to build a sound phrase for playing it as a greeting within our IVR


// Checks the space state API: if "open" is not 'true',
// it's assumed closed and plays a sound file

if (session.ready())

    var state = fetchUrl( "" );
    if (state == false)
        console_log( 3, "could not fetch space state");
        // Remove newlines
        state = state.replace( /[\r\n]/g,"");

        if( !state.match(  /.*"open"[ \t]*:[ \t]*true.*/i ) )
            console_log(4, "Space seems to be closed, or could not parse result.\n");
            session.setVariable("spacestate", "closed");
        } else {
            console_log(4, "Space is open!\n");
            session.setVariable("spacestate", "open");

dialplan and ivr

The javascript is executed just before executing the IVR

<action application="javascript" data="spacestate.js"/>
<action application="ivr" data="ackspace_ivr"/>

and the corresponding IVR setting is:



This snippet is put under lang/nl/IVR/ackspace.xml and checks the given variable whether it is set to 'open'

<macro name="ackspace_welcome">
    <input pattern="^(open)$">
            <action function="play-file" data="ivr/welkom.wav"/>
            <action function="sleep" data="300"/>
            <action function="play-file" data="phrase:ackspace_welcome_short"/>
            <action function="play-file" data="ivr/welkom.wav"/>
            <action function="sleep" data="300"/>
            <action function="play-file" data="ivr/gesloten.wav"/>
            <action function="sleep" data="2000"/>
            <action function="play-file" data="phrase:ackspace_welcome_short"/>