Using bgapi

Wilmar Perez ewdpb at
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();

   reply = api:executeString('bgapi \'my_curl.lua\'');

for i=1, 30 do
  if(session:getVariable('curl_response_code') == nil)then
   freeswitch.consoleLog('Notice', 'Nothing to see yet')
   session:execute('sleep', 500)
  console_log('The data is' .. session:getVariable('curl_response_data'))
  i = i + 1;

My_curl.lua:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  local url = ''
session:execute('curl', url); 

|  | 
ADSCHEAPER.COM - Best online advertising, Monetize domains & intellectua... - 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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the FreeSWITCH-users mailing list