[Freeswitch-users] config / scripting questions from voice mail integration attempt

Anthony Minessale anthony.minessale at gmail.com
Thu Jun 26 07:50:30 PDT 2008


You may want to join IRC for some real-time help but I will try to answer
your questions.


On Wed, Jun 25, 2008 at 10:32 PM, John Wehle <john at feith.com> wrote:

> The AT&T System 25 sends inband DTMF at the beginning of a call being
> transferred to voicemail which identifies the extension that was called
> so I'm creating a javascript to parse the DTMF and do the right thing.
>
> Questions:
>
>  1) Following the example I found on thelostpacket.org I've created
>     a script and placed it in /usr/local/freeswitch/scripts.  I've
>     added:
>
>    <extension name="system25_vmail">
>      <condition field="destination_number" expression="^5590$">
>        <action application="javascript"
> data="$${basedir}/scripts/system25vmail.js"/>
>      </condition>
>    </extension>
>
>    to dialplan/default.xml.  When I call 5590 freeswitch can't find
>    the script.  If I replace $${basedir} with /usr/local/freeswitch,
>    then the script is called.
>
>    What's the proper way to specify the path to a script in the dialplan?
>    Is there a way to say that it's in the script directory under the
>    freeswitch installation point without using a full path?
>

it's actually $${base_dir}
also a script with a relative path will assume $${base_dir}/scripts/ in
front of it.


>
>  2) The DTMF looks something like 123#456# .  If I use getDigits(3, '#')
>     followed by another getDigits(3, '#'), then the first call returns
>     123, however the second call doesn't return 456.
>
>     It appears that getDigits returns when it either gets the requested
>     number of digits * or * it encounters the terminator.  Is that correct?
>     So should I simply do something like getDigits(9, '#') followed by
>     another getDigits(9, '#')?
>

Yes that is correct I have tested this script and it works:

session.answer();
a = session.getDigits(9, "#");
b = session.getDigits(9, "#");
consoleLog("err", "READ A=" + a + " B=" + b + "\n");




>
>  3) One thought I had was to do something like:
>
>     <extension name="system25_vmail">
>       <condition field="destination_number" expression="^5590$">
>       <action application="javascript"
> data="$${basedir}/scripts/system25vmail.js"/>
>
>       <!-- Inside extension checking voicemail -->
>       <condition field="system25_vmail_mode" expression="00">
>         <action application="voicemail" data="check default $${domain}
> ${system25_vmail_caller}"/>
>       </condition>
>
>       <!-- Inside extension bounced to voicemail -->
>       <condition field="system25_vmail_mode" expression="02">
>         <action application="voicemail" data="default $${domain}
> ${system25_vmail_callee}"/>
>         <action application="send_dtmf"
> data="#90${system25_vmail_callee}"/>
>       </condition>
>
>     the idea being that when 5590 is dialed the script will be called
>     to parse the DTMF and set the system25_vmail_XXX variables which
>     are then used by the later conditions.  However the wiki for
>     Dialplan XML says:
>
>       Those accustomed to Asterisk may expect the call to follow the
>       dialplan by executing the applications as it parses them allowing
>       data obtained from one action to influence the next action. This
>       is not the case ...
>
>     so it sounds like I can't use an action to set variables to be used
>     for the next condition / action.  However the example on
>     thelostpacket.org does:
>
>       <action application="javascript" data="$${basedir}/scripts/read.js
> conf-getconfno.wav 5"/>
>       <action application="conference" data="${res}@default"/>
>
>     which appears to do exactly what wiki says you can't so I'm confused.
>

What that means is that when the *dialplan* is being parsed it does not
begin executing anything until it has parsed then entire dialplan.  The
variables that begin with $$ are parsed once when FS starts and permanently
substituted while the ones that start with just 1 $ are parsed when the
extension executes.

So the jist is that you cannot assume the XML dialplan is executing the apps
as the XML is being parsed.
Rather, it parses it all and is left with a set of instructions with all the
variables not yet expanded.

So the example is correct because you can choose to execute one application
and expect that application to set some critical variables then assume those
variables to be set in the next application because those applications are
called in order.

The only thing you can't do is set a variable in one action of your dialplan
and then expect that variable to be set to do more <condition> tags inside
that same dialplan.



>
>  4) My other thought was to have the javascript call the voicemail
>     application after parsing the DTMF.  I.e.:
>
>     switch (mode) {
>      // Direct Inside Access
>      case "00":
>        if (isNaN (parseInt (from))) {
>          console_log ("err", "Invalid VMAIL calling PDC from PBX\n");
>          session.flushDigits ();
>          exit();
>          }
>
>        session.setVariable ("voicemail_authorized", "false");
>        apiExecute ("voicemail", "check default " + domain + " " + from);
>
>     however the apiExecute doesn't seem to invoke voicemail.  Probably
>     because there's a difference between invoking an application and
>     an api.  So, how do you invoke an application from a javascript
>     called from a dialplan?
>


apiExecute is for FSAPI calls voicemail is a dialplan application.
you would want to do one of the following:

session.execute("voicemail", "<voicemail args>");
session.execute("transfer", "<some ext that leads to voicemail>");

Your plan to set the variables is the best one to avoid overhead of leaving
JS running.
You may also want to investigate LUA which is a lighter weight scripting
engine that is similar to JS and also available.




> -- John
> -------------------------------------------------------------------------
> |   Feith Systems  |   Voice: 1-215-646-8000  |  Email: john at feith.com  |
> |    John Wehle    |     Fax: 1-215-540-5495  |                         |
> -------------------------------------------------------------------------
>
>
> _______________________________________________
> Freeswitch-users mailing list
> Freeswitch-users at lists.freeswitch.org
> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
> http://www.freeswitch.org
>



-- 
Anthony Minessale II

FreeSWITCH http://www.freeswitch.org/
ClueCon http://www.cluecon.com/

AIM: anthm
MSN:anthony_minessale at hotmail.com <MSN%3Aanthony_minessale at hotmail.com>
GTALK/JABBER/PAYPAL:anthony.minessale at gmail.com<PAYPAL%3Aanthony.minessale at gmail.com>
IRC: irc.freenode.net #freeswitch

FreeSWITCH Developer Conference
sip:888 at conference.freeswitch.org <sip%3A888 at conference.freeswitch.org>
iax:guest at conference.freeswitch.org/888
googletalk:conf+888 at conference.freeswitch.org<googletalk%3Aconf%2B888 at conference.freeswitch.org>
pstn:213-799-1400
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20080626/0a2c91a6/attachment-0002.html 


More information about the FreeSWITCH-users mailing list