I have an asterisk which is originating various calls.
Which is the most elegant way to send and email (or more generally trigger an event) when it fails to call a certain amount of time in a row?
For instance: When more than 20 calls fail because of insufficient credit, send an email.
My solution: Schedule using crontab a scripts that grep log files (cdr-csv) and do the requested operation.
Most elegant/lower cpu usage is use AMI event listener and trigger UserEvent with request of email.
To trigger UserEvent you can use h extension
exten => _X.,1,Dial(SIP/trunk/${EXTEN},,o)
exten => h,1,ExecIF($[ ${DIALSTATUS} != "ANSWERED" ]?UserEvent(TrunkFailed,Status: ${DIALSTATUS})
Related
I have realtimequeue. After restarting asterisk do not sees queue members. When execute on cli this command “queue pause member SIP/111” get this error.
Unable to pause interface 'SIP/111’
Command ‘queue pause member SIP/111’ failed.
But after execute this command “queue show” Asterisk sees all queue members.
Note: I use realtime config.
[settings]
queues => odbc,asteriskdb,queue_table
queue_members => odbc,asteriskdb,queue_member_table
queue_log => odbc,asteriskdb,queue_log
That is normal behavour for realtime queues.
However they still can work and queue will be fetched on first request. It designed so to support thousands of "lazy" queues.
If you want it always be in memory, use realtime config store method.
Using Asterisk 11, with an inbound route configured to call Queue app, every time the caller hangs up the HANGUPCAUSE variable is 0, it works and returns the NORMAL_CLEARING code only when the assigned queue member hangs up or if not using queues. Example code:
[from-trunk]
exten => s,1,Answer()
same => n,Queue(queue-1,rkt,,,30)
exten => h,1,Verbose(Hangup cause is ${HANGUPCAUSE})
How to obtain a valid HANGUPCAUSE from calls answered with queues?
Asterisk HANGUP_CAUSE will show you only value of last Dial command and only for SOME channel types.
Queue generate 100500 of NEW calls and bridge it together to make functionality you want.
You can check cause in queue's branches(in each one can be DIFFERENT), using agents in Local/ channels.
You can use Queue app variables:
This application sets the following channel variables upon completion:
${QUEUESTATUS}: The status of the call as a text string.
TIMEOUT
FULL
JOINEMPTY
LEAVEEMPTY
JOINUNAVAIL
LEAVEUNAVAIL
CONTINUE
${ABANDONED}: If the call was not answered by an agent this variable will be
TRUE.
You also can use queue_log or CDRs.
Here is my scenario i want to achieve, I have do outbound call to a number, after conversation i need to transfer the call to play a message for callee. After the message end, the call will route back to caller continue conversation.
How am i going to achieve this. using method MeetMe? or others?
Dialplan should be something like this:
[default]
exten => _10XX,1,Dial(SIP/${EXTEN})
After the conversation if the user transfer the call to "Music" extensions: (from sip client i guess):
[Music]
exten => _X.,n,Playback(your_play_file)
exten => _X.,n,Dial(SIP/${EXTEN})
better if you can manipulate using AGI to get/set the user was talking to the caller.
alternate:
you can use Call Parking for this.
I want to pickup call in Asterisk using AMI. I can originate call, but totally don't know, how to answer the phone...
Script for calling:
#login
sock = socket.socket(af, socktype, proto)
sock.connect(sockaddr)
sock.send('Action: login\r\n')
sock.send('Events: off\r\n')
sock.send('Username: '+str(ast_server.login)+'\r\n')
sock.send('Secret: '+str(ast_server.password)+'\r\n\r\n')
#originate call
sock.send('Action: originate\r\n')
sock.send('Channel: ' + str(user.asterisk_chan_type) + '/' + str(user.internal_number)+'\r\n')
sock.send('Timeout: '+str(ast_server.wait_time*1000)+'\r\n')
sock.send('CallerId: '+str(user.callerid)+'\r\n')
sock.send('Exten: '+str(ast_number)+'\r\n')
sock.send('Context: '+str(ast_server.context)+'\r\n')
if ast_server.alert_info and user.asterisk_chan_type == 'SIP':
sock.send('Variable: SIPAddHeader=Alert-Info: '+str(ast_server.alert_info)+'\r\n')
sock.send('Priority: '+str(ast_server.extension_priority)+'\r\n\r\n')
#logout
sock.send('Action: Logoff\r\n\r\n')
time.sleep(1)
sock.close()
I need something similar, but for answering calls.
Can't find any useful command in *CLI> manager show command
Halp me, plox
You can't answer a call directly via AMI. This is because a new call will "arrive" at the given context/priority/extension configured in the dialplan (or it will be rejected if cant find one that applies). So whatever happens with that call will start at the given context/priority/extension in the dialplan.
If you want to handle calls via AMI, try using asynchronous AGI, like this:
exten => _X.,1,AGI(agi:async)
This will handle all calls to any extension that has at least 1 digit, by issuing an event (AsyncAGI) that you can handle with your AMI client.
Then, from your AMI client, you can send AGIAction's, like:
Action: AGI
Channel: SIP/adevice
Command: ANSWER
CommandID: MyCommandID
This will effectively allow you to run AGI commands (and handle a call like you would normally do in any AGI script) from your AMI client.
Hope it helps!
I have started to read about Asterisk::AMI module.
In that module if we want to send the action to the AMI server,we need to use the Action with action name using send_action method.
In that module they mentioned about Action => 'Ping' within send_action method.
Here what is the use of Action => 'Ping'.Can anyone explain me about it.
send_action({ Action => 'Ping',
CALLBACK => \&method,
});
Thanks in advance.
The Asterisk Manager Interface (AMI) allows a client program to connect to an Asterisk instance and issue commands or read events over a TCP/IP stream
Action: A packet sent by the connected client to Asterisk, requesting a particular Action be performed. There are a finite (but extendable) set of actions available to the client, determined by the modules presently loaded in the Asterisk engine. Only one action may be outstanding at a time
Action => Ping
gives Keep alive packet to be sent from the client to Astersik
Action: Ping
Synopsis: Keepalive command
Privilege: <none>
Description: A 'Ping' action will elicit a 'Pong' response. Used to keep the
manager connection open.
Variables: NONE
You can get basic help for any Asterisk AMI command from within the Asterisk CLI
interface by typing
manager show command yourCommand
You can see an entire list of supported commands by typing
manager show commands
BTW the shell command to get to the Asterisk CLI is
asterisk -r
I think this is a just a keep alive. Asterisk Manager Interface is known for being a little unreliable. Astmanproxy is a good way to fix that.