gateway dialplan is:
<extension name="mytelco">
<condition field="destination_number" expression="^987(\d+)$">
<action application="set" data="effective_caller_id_number=46xxxxxxxx"/>
<param name="caller-id-in-from" value="true"/>
<action application="set" data="record_link=${strftime(%Y-%m-%d-%H-%M-%S)}_${destination_number}_${caller_id_number}.wav"/>
<action application="record_session" data="/var/www/html/freeswitch/recordings/${record_link}"/>
<action application="lua" data="/etc/freeswitch/scripts/beep_detection-from-call-v0.1.2.lua $1 ${record_link}"/>
<action application="hangup"/>
</condition>
</extension>
file beep_detection-from-call-v0.1.2.lua
#!/usr/local/bin/lua
DNID = argv[1]
if session:ready() then
session:sleep(1000)
session:execute("avmd_start", "inbound_channel=1,outbound_channel=0,sample_n_continuous_streak=10,sample_n_to_skip=0,debug=1,report_status=1")
session:execute("bridge", "{execute_on_answer=lua /etc/freeswitch/scripts/on_answer-v0.3.lua " .. uuid .. "}sofia/gateway/mytelco/" .. DNID)
session:execute("avmd_stop","")
end --if
file on_answer-v0.3.lua
#!/usr/bin/lua
uuid_original = argv[1]
api = freeswitch.API()
reply = api:executeString("bgapi uuid_broadcast " .. uuid_original .. " /usr/share/asterisk/sounds/en/dennis-ivan.gsm both")
freeswitch.consoleLog("INFO","==============================================")
freeswitch.consoleLog("INFO","API reply is:" .. reply)
freeswitch.consoleLog("INFO","==============================================")
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}