Two things:
1) You aren't grabbing the arg, but the channel variable.. try this in your script:
caller_id_number = argv[1]
number_to_call = argv[2]

2) I don't think you're managing your hangup/callback originate properly.
I don't think you want to use bgapi... or maybe you just need a destination. It's "originate sofia/A endpoint" -- you need to specify where it goes to, the lua script can't "receive" the call. You can have it received by e.g: &lua(pickup.lua)

api = freeswitch.API()
api:execute("originate", DialString.." &lua(pickup.lua)");

Also:
Maybe you want to use it as a hangup hook. Instead of:
<action application="lua" data="callback.lua ${effective_caller_id_number} ${destination_number}"/>
Do:
<action application="set" data="api_hangup_hook=lua callback.lua ${effective_caller_id_number} ${destination_number}"/>
<action application="hangup" data="486"/>

-Avi 

On Wed, Jan 7, 2015 at 1:52 AM, Sina Owolabi <notify.sina@gmail.com> wrote:
Hi List,

FreeSWITCH newbie here again.
I am trying to cobble togther a lua callback script, my first attempt
was successful, but I am trying to make it slightly more elegant.
I don't see any errors when I try to run this but the callback isnt happening.
This is my very second attempt trying to write in lua, so I would be
very grateful for any help.

The user is expected to dial in, have the call hangup and FreeSWITCH call back.

I'm passing a modified $effective_caller_id_number and
$destination_number to the lua script:

<extension name="callyouback">
    <condition field="${caller_id_number}"
expression="^1(\d{10})$"require-nested="false">
       <action application="set" data="effective_caller_id_number=+234${1}"/>
       <action application="set" data="effective_caller_id_name=+234${1}"/>
    </condition>
    <condition field="destination_number" expression="^012345(6)(7)$">
      <action application="set" data="destination_number=+12312345${1}${2}" />
      <action application="lua" data="callback.lua
${effective_caller_id_number} ${destination_number}"/>
      <action application="gentones" data="%(3000,0,430,450,550)"/>
      <action application="hangup" data="NORMAL_CLEARING"/>
     </condition>


The script itself:

api = freeswitch.API();
call_string = "bagpi originate
{origination_caller_id_name="..caller_id_name..",origination_caller_id_number="..caller_id_number.."}sofia/gateway/mysipgate/"..number_to_call..""

freeswitch.msleep(5000);
if (session:ready()) then
        caller_id_number = session:getVariable("destination_number");
        caller_id_name = session:getVariable("destination_number");
        number_to_call = session:getVariable("effective_caller_id_number");

        api:executeString(call_string);
        freeswitch.msleep(2000);
        session:streamFile("/tmp/get_off_my_lawn.wav");
        session:hangup("NORMAL_CLEARING");
end

_________________________________________________________________________
Professional FreeSWITCH Consulting Services:
consulting@freeswitch.org
http://www.freeswitchsolutions.com

Official FreeSWITCH Sites
http://www.freeswitch.org
http://confluence.freeswitch.org
http://www.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
http://www.freeswitch.org