After recording with mixmonitor, run the AGI script and POST the wav to another server via CURL - asterisk

I want to start an AGI script after transferring a phone call with Asterisk and recording it with mixmonitor, and POST the wav to another server via CURL, but the extensions.conf I created does not work.
exten => 0123456,1,MixMonitor(${UNIQUEID}.wav49)
exten => 0123456,n,Dial(SIP/xxxxxxxx#0123456,60)
exten => h,1,AGI(curl_post.php)
I can start curl_post.php with AGI, but the wav file is not ready yet, and I cannot do CURLPOST. How can I wait for the wav file to be created so I can CURLPOST to another server? Thank you for your help.

MixMonitor has internal option for that
MixMonitor(filename.extension,[options,[command]])
...
command - Will be executed when the recording is over.
Any strings matching ^{X} will be unescaped to X.
All variables will be evaluated at the time MixMonitor is called.
https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Application_MixMonitor
For example, in FreePBX it is like this:
exten => 0123456,1,MixMonitor(${UNIQUEID}.wav49,,/bin/emailrecording.sh ^{CALLFILENAME})
https://community.freepbx.org/t/solved-how-to-email-call-recordings-post-call-recording-script/26747/18

Related

Get return value of the Dial application in Asterisk

I call to a voice browser with the Dial application on SIP channel in Asterisk. The VXI returns a number. How can I get that number as a return value of the Dial application? ${DIALSTATUS} doesn't get the return value. It has last result of Dial application like ANSWER,NOANSWER,... .
exten => _.,n,Set(VXMLFILE=/var/spool/asterisk/tmp/${EXTEN}.vxml)
exten => _.,n,SipAddHeader(voicexml: ${VXMLFILE})
exten => _.,n,Dial(sip/[some parameters])
Voicexml processing is not part of asterisk, it done by your UA.
So you have consult our UA for result.
Can suggest it allow save log on remote syslog server, so you can parse result from log.
Asterisk cannot directly parse the vxml or xml files.
Create an Asterisk AGI script and parse the vxml file and assign the value to the variable "VXMLFILE".
Go through this URL to understand how Asterisk AGI works.
voip-info.org

Call hangup take time - asterisk dialplan

I wrote dialplan for my Asterisk system. The extension.conf is :
extensions.conf
[from-pstn]
exten =>s,1,Verbose(1, Caller ${CALLERID(all)} has entered the paf IVR)
same=>n,Answer()
same=>n,Wait(3)
same=>n,Playback(welcome)
same=>n,GoSub(post,ss,1)
same=>n,Playback(thanks)
same=>n,Hangup()
[post]
include => default_cont
exten => ss,1,Background(gud/post)
same=>n,WaitExten(5)
exten => 1,1,Set(CDR(aa)=136)
same=>n,Return()
exten => 2,1,Set(CDR(aa)=137)
same=>n,Return()
[default_cont]
exten => i,1,Playback(invalid)
same=> n,Hangup()
exten => t,1,Playback(timeout)
same=> n,Hangup()
exten => h,1,DeadAGI(convert_recordings.sh)
same=>n,DeadAGI(my_uploader.php,${var1},${CALLERID(num)},${CDR(var2)},${CDR(aa)})`
When i call to my asterisk system. it takes time to hangup after playing thanks audio file. Actually, call hangup after all AGI execution are completed and my_uploader.php execution takes time. But i need instant hangup after playing thanks message. System only executes AGI files after the call is completely hangup. How can i solve this problem ?
Thats becuase you have h extensions in your dialplan
So it will take time while you agi on h-extension ends.
You can use cdr info and run external script based on that. You can write dialplan on hexten(not agi). You can write faster(not blocking) agi.
Very likly your uploaded or conversion task take time. You have only notate somewhere in db what you have to do and do that in external thread, not in asterisk.
That way you will not block asterisk thread.

Execute dialplan context from command line

I'm trying to execute an extension from the command line (via asterisk -rx "command") on a context that makes a AGI based query to determine which extension needs to be dialed (these extensions are updated on the DB).
It's something like this:
[autodialer]
exten => 2,1,Answer()
exten => 2,n,AGI(database_query.php); Makes a database query and generates vars
exten => 2,n,Set(CALLERID(name)=${db_customer_name}); Sets callerid from DB data
exten => 2,n,Dial(SIP/${db_customer_extension}); Also, extensions are stored on DB
exten => 2,n,Playback(custom/important_message)
exten => 2,n,SayDigits(${important_numbers}); The message, stored on DB too.
exten => h,1,Hangup()
Here, I need that context executed from command line, without having to dial it from any extension (it is supposed to be executed with a crontab every X time).
I tried with originate command, but I think I misunderstood the command syntax and didn't work.
I think that it should be something like: asterisk -rx "channel originate 2#autodialer" and then Asterisk executes that context and we're all happy with our important numbers.
I know that's not the right syntax, just trying to explain how I imagine it could work.
Thanks for your help.
There are no way do originate only one leg. You have supply second argument(other channel dest)
if you not need other channel, create context like this
[wait]
exten =>s,1,Wait(10000)
and use
asterisk -rx "channel originate 2#autodialer s#wait"
Read this article:
http://www.voip-info.org/wiki/view/Asterisk+auto-dial+out
NOTE: it is not recommended do diallout apps for people with less then 5 years dedicated asterisk experience. If you want one, use vicidial.org or other dialler.

Asterisk call transfer on DAHDI channells

All channels on Asterisk configured as DAHDI channels.After customer make payment I want to transfer the customer to the representative who interact customer before.
I try to make it by Dial() command. This is the dialplan
exten => s,1,Set(TRFNUM=${CALLERID(num)})
exten => s,2,Set(TRFNAME=${CALLERID(name)})
exten => s,3,AGI(agi://192.168.7.20/customivr)
exten => s,4,Dial(DAHDI/1/${TRFNUM}&DAHDI/2/${TRFNUM}&DAHDI/3/${TRFNUM}&DAHDI/4/${TRFNUM}&DAHDI/5/${TRFNUM}&DAHDI/6/${TRFNUM}&DAHDI/7/${TRFNUM}&DAHDI/8/${TRFNUM},30)
exten => s,5,Hangup
For example: Call comes to DAHDI/1 after the payment DAHDI/1 dial all channels one them Answer the others Hangup. DAHDI/1 bridge call by with DAHDI/2. However, although Customer and representative close phones, Channels do not Hangup. They stay Busy.
Where do i make mistake. I should hangup call channels or find another way to transfer.
It seems to be configured correctly,
I think your AGI script hangup the call when he finishes his work,
It can happen if you have $agi>hangup in the end,
or if you make any outputs in the scripts (echo, print_r, etc...),
even empty spaces output can cause this behavior,
another thing you can try is make the Dial command from the agi itself using:
agi->exec("Dial","options");

Asterisk auto Call recording

We are running asterisk with 8 port FXO. FXO connects to our old PBX (Samsung Office Serv 100).
Now we want to record all calls routed through FXO (if it was dialed to outside or comming from outside).
Is there a simple way to do this?
Are you running plain Asterisk? If so you can modify your dial plan to start 'monitoring' the channel, which will record the call.
The monitor command's documentation: http://www.voip-info.org/wiki/view/Asterisk+cmd+monitor
Just for the sake of completion, here's the documentation:
[root#localhost ~]# asterisk -rx 'core show application monitor'
-= Info about application 'Monitor' =-
[Synopsis]
Monitor a channel
[Description]
Monitor([file_format[:urlbase],[fname_base],[options]]):
Used to start monitoring a channel. The channel's input and output
voice packets are logged to files until the channel hangs up or
monitoring is stopped by the StopMonitor application.
file_format optional, if not set, defaults to "wav"
fname_base if set, changes the filename used to the one specified.
options:
m - when the recording ends mix the two leg files into one and
delete the two leg files. If the variable MONITOR_EXEC is set, the
application referenced in it will be executed instead of
soxmix and the raw leg files will NOT be deleted automatically.
soxmix or MONITOR_EXEC is handed 3 arguments, the two leg files
and a target mixed file name which is the same as the leg file names
only without the in/out designator.
If MONITOR_EXEC_ARGS is set, the contents will be passed on as
additional arguments to MONITOR_EXEC
Both MONITOR_EXEC and the Mix flag can be set from the
administrator interface
b - Don't begin recording unless a call is bridged to another channel
i - Skip recording of input stream (disables m option)
o - Skip recording of output stream (disables m option)
By default, files are stored to /var/spool/asterisk/monitor/.
Returns -1 if monitor files can't be opened or if the channel is already
monitored, otherwise 0.
And here's a sample way you can use it:
; This fake context records all outgoing calls to /var/spool/asterisk/monitor in wav format.
[fake-outgoing-context]
exten => s,1,Answer()
exten => s,n,Monitor(wav,,b)
exten => s,n,Dial(DAHDI/g0/${EXTEN})
exten => s,n,Hangup()
Obviously you'd have to make changes to my code, but hopefully that gives you a good idea.
A real life example is
exten => _87X,1,NoOp()
exten => _87X,n,MixMonitor(${UNIQUEID}.wav,ab)
exten => _87X,n,Dial(SIP/${EXTEN},45)
exten => _87X,n,StopMixMonitor()
exten => _87X,n,Hangup()
It's good practise to always have NoOp - the first rule must start with 1, this way you can interchange the rules with the n step any way you want.
It's always best to use MixMonitor as opposed to Monitor - Monitor only records inbound or outbound audio - MixMonitor uses both.
Also wav is quite a good choice as a format - I also use a script to transform the wav files to OGG at the end of the day - the best compromise between size / quality and licensing issues.
With regards to the arguments
a is append
b is bridge (good for production - it will only record when the call is answered - not good for debugging)
With regards to StopMixMonitor(), I'm just being thorough, but for examples there are cases in which you would like to stop the recording, for example:
...
exten => _39[5-9],n,Dial(SIP/${EXTEN},45)
exten => _39[5-9],n,GotoIf($["${DIALSTATUS}" = "BUSY"]?busy:unavailable)
exten => _39[5-9],n(busy),NoOp()
exten => _39[5-9],n,StopMixMonitor()
exten => _39[5-9],n,Voicemail(${EXTEN},u)
exten => _39[5-9],n,Hangup()
exten => _39[5-9],n(unavailble),NoOp()
exten => _39[5-9],n,StopMixMonitor()
exten => _39[5-9],n,Hangup()
...
In this example, you would stop the recording of the voice mail interaction.
Hope this will bring some light on the matter.
Depending on the specifications of your Asterisk box you might find this hack useful too. Create a rather large ramdisk and mount /var/spool/asterisk/monitor to it. That way Asterisk records to memory not disk. Then write a script under cron to move the recordings to permanent storage every 15-30 minutes or so.

Resources