Create new channel in asterisk dialplan - asterisk

This operation that I need to implement on Asterisk is similar to a call forwarding, but with some differences. This is a simplified explanation of the system.
There are three extensions: 100, 200 and 300. Calls between 100 and 200 are cheap, and calls from any extension to 300 are expensive. And extension 300 is programmed on the remote device to receive and accept calls only from extension 200.
Extension 200 program a "call forwarding" to extension 300 (it adds to a database).
When extension 100 calls extension 200, extension 200 should call extension 300 and transfer the call to extension 100.
The call forwarding examples I found suggest to use Dial() from the extension 100.
[context]
exten => s,1,Set(CFIM=${DB(CFIM/${ARG1})})
exten => s,n,GotoIf($["${CFIM}"!=""]?s-CFIM,1:s-NoCFIM,1)
exten => s,n,Hangup
exten => s-CFIM,1,Dial(Local/${CFIM},30,Ttr)
exten => s-CFIM,n,Hangup
exten => s-NoCFIM,1,Dial(${ARG1},30,Ttr)
exten => s-NoCFIM,n,Hangup
The problem with this approach is that the call to 300 is actually being made by extension 100 (the current channel). This will generate expensive billing for 100 and extension 300 will receive a call from 100, which it will drop.
What I need to do is create a new channel on behalf of extension 200, dial to 300 and then transfer that call to the current channel, so that extension 300 receives call from 200 and there are two billing generated: one from 100 to 200 and another from 200 to 300.
I tried using the Originate() app, but that doesn't work for me because it blocks until 200 picks up (which it will not do).
Any ideas on what I could do to solve this?

Use Local channels for that.
See freepbx.org system followme module for how realize followme with Local channel.
https://www.voip-info.org/wiki/view/Asterisk+local+channels

Related

Asterisk: How to implement outbound rate limiting (calls per second)

My VoIP provider has limited cps. When my Asterisk exceed the threshold, provider sends SIP 503 response and call goes through spare provider. How to make a call to wait for a while and then proceed? I guess there is should be some "locks counter". So a scheduler check this counter, pauses and awakes a call process. What is the preferable mechanism to do that?
It seems a kind of AGI script that has as a parameter CallerID, which accesses the server. If the counter is exceeded, then the server pauses the call process through the ARI mechanism.
Any hints, ideas are appreciated
Example:
[globals]
calls_per_sec=20
[OUTBOUND]
exten => _X.,1,NoOp(Rate Limited Calling)
same => n,Set(GROUP()=${EPOCH})
same => n,GotoIf($[${GROUP_COUNT(${EPOCH})}>${calls_per_sec}]?DELAY,${EXTEN},1)
same => n,Dial(SIP/provider/${EXTEN})
[DELAY]
exten => _X.,1,NoOp(Half Second Delay)
same => n,Wait(0.5)
same => n,Goto(OUTBOUND,${EXTEN},1)
Taken from Asterisk Community Board
There are no any realible way do that for asterisk.
You can count in AGI script, external app or check GROUP_COUNT(${EPOCH}#control).
You can limit CPS naturally in kamailio using ratelimit module.

Asterisk ringback tone recording

I made an outbound-call service application using Asterisk AMI interface.
Following is how my application works.
I generate an Originate request to internal channel using TCP/IP socket.
my dialplan accepts the request and run dial command. extension.conf file is
[from-internal]
exten => _X.,1,NoOP()
same => n,MixMonitor(${DialMonitorFile}.wav)
same => n,Dial(PJSIP/${EXTEN}#TRUNK_100-1234-5678,30)
What I want to do is record whole call process (from ringback tone sound until user hangup).
But, when dial started, only 44 byte size file is generated (maybe wav file header?) before user accepts the call. And, file increased after user accepts call.
Can someone help me how can I record ringback tone sound as well ?
Regards,
Brian
You should do Answer before MixMonitor if you want that
Please note, CDRs will be affected

Asterisk call transfer to queue

I have two sip extensions: 200 and 300 and a queue, let's call it my_queue.
Extension 200 is talking to extension 300 and decides to transfer extension 300 to my_queue.
So extension 200 puts extension 300 on hold and dials the queue number in the dialplan that eventually will call
...
same => n,answer()
same => n,queue(my_queue,,,,${TIMEOUT},,,)
...
Now, at this point extension 200 is listening to the queue's MOH and 300 is listening to the call in progress (as expected).
When 200 hangs up (and uses the IP phone transfer), the extension 300 is indeed transferred to the queue, and if any extension in the queue answers, it is correctly connected to the extension 300.
The problem is that while extension 300 is waiting for some extension in the queue to pick up it is completely silent. It does not hear a call progress nor the queue's MOH.
Is there a way to make extension 300 hear the queue's MOH while it is waiting in the queue?
Try transfer to announcement, which after end go to queue. And hangup before announcemnt ends.
Or add ivr breakout menu to queue(will be silence till IVR, after that moh).

Asterisk - playing music whilst originating a call

I'm using a cloud-based Asterisk server as my PBX. At my current location, the Internet is rather shaky, but cell phones are reliable and commonplace. However, international cell calls are expensive, VOIP calls are much cheaper.
So, I came up with a script in Asterisk which dials my local cell phone:
exten => _abcd.,1,NoOp(-- Making outbound call to number ${EXTEN:4} --)
same => n,Answer()
same => n,Wait(1)
same => n,Originate(SIP/+86[my_cell_no]#[voip_provider],exten,incoming_remote,##${EXTEN:4})
same => n,Hangup()
Let's say I want to call a UK mobile number, +4477something. I would use my softphone to dial abcd+4477something. The script above runs, makes a call into my local cell phone. As soon as I answer, it jumps into another extension _##. which dials the outbound number, and connects the two together.
It works perfectly. However, whilst I'm waiting for the local cell to connect, I've got silence on the line. I'd quite like to play music... but I can't use the MusicOnHold() application, because it just sits there & does nothing until I hang up!
I can't add any "DIAL" style commands (i.e. "m") to the Originate command because it doesn't support them.
Is there any known way of playing (one of) the MusicOnHold channels asynchronously whilst the rest of my dialplan gets on with it?
Would the AGI command SET MUSIC do what I wanted?
e.g.
exten => _abcd.,1,NoOp(-- Making outbound call to number ${EXTEN:4} --)
same => n,AGI(turn_music_on.sh)
same => n,Answer()
.....etc.
I'm using Asterisk 1.8, if a newer version fixes/changes the MusicOnHold behaviour, then that will be the accepted answer (but the documentation seems to suggest it's the same).
You can call to Local channel(dialplan). After that in dialplan you can use m of dial command.
https://www.voip-info.org/wiki/view/Asterisk+local+channels
same => n,Originate(Local/[my_cell_no]#out/n,exten,incoming_remote,##${EXTEN:4})
[out]
exten => _X.,1,Dial(SIP/+86${EXTEN}#[voip_provider],,m)

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