Getting the extension number on which a call was received within a function - asterisk - asterisk

I have an asterisk server set up as a telephone exchange. I have, on it, a 100 extensions, from 00 - 99. I am running specific functions on each of those extensions. Some of these functions may need the extension on which the call was received to be available. How can I access the same? For example,
Say a call comes in on extension 55.
55 has a function associated with it. That function must take in 55 as an input parameter. How do I do this?
I have tried the following:
exten => 0,n,Verbose(1, "Call on ${EXTEN}-${CHANNEL}")
Output is : Call on 0-DAHDI/20-1
Thanks,
Sriram Shankar.

The answer you are looking for is dependent upon the path that the call is taking through your system. The easiest way to determine the answer to your question is to place the call and then run the following commands from within the Asterisk CLI:
> core show channels
This will show you what channels are active. Find the channel name of your call.
core show channel [channel-name]
This will output an array of channel details, including different variables that are set and their corresponding values. Look for the extension number you are trying to grab in the value fields and then look to see what the corresponding variable name is. It could be ${CALLERID(num)}, ${CALLERID(dnid)}, something under the ${CDR} variable, or even elsewhere.
If you don't find it in the output produced by "core show channel [channel-name]", you may have to trace the dialplan path that the call is taking and try setting the variable early on when the DID information is still available.

Related

Get call duration of active calls in Asterisk 13

Please, I want to implement billing in asterisk 13.
i want to be able monitor an active call of a particular extension ( say extension 0001) and Hangup call once the extension have used 10mins. How do I achieve this in dailplan ( i.e extensions.conf)
...appreciations for any input.
First of all i can recommend you use already created billings like a2billing.org or CCGrates.
If you have not much resources and experience, that will be just wast of time(alot of things can go not as you expect).
For see currently active calls you can use ForkCDR functions of CEL events(like some commercial billing systems use).
You also can use AMI events+dialplan for track that(like fop/fop2 use), but tat is not easy way.
Most easy way is CEL probably.
For hangup call you can use function TIMEOUT(absolute) or params of Dial command.

Asterisk pre-emption and callers in a channel

I would like to have pre-emption calls in Asterisk. I think there is no Asterisk support for this feature so i'm trying to implement it following a simliar algorithm like the one showed in this thread: Asterisk - Pre-emption calls
So I'm having problems in this step:
check if B in call with lower priority caller( ASTDB or REALTIME or fastagi script).
I know how to check if B is in a call using for example DEVICE_STATE(device) cmd, but i can't achieve to know who is the other caller in order to see his priority.
So, How can I know if one users is in a call and who is the other caller inside this call?
Thanks a lot.
You can read variables of any channel using
SHARED(varname[,channel])
-= Info about function 'SHARED' =-
[Synopsis]
Gets or sets the shared variable specified.
[Description]
Implements a shared variable area, in which you may share variables between
channels.
The variables used in this space are separate from the general namespace
of the channel and thus ${SHARED(foo)} and ${foo} represent two completely
different variables, despite sharing the same name.
Finally, realize that there is an inherent race between channels operating
at the same time, fiddling with each others' internal variables, which is
why this special variable namespace exists; it is to remind you that variables
in the SHARED namespace may change at any time, without warning. You should
therefore take special care to ensure that when using the SHARED namespace,
you retrieve the variable and store it in a regular channel variable before
using it in a set of calculations (or you might be surprised by the
result).
Sure you have set variables first.
You can set in variables or in ASTDB name of current speaking channel using in-call macro
General complexity of any solution like you want is above average, need person with at least 1-2 year of extensive experience with *.

Get state of other channel

Is it possible to get a state of another channel. For example: In my dialplan I want to know the state of channel: SIP/provider/0612345678 and it should return, INVITE or ANSWERED etc
Is this possible?
Yes, you can use function SHARED.
core show function SHARED
-= Info about function 'SHARED' =-
[Synopsis]
Gets or sets the shared variable specified.
[Description]
Implements a shared variable area, in which you may share variables between
channels.
The variables used in this space are separate from the general namespace
of the channel and thus ${SHARED(foo)} and ${foo} represent two completely
different variables, despite sharing the same name.
Finally, realize that there is an inherent race between channels operating
at the same time, fiddling with each others' internal variables, which is
why this special variable namespace exists; it is to remind you that variables
in the SHARED namespace may change at any time, without warning. You should
therefore take special care to ensure that when using the SHARED namespace,
you retrieve the variable and store it in a regular channel variable before
using it in a set of calculations (or you might be surprised by the
result).
[Syntax]
SHARED(varname[,channel])
[Arguments]
varname
Variable name
channel
If not specified will default to current channel. It is the complete
channel name: 'SIP/12-abcd1234' or the prefix only 'SIP/12'.
For answered you have check variable DIALSTATUS

How can I insert call duration of an Asterisk call into my own database?

I have my own database to log the calls in astreisk. I need to insert call duration of every call into a table. How can I do this? Can I do this in my dialplan?
You are not giving much information about what db backend you would like to use, and also if you are asking about how to write yourself the call duration or how to configure asterisk to write the cdr in question.
So, generally speaking, you have 3 possible options for this (see below). For options 2 and 3 you would have to open the connection to the database yourself, write the queries needed to insert/update whatever row(s) needed, handle errors, etc. While for option 1 you just need to configure asterisk to do the job.
1) Asterisk can do this by default on its own, by writing the CDR (Call Detail Record) of every call to a backend. This backend can be csv, mysql, pgsql, sqlite and other databases through the cdr_odbc module. You have to configure your cdr.conf (and depending on the backend you chose, cdr_mysql.conf, cdr_odbc.conf, cdr_pgsql.conf with your backend information, like credentials, table names, etc).
The CDR will be written by default with some contents, which are the CDR Variables (taken from the predefined asterisk variable list)
If the channel has a cdr, that cdr record has it's own set of
variables which can be accessed just like channel variables. The
following builtin variables are available and, unless specified,
read-only.
The ones interesting for you at this point would be:
${CDR(duration)} Duration of the call.
${CDR(billsec)} Duration of the call once it was answered.
${CDR(disposition)} ANSWERED, NO ANSWER, BUSY
When disposition is ANSWER, billsec will contain the number of seconds to bill (the total "answered time" of the call), and duration will hold the total time of the call, including non-billed time.
2) If, on the other hand, if you are not asking about the cdr, but want to write yourself the call duration, you can have an AGI script that after issuing a dial(), reads the CDR(billsec) variable, or the ANSWEREDTIME (set by the Dial() command):
${DIALEDTIME} * Time for the call (seconds)
${ANSWEREDTIME} * Time from dial to answer (seconds)
3) You can also achieve the same result by having an AMI client listening for the event VarSet for the variable ANSWEREDTIME. The event in question will contain the channel for which this variable has been set.
So, options 2 and 3 are clearly more useful if you already have an AGI script or an AMI client of your own controlling/handling calls, and option 1 is more generic but maybe slightly less flexible.
Hope it helps!

isControllable and isObservable maple functions: Is there a way to make them show steps?

So we can use isObservable to work with some systems but I wonder If we can make tham show staps or do something like that. Is that possible?
I'm supposing that you are actually referring to the Observable and Controllable commands which are part of the DynamicSystems package.
Some Maple routines have so-called userinfo messages, which are optionally displayed and which can show partial steps. Those would typically be enabled with a call like infolevel[DynamicSystems]:=6 where 6 is the highest level of detail. With a lower value less detail might be displayed. Unfortunately, these particular DynamicSystems routines don't seem to have any userinfo messages in them. So this won't help directly in your case.
Sometimes one package calls another. The routine LinearAlgebra:-Rank is called, at some point, when Controllable is called. I'm guessing that you don't wish to see userinfo messages in Rank, which would be enabled by issuing infolevel[LinearAlgebra]:=n for some n between 1 and 6.
An alternative is to set printlevel high. But doing so will make all Maple internal calls also be verbose. The resulting output of setting, say, printlevel:=20 is overwhelming. I doubt that you'd find this approach useful.
Another alternative is to set certain routines as option trace. Sometimes doing so entails knowing the names of the appropriate internal routines. And this is made more complicated by the fact that not all non-exported module locals are visible by default. You could try first issuing the call, trace(DynamicSystems::ControllableSS): before invoking Controllable on your system. That shows some intermediary results, but those might not make much sense to you unless you know what source lines are generating those results. You can see the source by issuing the command, showstat(DynamicSystems::ControllableSS);
Here's an example,
restart:
with( DynamicSystems ):
aSys := StateSpace( <<1,2>|<3,4>>, <<2,3>>, <<1,0>|<0,1>>, <<0,0>> ):
aSys:-a, aSys:-b, aSys:-c:
trace(DynamicSystems::ControllableSS):
Controllable( aSys );
showstat(DynamicSystems::ControllableSS);
By looking at the source of the ControllableSS routine, you can deduce that it calls DynamicSystems:-StaircaseTransformation when the staircase method is specified. So here too you could issue showstat(DynamicSystems::StaircaseTransformation) to see the source of that internal (local) routine. Or you could trace that routine as well.
As a general rule, you can refer to exports of a module or package using the :- notation. And you can pass such names to trace and showstat using the :: notation instead of :-, unless you have first set kernelopts(opaquemodules=false). If an inner submodule member has more than one :- in its name then you'd have to use round-bracket delimiters to refer to it with the :: syntax. Sorry, that that's not so easy to express.

Resources