Javascript FAQ

From FreeSWITCH Wiki
Jump to: navigation, search

Frequently answered questions. Feel free to ask your own questions. We will answer then as soon as we can.

Contents

Q: How do I transfer a call to a UA

[17:02]	<Verifier> MikeJ: Yeah. But I could do a session.originate and then bridge. That would work like a transfer. Right? 
 i.e. connecting the caller with an UA
[17:03]	<MikeJ>	no.. it would block your script
[17:03]	<anthm>	no but if that's what you want to do then it's fine
[17:03]	<anthm>	calling out to somewhere is a bridge
[17:04]	<anthm>	transfer is to take your inbound call and go run some different script for example

Q: How can I make a delay (to make a pause between phrases?)

See: Sleep

Q: How can I pass variables to my JavaScript?

On console:

  jsrun script.js arg1 arg2 ...

These can be accessed as argv[0], argv[1],.. in the script

In dialplan

  <extension ...>
    <condition ...>
       <action application="javascript" data="script.js ${caller_id_number}"/>
     </condition>
   </extension>

If you're running the script as an application for originate command

   originate sofia/internal/1000 &javascript(script.js arg1)          //single argument
   originate sofia/internal/1000 '&javascript(script.js arg1 arg2)'   //multiple arguments

Q: How can I print stuff inside my JavaScript?

  console_log("notice","<Whatever you need to print>");


--Gakul 06:00, 13 September 2008 (EDT)

Q: Can I save the parsed code to gain performance for often-used bits and pieces?