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@lists.freeswitch.org> wrote:



---------- Forwarded message ----------
From: Wilmar Perez <ewdpb@yahoo.com>
To: "freeswitch-users@lists.freeswitch.org" <freeswitch-users@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); 



-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------  

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@lists.freeswitch.org>
To: "freeswitch-users@lists.freeswitch.org" <freeswitch-users@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@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@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