[Freeswitch-users] Using bgapi

Giovanni Maruzzelli gmaruzz at gmail.com
Fri Mar 20 09:35:55 UTC 2020


I have not read the script, etc, only first lines of your mail

I'd like to point you that you can use "luarun" that will execute script in
nits own thread, no blocking, no waitin for result. Is probably what you
want...

-giovanni


On Thu, Mar 19, 2020 at 11:30 PM Wilmar Perez via FreeSWITCH-users <
freeswitch-users at lists.freeswitch.org> wrote:

>
>
>
> ---------- Forwarded message ----------
> From: Wilmar Perez <ewdpb at yahoo.com>
> To: "freeswitch-users at lists.freeswitch.org" <
> freeswitch-users at lists.freeswitch.org>
> Cc:
> Bcc:
> Date: Wed, 18 Mar 2020 12:31:57 +0000 (UTC)
> Subject: Using bgapi
>
> Hi all,
>
> I am trying to wrap my head around the use of bgapi.  What I am tryin
> gto is to call a lua script that executes a curl command. While curl does
> its thing I want to do something else (e.g. playing back some music on hold
> to the caller).  I am trying to do this in pure LUA (no ESL - the only
> reason is that I did not know ESL existed at all when I started this
> project and now it is too late to go back).
>
> So, I've been texting with the following scrip which simply executes an
> external script which is using mod curl.  I woud expect some session
> variables to be set but it does not seem to be the case. I use a for loop
> just to check every few seconds the existence of the session variable.
>
> *My main script*:
>
> -----------------------------------------------------------------------------------------------------------------------
>
> -----------------------------------------------------------------------------------------------------------------------
> session:answer();
> api = freeswitch.API();
>
> if(session:ready())then
>    reply = api:executeString('bgapi \'my_curl.lua\'');
> end
>
> for i=1, 30 do
>   if(session:getVariable('curl_response_code') == nil)then
>    freeswitch.consoleLog('Notice', 'Nothing to see yet')
>    session:execute('sleep', 500)
>    else
>   console_log('The data is' .. session:getVariable('curl_response_data'))
>   end
>   i = i + 1;
> end
>
> session:hangup();
>
> -----------------------------------------------------------------------------------------------------------------------
>
> -----------------------------------------------------------------------------------------------------------------------
>
> *My_curl.lua*:
>
> -----------------------------------------------------------------------------------------------------------------------
>
> -----------------------------------------------------------------------------------------------------------------------
> local url = 'http://myapi.com'
> session:execute('curl', url);
>
> ADSCHEAPER.COM - Best online advertising, Monetize domains & intellectua...
>
> AdsCheaper.com - cost effective advertising Monetize domains!
> <http://myapi.com/>
>
>
>
> -----------------------------------------------------------------------------------------------------------------------
>
> -----------------------------------------------------------------------------------------------------------------------
>
> In the logs I can see something happening:
>
> +OK Job-UUID: fbb932aa-d58b-4e9f-b658-c542eff0640d
>
> But nothing else happens. My main script simply goes through the for look
> until the end and session variable  curl_response_code never gets set.
>
> Clearly I am probably misunderstanding how this whole thing works.  Any
> hint or guid would be very helpful.
>
> Thanks!
>
>
>
>
>
> ---------- Forwarded message ----------
> From: Wilmar Perez via FreeSWITCH-users <
> freeswitch-users at lists.freeswitch.org>
> To: "freeswitch-users at lists.freeswitch.org" <
> freeswitch-users at lists.freeswitch.org>
> Cc:
> Bcc:
> Date: Thu, 19 Mar 2020 15:30:29 -0700 (PDT)
> Subject: [Freeswitch-users] Using bgapi
> _________________________________________________________________________
>
> The FreeSWITCH project is sponsored by SignalWire https://signalwire.com
> Enhance your FreeSWITCH install with disruptive priced SMS and PSTN
> services.
> Build your next product on our scalable cloud platform.
>
> Join our online community to chat in real time
> https://signalwire.community
>
> Professional FreeSWITCH Services
> sales at freeswitch.com
> https://freeswitch.com
>
> Official FreeSWITCH Sites
> https://freeswitch.com/oss
> https://freeswitch.org/confluence
> https://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
> https://freeswitch.com



-- 
Sincerely,

Giovanni Maruzzelli
OpenTelecom.IT
cell: +39 347 266 56 18
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20200320/d87cc3c0/attachment-0001.html>


More information about the FreeSWITCH-users mailing list