How to map call to caller?

Hi All,

I am initiating calls from a windows program using the Asterisk Management API . First a socket connection is established and after that the program uses “Action: Originate” and a bunch of other instruction/parameters to trigger a call.
First the phone on the user’s desk rings, once picked up, it calls the destination. This works fine.

What i like to work out is how to map the actual call to the entry in the MySQL DB of asterisk?
I can see a number of fields/columns in the DB those relate to a call, but I would like to save an ID or somesort of identifier that is more unique to the caller’s extension and the dialled number.

Is there away to get the uniqueId of the call through the AMI? Or what else isavaileble?



manager show command Getvar

Thanks for the reply.
Would you be kind to explain the process and what is required in a little more detail?
Can it be sent right after the call initiated?

Also what is the format? Could I have an example please?

I am originating the call by sending the following lines:

Action: Originate
ActionID: 69
Channel: local/211@from-internal
Context: from-internal
Exten: 0412868320
CallerID: inCommand Call
Priority: 1
Async: yes

What should the GetVar looklike?



You didn’t say you didn’t know the channel. If you don’t know the channel, you will need to look for the newchan event, which will probably contain the uniqueid.

Using Getvar should be obvious from its synopsis and the AMI documentation.

You can also set variables, which could include your own unique ID, using Originate, itself.

Thanks again, but I am new to the concept. The only thing I can do is originate calls.

Using GetVar maybe obvious to some but it certainly isn;t to me. Further more, I am finding it difficult to get through the initial barrier as the documentation seems to be rather slim for the newcomer, I can see a lot of stuff on Asterisk but most appear to assume a good conceptual understanding of how calls are managed.

This is what I haven’t got and i can’t seem to find docs on how to originate a call from a program so I can easily determine the uniqueid of the record associated with the particular call.

From the docs I found so-far, I can’t even work out how to use getvar.

Asterisk is self documenting.

At the CLI, “manager show commands” will tell you all the possible AMI actions, "manager show command " will give details for a particular command. The easiest way of working out what events are possible is to run the system and log the events.

There is a lot of documentation at

Don’t assume that just because you want to do something, that it is commonly done or that Asterisk makes it easy.

What might be best for you is to set an identifier as a variable, on the Originate, then set that variable to itself in the dialplan. That will give you a newstate event that should uniquely identify the ;2 side of the local channel.

Sorry David55 but you are missing my point. I have found the list of commands. I have found a wholelot of docs,, I read through what I thought may be relevant, but found nothing that gives me the conceptual understanding needed to do the call and map the call to the record.

I can see the command syntax, that is fine. BUT what is what? What should go where?

This what I get back:
Response: Success
ActionID: 79
Message: Originate successfully queued

Response: Success
Variable: uniqueid
Value: (null)
ActionID: 79

What am I doing wrong?



It is UNIQUEID. I don’t know which channel you used, but I guess it would have produced a different error if the channel name was wrong.

Note that UNIQUEID isn’t, strictly speaking a variable, it actually accesses a field in a data structure. However, I’m fairly sure that it is treated as a variable by Getvar.

On the other hand, it is included in the Newchannel event, and the safest way of tieing the channel to the AMI is to do something recognizable in the dialplan. As well as the tactics already mentioned, you can use UserEvent.