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 testing with the following script which simply executes another external script which, in turn, 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:
My_curl.lua:
In the logs I can see something happening:
But nothing else happens. My main script simply goes through the for loop 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 guide would be very helpful.
Thanks!
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 testing with the following script which simply executes another external script which, in turn, 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:
Code:
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
freeswitch.consoleLog('Notice','The data is' .. session:getVariable('curl_response_data'))
end
i = i + 1;
end
session:hangup();
My_curl.lua:
Code:
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 loop 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 guide would be very helpful.
Thanks!
Last edited: