[Freeswitch-users] Adding SIP Headers in Javascript
Preston Hagar
prestonh at gmail.com
Wed May 23 18:28:09 UTC 2018
Thanks, I'll try it out!
On Wed, May 23, 2018 at 1:01 PM, Michael Jerris <mike at jerris.com> wrote:
> session.setVariable(var, val);
>
>
> On May 23, 2018, at 1:46 PM, Preston Hagar <prestonh at gmail.com> wrote:
>
> I figured out my issue. I had left out part of my code in previous emails
> to try to make it simpler, and left out the part that was messing things up.
>
> So after I set the sip Diversion header:
>
> var diversionHeader = 'sip_h_Diversion=<sip:' + $destination_number + '@
> pbx.example.org>;privacy=off;reason=unconditional;counter=1;screen=no';
>
> session.execute('set',diversionHeader);
>
>
> I would set a timeout:
>
> session.execute('set', 'call_timeout=45');
>
>
> Then I would ring all three receptionist stations at once with a bridge
> command:
>
>
> var logic = '{ignore_early_media=true}user/1000@' + $pbx_domain +
> ':_:user/1001@'
> + $pbx_domain + ':_:user/1002@' + $pbx_domain;
> session.execute('bridge', logic);
>
>
> The problem ended up stemming from me ringing all three at once using the
> :_: to join the extensions. I switched it over to commas:
>
> var logic = '{ignore_early_media=true}user/1000@' + $pbx_domain +
> ',user/1001@'
> + $pbx_domain + ',user/1002@' + $pbx_domain;
> session.execute('bridge', logic);
>
> and now the Diversion header shows up as expected. We shouldn't have
> multiple registrations for any of those numbers, so it shouldn't be an
> issue.
>
> Thanks everyone for taking a look.
>
>
> Out of curiosity, what is the "direct method" for setting the SIP header
> (instead of using session.execute)? I can't seem to find anything in the
> documentation.
>
>
> Thanks again,
>
>
>
>
>
>
>
>
> On Wed, May 23, 2018 at 10:26 AM, Michael Jerris <mike at jerris.com> wrote:
>
>> I’d avoid using the bridge function like this, but worthwhile to set the
>> variable using the direct method instead of session execute for set
>> application.
>>
>>
>> On May 22, 2018, at 5:01 PM, Branden Jordan <BJordan at E-Teleco.com> wrote:
>>
>> I don’t see any reason why that wouldn’t work but maybe there is
>> something weird going on with the javascript session object where it isn’t
>> getting/setting the exported variables from the session when you are doing
>> the bridge? Have you tried making a new session object and setting your
>> variables for that session object instead of doing a session.execute? I
>> found something like this on the Wiki that you might be able to do, small
>> example below.
>>
>> var anotherSession = new Session(session, '{ignore_
>> early_media=true}user/1003@' + $pbx_domain);
>> anotherSession.execute(‘set’,diversionHeader);
>> bridge(session, anotherSession);
>> anotherSession.hangup();
>>
>> Like I said earlier I am a bit rusty on the Javascript side, (no idea if
>> bridge blocks or if you have to do a loop) but I know that would work on
>> the LUA side which is where I am more familiar. I know Javascript examples
>> are a little light on the wiki but you might be able to get the gist of
>> what is going on in the LUA side and then mimic that in Javascript.
>> https://freeswitch.org/confluence/display/FREESWITCH/Lua+example+
>> Bridging+two+calls+with+retry
>>
>> Thanks,
>>
>> Branden Jordan
>>
>> *From:* FreeSWITCH-users <freeswitch-users-bounces at lists.freeswitch.org> *On
>> Behalf Of *Preston Hagar
>> *Sent:* Monday, May 21, 2018 6:53 PM
>> *To:* FreeSWITCH Users Help <freeswitch-users at lists.freeswitch.org>
>> *Subject:* Re: [Freeswitch-users] Adding SIP Headers in Javascript
>>
>> Thanks for responding!
>>
>> Below is a bit more code to fill in the gaps. I'm passing the
>> destination_number from the XML as a third argument. When I test out the
>> code below, the console_log does in fact print out a "correct" Diversion
>> header line. If I use the exact same Diversion header, set in my XML
>> dialplan, it shows up in the SIP packet and the VOP software reads it.
>> When I set it using session.execute in javascript, then no Diversion
>> header, even an incorrect one, gets added to the SIP packet.
>>
>> I don't think it is in the variable substitution or anything like that.
>> I've also tried not passing a variable to session.execute and just putting
>> the string in the command, as well as just hard coding a test number. In
>> all cases, no Diversion header ever shows up. Either I'm not setting it
>> right for javascript or there is something different about setting it in
>> Javascript vs XML that I haven't figured out.
>>
>> Here is more expanded code:
>>
>>
>> var $extension = argv[0];
>> var $pbx_domain = argv[1];
>> var $destination_number = argv[2];
>>
>> var diversionHeader = 'sip_h_Diversion=<sip:' + $destination_number + '@
>> pbx.example.org>;privacy=off;reason=unconditional;counter=1;screen=no';
>>
>> session.execute('set',diversionHeader);
>> session.execute('export','sip_h_Diversion');
>>
>> onsole_log("notice","Trying receptionist");
>> console_log("notice",session.state);
>> console_log("notice",diversionHeader);
>> session.execute('set', 'call_timeout=15');
>>
>> var logic = '{ignore_early_media=true}user/1003@' + $pbx_domain;
>> session.execute('bridge', logic);
>>
>> console_log("notice","Trying Kim");
>> console_log("notice",session.state);
>> session.execute('set', 'call_timeout=10');
>> session.execute('bridge', 'user/2741@' + $pbx_domain);
>>
>> // No one answered, send to IVR
>>
>> console_log("notice","No one is answering");
>> console_log("notice",session.state);
>> if (session.state == "CS_EXECUTE")
>> {
>> console_log("notice","Trying IVR");
>> session.execute('transfer', 'ivr');
>> }
>>
>>
>>
>> On Mon, May 21, 2018 at 6:57 PM, Branden Jordan <BJordan at e-teleco.com>
>> wrote:
>>
>> Not sure if you still need help with this but could you post some more of
>> your javascript code? Something about this line is off to me but maybe it
>> makes sense in the grander scheme of things.
>> var diversionHeader = 'sip_h_Diversion=<sip:' + $destination_number
>> + '@pbx.example.org>;privacy=off;reason=unconditional;counter=
>> 1;screen=no';
>>
>> I have not used javascript with freeswitch in a little while, so I might
>> be totally wrong but did you declare $destination_number? Because its
>> possible its undefined if you didn’t declare that specifically equal to the
>> value you passed in via args and thus javascript does you a solid and makes
>> the whole string undefined which sets the sip_h_Diversion to null which is
>> why it isn’t exporting. Maybe try argv[3] or argv[2] (console them out I am
>> not sure which one it’ll be) instead of $destination_number in your
>> concatenation?
>>
>> If that isn’t it and you are still having an issue we can try some other
>> stuff.
>>
>> Thanks,
>> Branden Jordan
>>
>>
>> *From:* FreeSWITCH-users <freeswitch-users-bounces at lists.freeswitch.org> *On
>> Behalf Of *Preston Hagar
>> *Sent:* Friday, May 18, 2018 8:55 AM
>> *To:* FreeSWITCH Users Help <freeswitch-users at lists.freeswitch.org>
>> *Subject:* [Freeswitch-users] Adding SIP Headers in Javascript
>>
>> Quick Version: Is there some special way to set custom SIP headers when
>> you are bridging a call from Javascript instead of XML?
>>
>> Full Details:
>> We am using Voice Operator Panel (VOP) as a receptionist console. We
>> have multiple external numbers that all funnel into a few receptionist
>> desks. If I add a SIP Diversion header, then VOP will use that to show the
>> receptionist which number the caller dialed to reach them, which would help
>> things out a lot.
>>
>> If I add it in an XML dialplan and then do a direct bridge to one of the
>> receptionist numbers, it works great (snip of working direct dialplan):
>>
>> <action application="set" data="sip_h_Diversion=<sip:${d
>> estination_number}@pbx.example.org>;privacy=off;reason=
>> unconditional;counter=1;screen=no"/>
>> <action application="bridge" data="user/1000 at pbx.example.org"/>
>>
>> The problem is I need a bit of advanced logic to figure out which
>> receptionist are online and then ring those, then fail over to other
>> numbers and ultimately IVR if no one answers, so I instead pass calls to
>> them off to javascript, so the bridge line above becomes something link:
>>
>> <action application="javascript" data="${jslib}/frontdesk.js
>> ${dialed_extension} ${domain_name} ${destination_number}" />
>>
>> I've tried setting the SIP header in the XML above the javascript line
>> and then exporting it
>> <action application="set" data="sip_h_Diversion=<sip:${d
>> estination_number}@pbx.example.org>;privacy=off;reason=
>> unconditional;counter=1;screen=no"/>
>>
>> <action application="export" data="sip_h_Diversion" />
>>
>> and setting it in the Javascript:
>>
>> var diversionHeader = 'sip_h_Diversion=<sip:' + $destination_number
>> + '@pbx.example.org>;privacy=off;reason=unconditional;counter=
>> 1;screen=no';
>>
>> session.execute('set',diversionHeader);
>> session.execute('export','sip_h_Diversion');
>>
>> but in both cases (or with both in place), the SIP header is never
>> written.
>>
>> Is there some magic to setting SIP headers in Javascript? I can't seem
>> to find any examples or documentation about it.
>>
>> Thanks!
>>
>>
>>
> _________________________________________________________________________
> Professional FreeSWITCH Consulting Services:
> consulting at freeswitch.org
> http://www.freeswitchsolutions.com
>
> Official FreeSWITCH Sites
> http://www.freeswitch.org
> http://confluence.freeswitch.org
> http://www.cluecon.com
>
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20180523/e1908997/attachment-0001.html>
More information about the FreeSWITCH-users
mailing list