Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Asterisk v 1.4 Call Trace

72 views
Skip to first unread message

Jono

unread,
Mar 14, 2009, 1:29:00 PM3/14/09
to
Hello,

Am having a bit of a thick moment.

How do I modify the below to allow me to dial in and listen to the last caller to extension 204?

[custom-app-1871]
exten => s,1,Answer
exten => s,n,Wait(1)
exten => s,n,Macro(user-callerid,)
exten => s,n,Playback(info-about-last-call&telephone-number)
exten => s,n,Set(lastcaller=${DB(CALLTRACE/${AMPUSER})})
exten => s,n,GotoIf($[ $[ "${lastcaller}" = "" ] | $[ "${lastcaller}" = "unknown" ] ]?noinfo)
exten => s,n,SayDigits(${lastcaller})
exten => s,n,Set(TIMEOUT(digit)=3)
exten => s,n,Set(TIMEOUT(response)=7)
exten => s,n,Background(to-call-this-number&press-1)
exten => s,n,Goto(fin)
exten => s,n(noinfo),Playback(from-unknown-caller)
exten => s,n,Macro(hangupcall,)
exten => s,n(fin),Noop(Waiting for input)
exten => s,n,WaitExten(60,)
exten => s,n,Playback(sorry-youre-having-problems&goodbye)
exten => 1,1,Goto(from-internal,${lastcaller},1)
exten => i,1,Playback(vm-goodbye)
exten => i,n,Macro(hangupcall,)
exten => t,1,Playback(vm-goodbye)
exten => t,n,Macro(hangupcall,)


Phil Reynolds

unread,
Mar 14, 2009, 2:10:38 PM3/14/09
to
On Sat, 14 Mar 2009 17:29:00 +0000, Jono wrote:

> How do I modify the below to allow me to dial in and listen to the last
> caller to extension 204?

Just to clarify, are you trying to do "call return" like 1471 (BT)?

If so I could give you my routine together with an explanation of how it
works.

--
Phil Reynolds
mail: phil...@tinsleyviaduct.com
PLEASE FOLLOWUP IN NEWS

Jono

unread,
Mar 14, 2009, 3:12:28 PM3/14/09
to
Phil Reynolds explained on 14/03/2009 :

> On Sat, 14 Mar 2009 17:29:00 +0000, Jono wrote:
>
>> How do I modify the below to allow me to dial in and listen to the last
>> caller to extension 204?
>
> Just to clarify, are you trying to do "call return" like 1471 (BT)?
>
> If so I could give you my routine together with an explanation of how it
> works.

Sort of.

I have calls into my PBX forwarded to my mobile. Because the ITSPs do
not forward the caller's CLI, if I miss a call, I can't find out who
called.

So, i thought it would be useful to dial in remotely to a DISA and then
do *69 or whatever....


Phil Reynolds

unread,
Mar 14, 2009, 8:37:38 PM3/14/09
to
On Sat, 14 Mar 2009 19:12:28 +0000, Jono wrote:

> Sort of.
>
> I have calls into my PBX forwarded to my mobile. Because the ITSPs do
> not forward the caller's CLI, if I miss a call, I can't find out who
> called.
>
> So, i thought it would be useful to dial in remotely to a DISA and then
> do *69 or whatever....

Well, my routine may be helpful then... have a look at this - it does
work if using DISA if you set the callerid correctly:

exten => 1471,1,Set(TECHNOLOGY=${CUT(CHANNEL,/,1)}) ; I add some 2 sec
delays iff technology is SIP
exten => 1471,n,Answer()
exten => 1471,n,ExecIf($["${TECHNOLOGY}"="SIP"],Wait,2)
exten => 1471,n,GotoIf($["${DB(lastcall/${CALLERID(num):-4}):0:1}"="0"]?
num:nonum) ; whether there was a number declared on last call to the
caller ID of this phone (last 4 digits are my internal extensions - I
have a small DID block)
exten => 1471,n,Playback(/var/lib/asterisk/sounds/custom/telno) ;
"Telephone number"
exten => 1471,n,SayDigits(${DB(lastcall/${CALLERID(num):-4})})
exten => 1471,n,Playback(/var/lib/asterisk/sounds/custom/called) ;
"called"
exten => 1471,n,SayUnixTime(${DB(lastcalltime/${CALLERID
(num):-4})},Europe/London,q \'digits/at\' IMp)
exten => 1471,n,Read(RESP,/var/lib/asterisk/sounds/custom/returncall,1) ;
"To return the call, press 3" and awaits a digit
exten => 1471,n,GotoIf($["${RESP}" = "3"]?${CONTEXT},${DB(lastcall/
${CALLERID(num):-4})},1) ; dial as would be normal context for this phone
exten => 1471,n,Hangup()
exten => 1471,n(nonum),Playback(/var/lib/asterisk/sounds/custom/
youwerecalled) ; "You were called"
exten => 1471,n,SayUnixTime(${DB(lastcalltime/${CALLERID
(num):-4})},Europe/London,q \'digits/at\' IMp)
exten => 1471,n,Goto(${DB(lastcall/${CALLERID(num):-4})}) ; see incoming
call routine
exten => 1471,n,Hangup()
exten => 1471,n(Withheld),Playback(/var/lib/asterisk/sounds/custom/
withheld) ; "The caller withheld their number"
exten => 1471,n,ExecIf($["${TECHNOLOGY}"="SIP"],Wait,2)
exten => 1471,n,Hangup()
exten => 1471,n(Unavailable),Playback(/var/lib/asterisk/sounds/custom/
donothave) ; "We do not have the caller's number to return the call"
exten => 1471,n,ExecIf($["${TECHNOLOGY}"="SIP"],Wait,2)
exten => 1471,n,Hangup()
exten => 1471,n(International),Playback(/var/lib/asterisk/sounds/custom/
international) ; "The call was from abroad" (if caller ID is available,
the call is treated as normal)
exten => 1471,n,ExecIf($["${TECHNOLOGY}"="SIP"],Wait,2)

My voicemail macro (similar to the idea in the book) sets values in the
dbi (ARG1 is the called user's channels, ARG2 his timeout - I have a user
who needs a longer timeout) similar to this:

[macro-voicemail]
exten => s,1,GotoIf($["${CALLERID(num)}"=""]?nonum:withnumber)
exten => s,n(nonum),ExecIf($["${CALLERID(name)}"="UNAVAILABLE"],Set,DB
(lastcall/${MACRO_EXTEN})=Unavailable)
exten => s,n,ExecIf($["${CALLERID(name)}"="INTERNATIONAL"],Set,DB
(lastcall/${MACRO_EXTEN})=International)
exten => s,n,ExecIf($["${CALLERID(name)}"="" | "${CALLERID
(name)}"="anonymous" | "${CALLERID(name)" = "WITHHELD"],Set,DB(lastcall/
${MACRO_EXTEN})=Withheld)
exten => s,n,SetCallerPres(allowed)
exten => s,n,Goto(calltime)
exten => s,n(withnumber),Set(DB(lastcall/${MACRO_EXTEN})=${CALLERID(num)})
exten => s,n(calltime),Set(DB(lastcalltime/${MACRO_EXTEN})=${EPOCH})
exten => s,n,ExecIf($["${CALLERID(name)}"=""],Set,CALLERID(name)=${DB
(cidname/${CALLERID(num)})}) ; if you do not look up caller names in the
db this line is optional
exten => s,n,Dial(${ARG1},${ARG2},otwW)
exten => s,n,GotoIf($["${DIALSTATUS}"="BUSY"]?busy)
exten => s,n,VoiceMail(${MACRO_EXTEN},u)
exten => s,n,MacroExit()
exten => s,n(busy),VoiceMail(${MACRO_EXTEN},b)

--
Phil Reynolds
mail: phil...@tinsleyviaduct.com

PLEASE followup news posts in news
- that's what it's here for

Jono

unread,
Mar 15, 2009, 12:00:11 AM3/15/09
to
Phil Reynolds brought next idea :

> On Sat, 14 Mar 2009 19:12:28 +0000, Jono wrote:
>
>> Sort of.
>>
>> I have calls into my PBX forwarded to my mobile. Because the ITSPs do
>> not forward the caller's CLI, if I miss a call, I can't find out who
>> called.
>>
>> So, i thought it would be useful to dial in remotely to a DISA and then
>> do *69 or whatever....
>
> Well, my routine may be helpful then... have a look at this - it does
> work if using DISA if you set the callerid correctly:
>

Thanks, Phil.

....where do I specify ext 204...? somewhere here?

exten => 1471,n,GotoIf($["${DB(lastcall/${CALLERID(num):-4}):0:1}"="0"]?num:nonum) ; whether there was a number declared on last call to the caller ID of this phone (last 4 digits are my internal extensions - I have a small DID block)


Phil Reynolds

unread,
Mar 15, 2009, 6:10:28 AM3/15/09
to
On Sun, 15 Mar 2009 04:00:11 +0000, Jono wrote:

> ....where do I specify ext 204...? somewhere here?

> exten =>
> 1471,n,GotoIf($["${DB(lastcall/${CALLERID(num):-4}):0:1}"="0"]?
num:nonum)
> ; whether there was a number declared on last call to the caller ID of
> this phone (last 4 digits are my internal extensions - I have a small
> DID block)

You could hardcode these occurrences as "lastcall/204" or arrange things
so that when you hit the DISA, your callerid ends "204" and recode them
as lastcall/${CALLERID(num):-3.

I set mine using:

exten => 8,1,VMauthenticate()
exten => 8,n,Set(CALLERID(num)=(my DID prefix)${AUTH_MAILBOX})
exten => 8,n,DISA(no-password,default)

If your AUTH_MAILBOX were 204, ${CALLERID(num):-3 would be 204. My
default context supports internal service codes and free calls only. You
could of course just set it to ${AUTH_MAILBOX} if you do not have
outbound calling possible through your DISA.

Jono

unread,
Mar 15, 2009, 7:11:02 AM3/15/09
to
Phil Reynolds explained :

> On Sun, 15 Mar 2009 04:00:11 +0000, Jono wrote:
>
>> ....where do I specify ext 204...? somewhere here?
>
>> exten =>
>> 1471,n,GotoIf($["${DB(lastcall/${CALLERID(num):-4}):0:1}"="0"]? num:nonum)
>> ; whether there was a number declared on last call to the caller ID of
>> this phone (last 4 digits are my internal extensions - I have a small
>> DID block)
>
> You could hardcode these occurrences as "lastcall/204" or arrange things
> so that when you hit the DISA, your callerid ends "204" and recode them
> as lastcall/${CALLERID(num):-3.
>
> I set mine using:
>
> exten => 8,1,VMauthenticate()
> exten => 8,n,Set(CALLERID(num)=(my DID prefix)${AUTH_MAILBOX})
> exten => 8,n,DISA(no-password,default)
>
> If your AUTH_MAILBOX were 204, ${CALLERID(num):-3 would be 204. My
> default context supports internal service codes and free calls only. You
> could of course just set it to ${AUTH_MAILBOX} if you do not have
> outbound calling possible through your DISA.

::-)

Pretend I'm /really/ new to this...made the changes, recorded the sounds

exten => 1871,1,Set(TECHNOLOGY=${CUT(CHANNEL,/,1)}) ; I add some 2 sec delays if technology is SIP
exten => 1871,n,Answer()
exten => 1871,n,ExecIf($["${TECHNOLOGY}"="SIP"],Wait,2)
exten => 1871,n,GotoIf($["${DB(lastcall/204):0:1}"="0"]?num:nonum) ; whether there was a number declared on last call to the caller ID of this phone (last 4 digits are my internal extensions - I have a small DID block)
exten => 1871,n,Playback(/var/lib/asterisk/sounds/custom/telno) ; "Telephone number"
exten => 1871,n,SayDigits(${DB(lastcall/204)})
exten => 1871,n,Playback(/var/lib/asterisk/sounds/custom/called) ; "called"
exten => 1871,n,SayUnixTime(${DB(lastcalltime/204)},Europe/London,q \'digits/at\' IMp)
exten => 1871,n,Read(RESP,/var/lib/asterisk/sounds/custom/returncall,1) ; "To return the call, press 3" and awaits a digit
exten => 1871,n,GotoIf($["${RESP}" = "3"]?${CONTEXT},${DB(lastcall/204)},1) ; dial as would be normal context for this phone
exten => 1871,n,Hangup()
exten => 1871,n(nonum),Playback(var/lib/asterisk/sounds/customyouwerecalled) ; "You were called"
exten => 1871,n,SayUnixTime(${DB(lastcalltime/204)},Europe/London,q \'digits/at\' IMp)
exten => 1871,n,Goto(${DB(lastcall/204)}) ; see incoming call routine
exten => 1871,n,Hangup()
exten => 1871,n(Withheld),Playback(var/lib/asterisk/sounds/customwithheld) ; "The caller withheld their number"
exten => 1871,n,ExecIf($["${TECHNOLOGY}"="SIP"],Wait,2)
exten => 1871,n,Hangup()
exten => 1871,n(Unavailable),Playback(var/lib/asterisk/sounds/customdonothave) ; "We do not have the caller's number to return the call"
exten => 1871,n,ExecIf($["${TECHNOLOGY}"="SIP"],Wait,2)
exten => 1871,n,Hangup()
exten => 1871,n(International),Playback(var/lib/asterisk/sounds/custominternational) ; "The call was from abroad" (if caller ID is available, the call is treated as normal)
exten => 1871,n,ExecIf($["${TECHNOLOGY}"="SIP"],Wait,2)


Aall I hear is "at 11 oh 4 am" (well, whatever the current time is)

-- Executing [1871@from-internal:1] Set("SIP/204-b7206af0", "TECHNOLOGY=SIP") in new stack
-- Executing [1871@from-internal:2] Answer("SIP/204-b7206af0", "") in new stack
-- Executing [1871@from-internal:3] ExecIf("SIP/204-b7206af0", "1|Wait|2") in new stack
-- Executing [1871@from-internal:4] GotoIf("SIP/204-b7206af0", "0?num:nonum") in new stack
-- Goto (from-internal,1871,12)
-- Executing [1871@from-internal:12] Playback("SIP/204-b7206af0", "var/lib/asterisk/sounds/customyouwerecalled") in new stack
-- Executing [1871@from-internal:13] SayUnixTime("SIP/204-b7206af0", "|Europe/London|q 'digits/at' IMp") in new stack
-- <SIP/204-b7206af0> Playing 'digits/at' (language 'en_GB')
-- <SIP/204-b7206af0> Playing 'digits/11' (language 'en_GB')
-- <SIP/204-b7206af0> Playing 'digits/oh' (language 'en_GB')
-- <SIP/204-b7206af0> Playing 'digits/4' (language 'en_GB')
-- <SIP/204-b7206af0> Playing 'digits/a-m' (language 'en_GB')
-- Executing [1871@from-internal:14] Goto("SIP/204-b7206af0", "") in new stack
== Spawn extension (from-internal, 1871, 14) exited non-zero on 'SIP/204-b7206af0'
-- Executing [h@from-internal:1] Macro("SIP/204-b7206af0", "hangupcall") in new stack
-- Executing [s@macro-hangupcall:1] ResetCDR("SIP/204-b7206af0", "w") in new stack
-- Executing [s@macro-hangupcall:2] NoCDR("SIP/204-b7206af0", "") in new stack
-- Executing [s@macro-hangupcall:3] GotoIf("SIP/204-b7206af0", "1?skiprg") in new stack
-- Goto (macro-hangupcall,s,6)
-- Executing [s@macro-hangupcall:6] GotoIf("SIP/204-b7206af0", "1?skipblkvm") in new stack
-- Goto (macro-hangupcall,s,9)
-- Executing [s@macro-hangupcall:9] GotoIf("SIP/204-b7206af0", "1?theend") in new stack
-- Goto (macro-hangupcall,s,11)
-- Executing [s@macro-hangupcall:11] Hangup("SIP/204-b7206af0", "") in new stack
== Spawn extension (macro-hangupcall, s, 11) exited non-zero on 'SIP/204-b7206af0' in macro 'hangupcall'
== Spawn extension (macro-hangupcall, s, 11) exited non-zero on 'SIP/204-b7206af0'


Jono

unread,
Mar 15, 2009, 7:39:20 AM3/15/09
to
Jono wrote :

> Phil Reynolds explained :
>> On Sun, 15 Mar 2009 04:00:11 +0000, Jono wrote:
>>
>>> ....where do I specify ext 204...? somewhere here?

So, I've modified the original with your /204 suggestion and it is
doing what I need....except the time stamp - always reads the current
time and not the time of the call...

[custom-app-1871]
exten => s,1,Answer
exten => s,n,Wait(1)
exten => s,n,Macro(user-callerid,)

exten => s,n,SayUnixTime(${DB(lastcalltime/204)},Europe/London,q
\'digits/at\' IMp)
exten => s,n,Playback(info-about-last-call&telephone-number)
exten => s,n,Set(lastcaller=${DB(CALLTRACE/204)})

Phil Reynolds

unread,
Mar 15, 2009, 8:12:49 AM3/15/09
to
On Sun, 15 Mar 2009 11:39:20 +0000, Jono wrote:

> Jono wrote :
>> Phil Reynolds explained :
>>> On Sun, 15 Mar 2009 04:00:11 +0000, Jono wrote:
>>>
>>>> ....where do I specify ext 204...? somewhere here?
>
> So, I've modified the original with your /204 suggestion and it is doing
> what I need....except the time stamp - always reads the current time and
> not the time of the call...

That would imply that you do not have a lastcalltime/204 entry in your
database - you need to add it when the call comes in, like this:

Set(DB(lastcalltime/204)=${EPOCH})

If not set, the SayUnixTime treats it as "empty" which reads the current
time.

Jono

unread,
Mar 15, 2009, 8:20:34 AM3/15/09
to
After serious thinking Phil Reynolds wrote :

> On Sun, 15 Mar 2009 11:39:20 +0000, Jono wrote:
>
>> Jono wrote :
>>> Phil Reynolds explained :
>>>> On Sun, 15 Mar 2009 04:00:11 +0000, Jono wrote:
>>>>
>>>>> ....where do I specify ext 204...? somewhere here?
>>
>> So, I've modified the original with your /204 suggestion and it is doing
>> what I need....except the time stamp - always reads the current time and
>> not the time of the call...
>
> That would imply that you do not have a lastcalltime/204 entry in your
> database - you need to add it when the call comes in, like this:
>
> Set(DB(lastcalltime/204)=${EPOCH})

Whoosh......not sure if you noticed....I'm not using vanilla Asterisk
:-)

Where does the CDR get date and time of calls?


Phil Reynolds

unread,
Mar 15, 2009, 8:27:46 AM3/15/09
to
On Sun, 15 Mar 2009 12:20:34 +0000, Jono wrote:

> Whoosh......not sure if you noticed....I'm not using vanilla Asterisk
> :-)
>
> Where does the CDR get date and time of calls?

Ah, now you've got me a little stumped - perhaps someone better with CDRs
could answer if they are about?

Jono

unread,
Mar 15, 2009, 9:50:10 AM3/15/09
to
Phil Reynolds was thinking very hard :

> On Sun, 15 Mar 2009 12:20:34 +0000, Jono wrote:
>
>> Whoosh......not sure if you noticed....I'm not using vanilla Asterisk
>> :-)
>>
>> Where does the CDR get date and time of calls?
>
> Ah, now you've got me a little stumped - perhaps someone better with CDRs
> could answer if they are about?

Oh dear; was relying on you!


alexd

unread,
Mar 15, 2009, 4:28:34 PM3/15/09
to
Jono wrote:

> After serious thinking Phil Reynolds wrote :
>> On Sun, 15 Mar 2009 11:39:20 +0000, Jono wrote:
>>
>>> Jono wrote :
>>>> Phil Reynolds explained :

>> That would imply that you do not have a lastcalltime/204 entry in your


>> database - you need to add it when the call comes in, like this:
>>
>> Set(DB(lastcalltime/204)=${EPOCH})
>
> Whoosh......not sure if you noticed....I'm not using vanilla Asterisk
> :-)
>
> Where does the CDR get date and time of calls?

If it's FreePBX, isn't it in a MySQL database? Set(DB(...)) will store the
given value in Asterisk Database, which is separate from the MySQL DB.

http://www.voip-info.org/wiki/view/Asterisk+database

All Phil's code does is 'touch' an AstDB key called "lastcalltime/204"
whenever a call comes in, thereby giving you the date/timestamp for the
most recent call. A lot easier than querying the CDR [which is perfectly
possible from the dialplan with MYSQL(Connect, MYSQL(Query and
MYSQL(Fetch].
--
<http://ale.cx/> (AIM:troffasky) (UnSoEs...@ale.cx)
20:25:13 up 100 days, 22:36, 3 users, load average: 0.00, 0.02, 0.04
Sexy ladies, and nasty boys, all freaky freakin', to the robot noise

0 new messages