L
L
LayneBuchyn2012-01-30 13:02:19
Asterisk
LayneBuchyn, 2012-01-30 13:02:19

How to get dial status from Asterisk in real time?

Good day.
I'm writing an application integrated with Asterisk, but haven't had time yet to get a good grasp of the Asterisk API.
I would like to be able to catch dialer status (ANSWERED, BUSY etc.) in real time, during a call.
Can anyone point me in the right direction? I would be grateful for any information.
Calls are made from the application by calling Action Originate over a TCP socket.
Thanks in advance.

UPD: I learned about Originate with the Async parameter and that you can catch an event like OriginateResponse. Now the question boils down to this: how to catch this event?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MyAsterisk_Team, 2012-03-13
@MyAsterisk_Team

Using Variables in the Asterisk Dial Plan
Asterisk can use both global variables and channel-specific variables that can be used as arguments to commands in the dial plan. Variables used in the dial plan (extensions.conf) use the following syntax:
${foo}
where foo is the name of the variable. The variable name can be an alphanumeric string, which must begin with a letter. User defined variables are not case sensitive ${FOO} and ${Foo} refer to the same variable. But variables defined by Asterisk itself are case sensitive, ${EXTEN} will work, but ${exten} won't.
There are three types of variables: global, channel-specific variables, and environment variables.
Global variables can be defined either in the [globals] section of the extensions.conf configuration file or by using the SetGlobalVar command in the dialplan. Once a variable is defined, then it can be used for any channel at any time.
Channel-specific variables are set using the Set command (the SetVar command is obsolete). Each channel uses an isolated space for variable names, so for different calls there will be no collisions in the values ​​of a variable with the same name and the variable will be automatically cleared when the call on any channel is completed.
Environment variables provide access from Asterisk to unix environment variables. A list of them can be found below this page.
If you define a variable for some channel with the same name as an existing global variable (remember: user-defined variables are case insensitive) then referring to that variable name in a command will give you the value you defined for that "channel" variable ( not the value of a global variable). For example, see for yourself what happens if we do the following in the context of "FooTest" with one extension 100:
[FooTest]
exten => 100.1,SetGlobalVar(FOO=5)
exten => 100.2,NoOp($ {FOO})
exten => 100.3,NoOp(${foo})
exten => 100.4,Set(foo=8)
exten => 100.5,NoOp(${FOO})

exten => 100,6,NoOp(${foo})
(Note: using the NoOp command will help us keep track of our actions and variable values.) If you call extension 100 in the context of FooTest, and you have an Asterisk console that displays detailed information about what is happening, you will see approximately the following information:
- Executing SetGlobalVar("Zap/1-1", "FOO=5") in new stack
- Setting global variable 'FOO' to '5'
- Executing NoOp("Zap/ 1-1", "5") in new stack
- Executing NoOp("Zap/1-1", "5") in new stack
- Executing Set("Zap/1-1", "foo=8") in new stack
- Executing NoOp("Zap/1-1", "8") in new stack
- Executing NoOp("Zap/1-1", "8") in new stack

We see that after executing the SetGlobalVar command, the variables ${FOO} and ${foo} return the value of the global variable with the value 5. After executing the Set command, the global variable "foo" is overridden by the channel variable "foo"; Both ${FOO} and ${foo} (actually the same variable) have a value of 8. However, the value of the global variable remains unchanged at 5, and using it in other channels will return the value of the global variable ${foo}, which is still five.
Channel-Specific Variable Inheritance
If we prefix the variable name with a single _ character in the Set command, then this variable will be inherited by the channel that will be created by the main channel, for example, when using the Dial(Local/...); command. Once inherited, this variable will not be further inherited. If we add two _ characters in front of the variable name, the variable will be inherited an unlimited number of times. (Only works for CVS HEAD, not supported in Asterisk 1.0.9.)
Note that if we want to get the value of a variable, there is no need for leading underscores when referring to its name.
[TestInherit]
exten => 100,1,Set( __ FOO=5)
exten => 100,2,Dial(Local/[email protected])
exten => test,1,NoOp(${FOO})

As a result, the FOO variable will be inherited. Without underscores, this variable will be undefined in a new pipe of type local.
Example
exten => 104,1,Set(FEE=${fee})
exten => 104,2,Set(_FIE=${fie})
exten => 104,3,Set(__FUM=${fum})
exten => 104.4,Dial(Local/105)
exten => 105.1,NoOp(${FEE})
exten => 105.2,NoOp(${FIE})
exten => 105.3,NoOp($ {FUM})
exten => 105,4,Dial(Local/106)
exten => 106,1,NoOp(${FEE})
exten => 106,2,NoOp(${FIE})
exten => 106, 3,NoOp(${FUM})
as a result we get:
- Executing Set("SIP/oberon-365e", "FEE=fee") in new stack
- Executing Set("SIP/oberon-365e", "_FIE=fie ") in new stack
- Executing Set("SIP/oberon-365e", "__FUM=fum") in new stack
- Executing Dial("SIP/oberon-365e", "Local/105") in new stack
- Called 105
- Executing NoOp(" Local/[email protected],2", "") in new stack
— Executing NoOp("Local/[email protected],2", "") in new stack
— Executing NoOp("Local/[email protected] 7263.2", "fum") in new stack
- Executing Dial("Local/[email protected]", "Local/106") in new stack
- Called 106
- Executing NoOp("Local/[email protected] -49be,2", "") in new stack
- Executing NoOp("Local/[email protected],2", "") in new stack
- Executing NoOp("Local/[email protected],2", "fum") in new stack

Only variables need to be substituted

V
Veshij, 2012-03-13
@Veshij

>I'm writing an application integrated with Asterisk, but I haven't had time yet to get a good grasp of the Asterisk API.
This is some kind of pipets what an absurd application, if you think about it.
"I'm writing in C here, but I didn't have time to figure it out, show me how to write 'hello world'"
"I'm writing an application for the Yandex.Direct API, but I didn't have time to figure it out"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question