Difference between revisions of "Telephone system:Space state"

From Hackerspace ACKspace
Jump to: navigation, search
m (fixed deprecated URI)
m (added category)
(One intermediate revision by the same user not shown)
Line 1: Line 1:
This script sets the spacestate variable according to what the webservice API returns.
+
<onlyinclude>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.
 
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
 
Currently it is used to build a sound phrase for playing it as a greeting within our IVR
 
+
</onlyinclude>
 
=== spacestate.js ===
 
=== spacestate.js ===
 
<pre>
 
<pre>
Line 61: Line 61:
 
</macro>
 
</macro>
 
</pre>
 
</pre>
[[Category:Telephony]]
+
[[Category:Telephony]][[Category:SpaceAPI]][[Category:Telephone snippet]][[Category:FreeSWITCH]]
[[Category:SpaceAPI]]
 

Revision as of 10:20, 14 February 2018

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>