Asterisk: Detect incoming call

RobertChanphakeo
RobertChanphakeo used Ask the Experts™
on
In asterisk/elastix/freepbx

How do you
1- detect an incoming call
2- read the caller id
3- do something...(perform function)

?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Hello Robert,

There are several case scenarios for an incoming call :

* If you have an analog line connected to an analog card in your server: the card will be configured so that any incoming call is sent to a particular context in the dialplan. Then all incoming calls will be sent to extension s, priority 1. For example:

-> Configuration:
FXO analog card port 1 : context = analog1

-> Dialplan:
[analog1]
exten => s,1,Answer()
exten => s,n,Playback(thank-you-for-calling)
exten => s,n,Hangup()

* If you have an ISDN formatted digital T1, such as PRI, you will simply define a context for your PRI. All incoming calls will be sent to that context, to the extension matching the DID sent through the PRI, at priority 1 (i'd recommend to ask your carrier to send you the whole 10 digits, so it makes it easy to read from the dialplan). For example:

-> Configuration:
T1 span: context = t1

-> Dialplan:
[t1]
exten => 2035551122,1,Answer()
exten => 2035551122,n,Playback(thank-you-for-calling)
exten => 2035551122,n,Hangup()


exten => 2035551155,1,Answer()
exten => 2035551155,n,Playback(thank-you-for-calling)
exten => 2035551155,n,Hangup()


* If you have a SIP phone connected to your asterisk server, this SIP phone will have a context defined. When a number is dialled on the sip phone, Asterisk will look for an extension matching this number in the context of the sip phone. For example:

-> Configuration:
SIP phone: context = sipphone

-> Dialplan:
[sipphone]
exten => 100,1,Answer()
exten => 100,n,Playback(thank-you-for-calling)
exten => 100,n,Hangup()


exten => 102,1,Answer()
exten => 102,n,Playback(thank-you-for-calling)
exten => 102,n,Hangup()


This is how it works in a nutshell, don't hesitate to ask more questions if you have any.

Author

Commented:
Hello nauliv

Using SIP, user dials the DID number, it connects to the asterisk PBX box, which file do I need to edit to get the caller id?

Will need to work with the caller id in php.
Commented:
Hello Robert,

Sorry about this, I totally forgot to address the callerID part of your question. The file that you would need to edit is the extensions.conf.

When a call has been answered by your dialplan, 2 variables will get automatically populated:
* CALLERID(num) which contains the caller id number of the person calling
* CALLERID(name) which contains the caller id name of the person calling

Keep in mind that they could be empty if the callerID has not been passed, or if the call comes from a connection that does not carry callerID.

For example, if you want to display these variables on the console using the NoOp command, it would look like:

[t1]
exten => 2301112222,1,Answer()
exten => 2301112222,n,NoOp(The callerid number is ${CALLERID(num)})
exten => 2301112222,n,NoOp(The callerid name is: ${CALLERID(name)})
exten => 2301112222,n,Playback(thank-you-for-calling)
exten => 2301112222,n,Hangup()


If you'd like to pass the callerID to a PHP script for processing, the dialplan would look like:

[t1]
exten => 2301112222,1,Answer()
exten => 2301112222,n,NoOp(The callerid number is ${CALLERID(num)})
exten => 2301112222,n,NoOp(The callerid name is: ${CALLERID(name)})
exten => 2301112222,n,AGI(robert.php,${CALLERID(num)},${CALLERID(name) })
exten => 2301112222,n,Playback(thank-you-for-calling)
exten => 2301112222,n,Hangup()

This will call the PHP script robert.php, and pass the callerID name and number. For more information on how to interface Asterisk with PHP, check this page: http://www.voip-info.org/wiki/view/Asterisk+AGI+php

Let us know if this helps.

Author

Commented:
solution: untested.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial