[Freeswitch-users] Javascript input

Jonas Gauffin jonas.gauffin at gmail.com
Mon Aug 20 07:12:39 PDT 2007


Yes you may ask =) And sorry for the delay.

Since I only used the module internally I coded it with my own
personal preference. I think that
say("to_conference_1;to_queue_2;to_operator_3"); looks nicer than
say(["to_conference_1", "to_queue_2", "to_operator_3"]); or say(new
Array("to_conference_1", "to_queue_2", "to_operator_3"));

But since I'm going to clean it up and create a module for FreeSwitch
I'll switch to using an array instead.

On 8/11/07, Nikolay Kolev <me at nikolay.com> wrote:
> My I asked why you used a semicolon-separated list when JavaScript already
> supports arrays? For example, instead of:
>
>         "to_conference_1;to_queue_2;to_operator_3"
>
> you could have simply used:
>
>         ["to_conference_1", "to_queue_2", "to_operator_3"]
>
> The other nice thing is that you can check if it's an array or a string. If
> it's a string, then, obviously, you would treat it like a single-item array.
>
> This is self-documented and more efficient, too.
>
> Nikolay
> -----Original Message-----
> From: freeswitch-users-bounces at lists.freeswitch.org
> [mailto:freeswitch-users-bounces at lists.freeswitch.org] On Behalf Of Jonas
> Gauffin
> Sent: Saturday, August 11, 2007 7:08 AM
> To: freeswitch-users at lists.freeswitch.org
> Subject: Re: [Freeswitch-users] Javascript input
>
> I've written a module for the input handling and for playing phrases
> only when dtmf digits are not pressed (which can be overridden). I got
> a couple of OOP javascript modules (for freeswitch) that I can
> contribute with.
>
> Should javascript modules be checked in too? Currently there are a lot
> of example code in the wiki, but it doesn't feel like the right place.
> Maybe there should be some example applications and modules in the
> repository?
>
> for instance, my module can do this:
>
> digit = input.getByMenu("123", "to_conference_1;to_queue_2;to_operator_3");
>
> That creates a complete menu that does this:
> a) Only valid digits are 123
> b) It plays "choice_invalid" if an invalid choice was pressed (max three
> times)
> c) plays "choice_timeout" if the user do not enter anything
> d) playes "choice_too_many_tries" if three attempts was made.
> e) It plays all of the soundfiles that was separated with semicolon
> f) Soundfiles that end with "_X" are handled in a special way. _X will
> be substituted with "pressX" soundfile. i.e the following soundfiles
> will be played: "to_conference", "press1", to_queue", "press2",
> "to_operator", "press3". That's perfect if you got a database driven
> menu where u want to reuse your normal sound files.
>
> I've also made the module aware of language choice. (You can switch
> language any time in the IVR apps).
>
> Thanks for the answer about streamFile. I guess that a standardized
> javascript module will do instead.
>
> On 8/11/07, Anthony Minessale <anthmct at yahoo.com> wrote:
> >
> > The notion of the callback goes all the way down to the core.  The C
> portion
> > of the code is where the digit is dequeued so there is no way to avoid it.
> >
> > So, When you call streamFile you can not only pass a function to callback,
> > you can also pass an arbitrary object.  That way you can get that object
> as
> > "arg" in your example callback and push the digits onto a shared string
> > there.
> >
> >
> > The intention is to make a pure js class for this kind of thing that we
> can
> > put in tree and people can use it to make their scripts.
> >
> >
> >
> > function mycb (type, data, arg) {
> >
> >  if (type == "dtmf") {
> >  arg.digits += data;
> >  return false;
> >  }
> > }
> >
> > var dtmf = new Object();
> > dtmf.digits = "";
> > session.streamFile("blah.wav", mycb, dtmf);
> > //say you need 3 digits so subtract how many you have so far.
> > dtmf.digits += getDigits(3 - dtmf.digits.length, "#", 5000);
> >
> > This is a crude example but you can see how you could write this into a
> > permanently  used module everyone could use.  The idea is to make the js
> the
> > place where you can continue to code functionality without touching the
> > core.  That is the reason the default api is the lowest level possible
> > without going too far.
> >
> > This pure js module has yet to be written but we probably should get
> started
> > on it soon before we make everyone duplicate this kind of thing....
> >
> >
> > Anthony Minessale II
> >
> > FreeSWITCH http://www.freeswitch.org/
> > ClueCon http://www.cluecon.com/
> >
> > AIM: anthm
> > MSN:anthony_minessale at hotmail.com
> > JABBER:anthony.minessale at gmail.com
> > IRC: irc.freenode.net #freeswitch
> >
> > FreeSWITCH Developer Conference
> > sip:888 at conference.freeswitch.org
> > iax:guest at conference.freeswitch.org/888
> > googletalk:conf+888 at conference.freeswitch.org
> > pstn:213-799-1400
> >
> >
> > ----- Original Message ----
> > From: Jonas Gauffin <jonas.gauffin at gmail.com>
> > To: freeswitch-users at lists.freeswitch.org
> > Sent: Saturday, August 11, 2007 3:37:26 AM
> > Subject: Re: [Freeswitch-users] Javascript input
> >
> > Ok. Let's take an example:
> >
> > I got a voicemail application that plays a lot of phrases. Let's check
> > a simple example:
> >
> > session.streamFile("you_have.wav");
> > session.streamFile("2.wav");
> > session.streamFile("new_messages.wav");
> > choice = session.getDigit(1, "", 5000);
> >
> > Ok. I want to skip to the second voicemail by pressing 2. That's not
> > possible with the code above. Instead you have to do something like
> > this:
> >
> > var _digits = "";
> > function on_dtmf(type, digits, arg)
> > {
> >   _digits += digits;
> >   return false;
> > }
> >
> > function say(phrase)
> > {
> >   if (_digits != "")
> >     return false;
> >   session.streamFile(phrase, on_dtmf);
> > }
> >
> > function getDigits(length, terminators, timeout)
> > {
> >   if (_digits != '')
> >   {
> >     var tempVar = _digits;
> >     _digits = "";
> >     return tempVar;
> >   }
> >   return session.getDigits(length, terminators, timeout);
> > }
> >
> > say("you_have.wav");
> > say("2.wav");
> > say("new_messages");
> > choice = getDigits(1, "", 5000);
> >
> > Right? That will abort speach on input and return the pressed digit.
> > But what if we want to enter a pincode or something like that? Then we
> > need to handle both _digits AND use session.getDigits:
> >
> > function getDigits(length, terminators, timeout)
> > {
> >   if (_digits.length < length)
> >   {
> >     tempVar = _digits;
> >     _digits = "";
> >     tempVar += session.getDigits(length - _digits.length, terminators,
> > timeout);
> >     return tempVar;
> >   }
> >   else
> >   {
> >     tempVar = _digits;
> >     _digits = "";
> >     return tempVar;
> >   }
> > }
> >
> > Get my point? All of that could have been two lines of code if there
> > was an alternative to streamFile which do not remove the DTMF from the
> > input queue (or whatever it's called):
> >
> > session.streamAndAbortOnDtmf("theFile.wav");
> > var digit = session.getDigits(1, "", 3000);
> >
> > All I wanted was an alternative that is simple. Again: I'm not looking
> > for a replacement of streamFile but an complement for those who just
> > want to do the above.
> >
> > I apologize if my examples are incorrect in some way, I've written
> > them directly in this email with my mind as a reference. I might have
> > done some syntax errors or something like that. Afterall, it's
> > saturday =)
> >
> > But anyway. I can create an alternative to streamFile which does
> > On 8/10/07, Chris Danielson <chris at maxpowersoft.com> wrote:
> > > Jonas,
> > > To what purpose would having a streamFile abort without DTMF input?  If
> > > the streamFile operation is going to require aborting then DTMF input or
> > > voice recognition will be the means.  Jonas, your heart is in the right
> > > place, but everything you have asked for is already implemented in a
> very
> > > flexible manner within the JavaScript engine.
> > > Regards,
> > > Chris Danielson
> > >
> > > > Yes. The current architecture works just fine.
> > > >
> > > > I'm not saying that the current method should be removed. It's
> > > > excellent in those cases when you want to filter input during
> > > > streamFile and recordFile. But I still think that those cases are more
> > > > rare than wanting to abort the speech.
> > > >
> > > > Consider this a feature request then: A new streamFile that do not eat
> > > > DTMF but aborts the speech instead. Or simply a new argument that
> > > > specifies that the method should abort instead of eating the DTMF.
> > > >
> > > > On 8/10/07, Mike Murdock <mmurdock at coppercom.com> wrote:
> > > >> You do currently have the option to either continue playing the
> prompt
> > > >> or abort the prompt. In order to collect the digits during the
> playing
> > > >> of a prompt you must code a dtmf_callback handler. When a user
> presses
> > a
> > > >> digit your call back handler gets called. You can decide it the digit
> > is
> > > >> a valid one and if it is valid return "false" (or the digit) causing
> > the
> > > >> prompt to stop. If the digit is not valid you can ignore it by
> > returning
> > > >> "true" and the prompting will continue. While this does require the
> > > >> application developer to code a digit handler it gives you a much
> > richer
> > > >> option for the handling of the results.
> > > >>
> > > >> You are free to develop your own wrapper function to force the
> > > >> particular behaviour you want. I have written a getdigits function in
> > > >> javascript that you are welcome to use to get the behaviour you are
> > > >> looking for.
> > > >>
> > > >>
> > > >> Michael B. Murdock
> > > >>
> > > >>
> > > >>
> > > >> ________________________________
> > > >>
> > > >> From: freeswitch-users-bounces at lists.freeswitch.org on
> > behalf of Jonas
> > > >> Gauffin
> > > >> Sent: Fri 8/10/2007 2:49 AM
> > > >> To: freeswitch-users at lists.freeswitch.org
> > > >> Subject: Re: [Freeswitch-users] Javascript input
> > > >>
> > > >>
> > > >>
> > > >> Why not simply make another streamFile method that aborts on input.
> > > >> Then the user can choose which one he wants.
> > > >>
> > > >> I can elaborate my wish too. I guess that you have used a lot of IVR
> > > >> applications, right?
> > > >> For instance, you call your phone provider and they have a IVR m
> > >
> > >
> > > _______________________________________________
> > > 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
> > >
> >
> > _______________________________________________
> > 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
> >
> >
> >  ________________________________
> > Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail,
> > news, photos & more.
> > _______________________________________________
> > 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
> >
> >
>
> _______________________________________________
> 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
>
>
> _______________________________________________
> 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
>




More information about the FreeSWITCH-users mailing list