Telephone system:Space state
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
spacestate.js
// Checks the space state API: if "open" is not 'true', // it's assumed closed and plays a sound file if (session.ready()) { session.preAnswer(); var state = fetchUrl( "https://ackspace.nl/spaceAPI" ); if (state == false) console_log( 3, "could not fetch space state"); else { // 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:
greet-long="phrase:ackspace_welcome:${spacestate}"
phrase
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)$"> <match> <action function="play-file" data="ivr/welkom.wav"/> <action function="sleep" data="300"/> <action function="play-file" data="phrase:ackspace_welcome_short"/> </match> <nomatch> <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"/> </nomatch> </input> </macro>