[asterisk-users] log incoming calls without answering

J Montoya or A J Stiles asterisk_list at earthshod.co.uk
Fri Apr 21 03:36:21 CDT 2017

On Thursday 20 Apr 2017, Fabio Moretti wrote:
> Hi,
> I've some analogic lines and I'm asked if it's possible to program an
> asterisk for "checking" the inbound calls without answering them, doing
> something like this:
> analog line 1 -----+---------- asterisk
>                    \______ analog phone
> when a call enter, asterisk sense it and store its values (callerid, date
> and time, etc) somewhere, but nothing more, people will answer using the
> old analog phone. The goal is to have a log of the inbound calls without
> touching the old analog system (it's shared between different subjects).
> I'm pretty sure it's something possible, but how to tell asterisk: "ok,
> call this AGI, and then don't answer and do nothing more".
> Any idea?

You can get FXO cards, such as the TDM410P/E; which connect to an analogue 
line just like a telephone and then allow the line to be treated as a DAHDI 
channel.  (You would need an FXS card to connect to an analogue telephone; 
this has an additional power supply to generate the 48V DC line voltage and 
80V, 25 Hz ringing voltage.  Usually these cards have 4 or 8 slots for either 
FXO or FXS modules; make sure you buy the right ones.  Explaining to the 
vendor what you want it for may be the best way.)

So you could have Asterisk as an extension to your analogue line, and it could 
monitor incoming calls.  (You would not be able to monitor outgoing calls, 
though; unless you connected each analogue telephone to an FXS port, and used 
Asterisk as a simple PABX.)  

You do not need to Answer() the line to get the caller ID; it comes down the 
line  (either as 300 baud modem tones representing ASCII, or DTMF digit tones, 
depending on your telephone company)  between the polarity reversal and the 
first ring.  And there is no need to have Answer()ed before running an AGI  (in 
fact, you might have good reasons why you would want to have a pre-answer 
script, such as deciding which extension to ring, if you want to direct 
inbound callers straight back to the agent who called them earlier).

All your AGI need do is fork(), and now -- as far as you are concerned -- 
there are two parallel universes, each containing a full copy of the original 
process with the same variables and file handles.  In one, which is the parent, 
fork() returned a non-zero value  (which is the PID of the child process, and 
you might have to clear it out of the process table if it exits before you 
do);  so that process can just exit and return control to Asterisk.  In the 
child process, where the fork() call returned zero  (you don't need to know 
your parent process's PID, since any still-living grandparent will just take 
care of you),  you need just to close STDIN, STDOUT and STDERR  (which are 
still connected to Asterisk)  so it will no longer be waiting for your process 
to do anything -- now you are free!  :)  You then connect to some sort of 
database and run a query like

INSERT INTO call_history(date,source,dest) 

except that ${CALLERID(num)} and ${EXTEN} will have to be passed into the AGI 
script as parameters.  

Then. back in extensions.conf, Dial() a local channel that does nothing but 
Wait() for long enough for the ringing to stop; either because the analogue 
phone has been picked up, or because the caller has stopped trying.  Asterisk 
should get a Hangup() event when the far end hangs up, at any rate.

If you buy a single-channel one of the cheap Chinese clone cards  (from The 
Usual Place),  it ought to last long enough and work well enough for you to 
experiment with; but DO NOT rely on these cheap cards for anything even 
remotely mission-critical.


Note:  Originating address only accepts e-mail from list!  If replying off-
list, change address to asterisk1list at earthshod dot co dot uk .

More information about the asterisk-users mailing list