I do have an Asterisk 11 PBX and I'm developing an Windows Service application using the github AsterNET.AMI Library to connect my PBX. Till here everything is working fine, I can send commands and read incoming event messages.
But now I need to develop a feature on my software based over one information that I thought it could be easy to retrieve. The information I'm looking for is - who hanged up?
I googled for it a lot and I could find a few answers, most of them talking about setup the G option on CDR but also some considerations about this approach. Still like this I couldn't grab any valuable information for my scenario.
Maybe if I tell you about my working scenario you could help me. Lets go, I'm going to bullet split this:
I do have a caller calling from a cellphone and this calling are incoming to my internal PBX extension
My PSTN trunk is a E1/R2 directly to my PBX
No matter if caller or callee hangs up always I do have "normal clearing" message for hangup_cause
I know I'm receiving from my service provider the information about the releasing device, because if I use my Siemens 3800 Hipath over CSTA I can retrieve this information.
So the gold question is: How can I retrieve who is the releasing device on this situation?
You can try a combination of g and F options in the Dial application. The g option allows dialplan execution when the called party hangs up, while the F option allows you to continue execution to a context,extension,priority of your choice if the caller hangs up.
So, you can understand which party is hanging up by the dialplan being executed after the call ended.
Find here more info on these options: https://www.voip-info.org/asterisk-cmd-dial/
The only way I could find after read Asterisk doc almost entirely was reading HangupRequest event messages.
As I'm using AsterNet.AMI library to connect and manage my Asterisk, so I change the source code a little bit to have an event handler do read HangupRequest event.
HangupRequest event writes the messages like the following one:
Event: HangupRequest
Privilege: call,all
Channel: SIP/8103-000001be
ChannelState: 6
ChannelStateDesc: Up
CallerIDNum: 8103
CallerIDName: Agent 8103
ConnectedLineNum: 51999887766
ConnectedLineName: 51999887766
Language: en
AccountCode:
Context: from-internal
Exten: 8100
Priority: 1
Uniqueid: 1569618521.446
Linkedid: 1569618519.445
So accordly to HangupRequest Event Asterisk documentation I could notice the channel in the message is the channel related to the releasing device, also CallerIDNum and CallerIDName are related to.
This feature is not implemented right now on the github library, but I'm going to push over there and ask them to include on next release.
Yet I don't know where to read this information on FreePBX Admin.
Related
I have a Python service which connects to Asterisk via AMI and listens for events to detect when a call has begun.
This seems to work on most of the Asterisk servers I connect to. However, on a few of our servers we just don't see any of the AMI events (e.g. Newstate) when the call happens, though we do later see the Cdr event once the call has completed.
I've confirmed that this isn't specific to the library we're using to connect to AMI (py-Asterisk), because I see exactly the same thing when I connect manually, e.g.
$ openssl s_client -connect my-asterisk-server:5039
...
Asterisk Call Manager/2.10.3
Action: Login
Username: manager
Secret: ThisIsWhereITypedTheActualPassword
Response: Success
Message: Authentication accepted
Event: FullyBooted
Privilege: system,all
Status: Fully Booted
Action: Events
EventMask: on
Response: Success
Events: on
In the above block, I manually connected to AMI, logged in as the same administrator my Python code is using, and ensured that all events are turned on (though my asterisk config should already be displaying all events I care about by default).
After this point what I see on some of my Asterisk servers is a series of expected events like Newstate, followed by an eventual Cdr event. On other servers, I see only the Cdr event, with nothing proceeding it. This is completely consistened within each server, meaning a server either always sends all of the expected events or it never does.
I've checked the versions of asterisk, the manager.conf config file, the extensions.conf dialplan, the asterisk console in verbose mode (i.e. connecting via asterisk -vvvr to the running process), and just generally comparing my config files to my actually-working Asterisk servers.
I'm stumped as to what could be causing this, or even what to try next. If it matters, here's what my manager.conf looks like:
[general]
tlsenable=yes
tlsbindaddr=10.0.0.123:5039
tlscertfile=/etc/pki/asterisk/ami.crt
tlsprivatekey=/etc/pki/asterisk/ami.key
[admin]
secret=TheActualPasswordIsOnThisLine
read=system,call,log,verbose,command,agent,user,originate,cdr
write=system,call,log,verbose,command,agent,user,originate,cdr
EDIT: After some further digging, it seems that the only events which are showing up are Cdr events, so even things like peer registration events don't show up. I've also confirmed that all of my Asterisk 13.19.0-1 servers are exhibiting this behavior, and the only working servers are running much older versions of Asterisk.
The weird thing is that calls do come through successfully, so the problem is not that I'm missing some necessary module. (Or maybe I am? Is there some "make events show up in AMI" module that I need to ensure is loaded?)
FURTHER EDIT: I was able to turn on CEL events (Channel Event Logging), and those events show up, but this is a different set of events than the standard Newchannel/Newstate/etc I'm looking for. In theory I could rewrite a large portion of my service to use the CEL events, but ideally I'd just turn on the standard Newstate/Newchannel/Hangup events.
It turns out the issue is that I was missing
enabled=yes
in my manager.conf. Hopefully this will be helpful to someone in the future: even if you're able to connect to AMI, log into AMI, receive some events from AMI, and send commands to AMI and get responses back, it might not be enabled, and this will suppress most of the core events like Newchannel, Newstate, etc.
One clue was that running manager show settings in the asterisk console returned this:
Global Settings:
----------------
Manager (AMI) No
...
which is apparently how it indicates that it's not enabled.
I use Asterisk 16.5 and sip trunk.
If known sip channel can i find uniqueid of call?
Note: I want do it with Asterisk AMI actions and events.
Action: Command
Command: core show channels concise
give you a list of :
Channel:Context:Exten:Priority:Stats:Application:Data:CallerID:Accountcode:Amaflags:Duration:Bridged
You have to pick the correct channel with the "Channel" field and make a
Action: Command
Command: core show channel YOUR_CHANNEL
If you expect do events, correct way is use event. I.e collect NewChannel events and build map(for example, in memcached).
https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+ManagerEvent_Newchannel
Running too many commands sometimes result problem with ami connection.
As an example of such code you can check FOP opensource or FOP2 project(no source now). https://www.fop2.com/about.php
I logged in using agc (agent) panel in vicidial and just to test manual dial, I just executed following MySql query fron cmd.
UPDATE vicidial_live_agents set external_dial='12122351880!!YES!NO!YES!!1478530720!!!!!!' where user='1001';
After this , i got a a call on my softphone (already configured).
I am unable to understand one thing, How can an explicit entry to the vicidial_live_agents table of mysql, make a call ?
You shouldn't be messing with the database for calls.
If you configured everything correctly, you should recieve a call as soon as you log-in which will send you to a conference, you should hear a voice confirming it (you are the only one in this conference), all future calls will be connected to that conference, you should keep that call at all times and not control anything in the softphone.
If you need to make a manual calls you can either set the "Manual Dial Override" option in the campaign to "ALLOW ALL", which will enable a link in the agent screen labeled "Manual Dial" or you can use the agent_api with the external_dial function.
What you have found is the raw method that the Agent API uses to implement a manual dial call. For more information on how the Agent API works, and for all of the options you can use with the "external_dial" function, take a look at the Agent API documentation:
http://vicidial.org/docs/AGENT_API.txt
I am developing a custom application to control an Asterisk based pbx using ami/agi interface. What I have to do is:
receive a call from a pstn external line
answer the call
play a welcome message
transfer the call to a specific extension
park the call
reconnect to the call from a different extension
Everything should be done using ami/agi interfaces. I succesfully developed everything up to point 5) but I am unable to understand how to transfer (using ami/agi) the parked call to a runtime-defined extension.
Can someone give me an idea on how to do it ?
you should originate from Local/XXX#parked_context to the extension you want.
something like this..
Action: Originate Channel: Local/XXX#parked_context (XXX is the number of parked call)
Context: default (here you put the context where you can reach the second party)
Exten: 123 (number who will receive the call)
Priority: 1
Callerid: 3125551212
Timeout: 30000
Variable:
ActionID:
Simplest way is just use async agi or conference or Wait extension instead of parking, i.e redo parking-like logic yourself.
That way you will 100% know channel name and how to transfer it back.
Considering you are gooing use ami - AsyncAGI is best option for you.
I'm trying to find answer how to make Asterisk execute some command (my script) after confbridge's recording is finished
There is the next info in confbridge.conf:
record_conference=yes
Records the conference call starting when the first user enters the
room, and ending when the last user exits the room.
It records file well but I want it sending wav file via email.
Could anybody help me?
My config now looks like this (if it's necessary):
exten => 333,1,ConfBridge(100010,100010_bridge_profile,100010_user_profile)
Dialplan scripting is limited to events relating to each call channel. To get event info for other parts of asterisk (such as the ConfBridge application) you should hook into the Asterisk Manager Interface (AMI).
There are many libraries already created to make working with the AMI easier. (That site may be outdated. Refer to the official Asterisk Wiki whenever possible.)
The AMI event you're interested in is "ConfBridgeEnd". Docs here.
You can use h-extension after confbridge, in which you have check if confbridge still active(last user).
If yes, run your script via System call.