Using bgapi

Wilmar Perez ewdpb at yahoo.com
Wed Mar 18 12:31:57 UTC 2020


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!
 |

 |

 |



----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  
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!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20200318/9f41e45a/attachment.html>


More information about the FreeSWITCH-users mailing list