TUTORIAL CNAM Lookup for Outbound Calls

Rrrr

Tink
Joined
May 28, 2009
Messages
343
Reaction score
25
Yes it is related to Asteridex lookup: when I disable this in the incoming route the call comes in immediately.
I am not using any lookup sources, other than one Database and one Lookup scheme.

With Superfecta enabled there is a delay, hard to express exactly, of around 4 sec.
Same with outgoing calls and CNAM lookup.
It simply hangs a while on Executing scheme....

It may be just more visible on the Pi, with less cpu power. If you think cpu is the source of the problem, I will wait till ODBC is implemented for dial plan and then test again.
Perhaps we continue on another thread or go offline to test this, I am willing to assist.
 

Rrrr

Tink
Joined
May 28, 2009
Messages
343
Reaction score
25
Good idea.
(Note that I did not enable the Superfecta cache yet)

:blush2: Just a note here: it is not as in the hint given in the UI: SELECT `name` FROM `pbxcontacts` WHERE `out` LIKE '%[NUMBER]%'
but this should be: SELECT name FROM user1 WHERE `out` LIKE '[NUMBER]'
Thanks to this post in 2008...

After testing this, I can do several direct lookups in an SQL database (of 6000 contacts) using the Caller ID Lookup Sources module and hardly notice a delay.
While MySQL still works now, it will be deprecated soon according to wardmundy, but at least it shows hope that ODBC might be equally performing.
 

wardmundy

Nerd Uno
Joined
Oct 12, 2007
Messages
19,168
Reaction score
5,199
I am no SQL guru, but if I recall correctly, the Asteridex database has no primary key and is not indexed. The query you are using is as simple as things get, so if you are going to make any performance improvements, it will probably have to be with the Asteridex database. I can't help you with that.


Actually, there are indexes on the ID field and the name field. The simple answer to speed things up would be to add an index on the OUT field. Then it'll be zippy quick. PhpMyAdmin can do it with simple point and click.
 

kenn10

Well-Known Member
Joined
Dec 16, 2007
Messages
3,764
Reaction score
2,173
Ward, any thought of modifying this to work on a standard CID lookup source like OpenCNAM. I find that Superfecta is just too slow but if I turn it off and use my paid tier of OpenCNAM, the lookup is quite fast (on incoming calls.) I'd like to see an option where you choose your lookup from the CallerID Lookup Sources under Admin > CallerID Lookup Sources. Just a wish list item. :yes:

Edit: I manually adjusted the code to do this (actual Account SID and Auth Token substituted for post.)
Code:
; use the 6 lines below for CallerID Superfecta lookups
exten => s,n,Set(CURLOPT(httptimeout)=7)
exten => s,n,Set(CIDSFSCHEME=YmFzZV9EZWZhdWx0)
exten => s,n,Set(lookupcid=${num2find})
exten => s,n,Set(CALLERID(name)=${OrigCNAM})
;exten => s,n,AGI(/var/www/html/admin/modules/superfecta/agi/superfecta.agi)
exten => s,n,Set(lookupcid=${SHELL(curl 'https://ACCOUNT_SID:[email protected]/v2/phone/${num2find}')})
exten => s,n,Set(CALLERID(name)=${lookupcid})

This works great for a fast lookup through OpenCNAM. :clap:
 

Rrrr

Tink
Joined
May 28, 2009
Messages
343
Reaction score
25
I use this in extensions_custom.conf.
It may not work much longer when MySQL will stop being supported, but its fast.

For inbound, you need to call the macro from your context from-trunk-custom-yourown as follows:
exten => _./_+X!,n,Macro(cidlookup-rm,${CALLERID(num)})

You may need to tweak this for your country / incoming callerid format:

Code:
;==============================================
[macro-cidlookup-rm]
;==============================================
; ARG1 = CID to look for
exten => s,1,MYSQL(Connect connid localhost root raspberry asteridex) ; also passw0rd instead of raspberry
exten => s,n,Set(lookupcid=${ARG1})
 
exten => s,n,Set(OrigCNAM1=${CALLERID(name)})
exten => s,n,Set(OrigCID1=${CALLERID(num)})
exten => s,n,Set(CALLERID(num)=${lookupcid})
exten => s,n,GotoIf($[ "${CALLERID(num):0:1}" = "+" ] ?:unexpected) ; Has to start with +
 
exten => s,n,Noop("Check DB for numbers starting with 00: 00${CALLERID(num):1}")
exten => s,n,MYSQL(Query resultid ${connid} SELECT `name` FROM `user1` WHERE `out` LIKE '00${CALLERID(num):1}') ; INTN remove + and add 00
exten => s,n,MYSQL(Fetch fetchid ${resultid} CALLERID(name))
exten => s,n,MYSQL(Clear ${resultid})
exten => s,n,GotoIf($[ "${CALLERID(name)}" != "${OrigCNAM1}" ] ?finished)
....
exten => s,n(unexpected),Noop(Unexpected Callerid lookup: no prefix + in callerid(num))
exten => s,n(finished),Noop("CALLERID(all) = ${CALLERID(all)}")
exten => s,n,Set(CALLERID(num)=${OrigCID1})
;exten => s,n,Set(CALLERID(name)=${OrigCNAM1})  ; no need
 
exten => s,n,MYSQL(Disconnect ${connid})
exten => s,n,MacroExit
 
;BEGIN Outbound CNAM Support
[macro-dialout-trunk-predial-hook]
 
exten => s,1,Noop(*** ${DIAL_NUMBER} ***)
exten => s,n,Set(num2find=${DIAL_NUMBER})
exten => s,n,Set(OrigCID=${CALLERID(num)})
exten => s,n,Set(OrigCNAM=${CALLERID(name)})
exten => s,n,Set(CALLERID(num)=${num2find})
 
; Use the  lines below for AsteriDex only lookups with MYSQL
exten => s,n,Macro(cidlookup-rm, +${num2find}) ; assume dialing out is E164
exten => s,n,Set(CALLERID(name)=${lookupcid})
 
exten => s,n,Set(CONNECTEDLINE(num,i)=${DIAL_NUMBER})
exten => s,n,Set(CONNECTEDLINE(name,i)=${lookupcid})      ; for Asteridex MYSQL
;exten => s,n,Set(CONNECTEDLINE(name,i)=${USER})      ; for AsteriDex ODBC
;exten => s,n,Set(CONNECTEDLINE(name,i)=${lookupcid})  ; for CallerID Superfecta
exten => s,n,Set(CALLERID(num)=${OrigCID})
exten => s,n,Set(CALLERID(name)=${OrigCNAM})
exten => s,n,MacroExit()
;END Outbound CNAM Support
 

wardmundy

Nerd Uno
Joined
Oct 12, 2007
Messages
19,168
Reaction score
5,199
Ward, any thought of modifying this to work on a standard CID lookup source like OpenCNAM. I find that Superfecta is just too slow but if I turn it off and use my paid tier of OpenCNAM, the lookup is quite fast (on incoming calls.) I'd like to see an option where you choose your lookup from the CallerID Lookup Sources under Admin > CallerID Lookup Sources. Just a wish list item. :yes:

Edit: I manually adjusted the code to do this (actual Account SID and Auth Token substituted for post.)
Code:
; use the 6 lines below for CallerID Superfecta lookups
exten => s,n,Set(CURLOPT(httptimeout)=7)
exten => s,n,Set(CIDSFSCHEME=YmFzZV9EZWZhdWx0)
exten => s,n,Set(lookupcid=${num2find})
exten => s,n,Set(CALLERID(name)=${OrigCNAM})
;exten => s,n,AGI(/var/www/html/admin/modules/superfecta/agi/superfecta.agi)
exten => s,n,Set(lookupcid=${SHELL(curl 'https://ACCOUNT_SID:[email protected]/v2/phone/${num2find}')})
exten => s,n,Set(CALLERID(name)=${lookupcid})

This works great for a fast lookup through OpenCNAM. :clap:


This will work with the freebie account, too. No account credentials required! I added it as an option in the dialplan code...
Code:
exten => s,n,Set(lookupcid=${SHELL(curl 'https://api.opencnam.com/v2/phone/${num2find}')})
 

wardmundy

Nerd Uno
Joined
Oct 12, 2007
Messages
19,168
Reaction score
5,199
We've added OpenCNAM as the default install in Incredible PBX 11 since it requires no choices.

Beginning with version 1.3.0, you also can install OpenCNAM from the installer with this (new) syntax:
Code:
/root/install-dialout-cnam.sh opencnam
 

Rrrr

Tink
Joined
May 28, 2009
Messages
343
Reaction score
25
Question about [macro-dialout-trunk-predial-hook]:

Code:
exten => s,n,Set(CONNECTEDLINE(num,i)=${DIAL_NUMBER})

In the display, what the user will see, is the dialed number after it has been manipulated (by from-internal when it calls the Macro dialout-trunk?). This may surprise the user: eg. he dials 06123123123 and sees 496123123123 which is a non valid number as people do not understand e164 formatted numbers)

What would be nicer to the user is to present back the number he actually dialed.
I tried this, but then CONNECTEDLINE(num and name) are not being displayed.
Code:
exten => s,n,Set(CONNECTEDLINE(num,i)=${CALLERID(dnid)})

Do you know another way?

PS I have been searching in which file I can find the actual code for from-internal, but I got lost in the many included sub routines...where is it?
 

Rrrr

Tink
Joined
May 28, 2009
Messages
343
Reaction score
25
${callerid (dnid)} has a value, but ${dnid} not.
The value is: 0123123123
Perhaps the value is not a valid one?
Is there a check carried out?
 

Rrrr

Tink
Joined
May 28, 2009
Messages
343
Reaction score
25
I am at a loss:
I tried this, its working fine and I get the connectedline(name,i) on my display:
Code:
exten => s,n,Set(CONNECTEDLINE(num,i)=0650123123)
Then I tried to replace it with this:
Code:
exten => s,n,NoOp(*** DNID:${CALLERID(dnid)}***)
exten => s,n,Set(CONNECTEDLINE(num,i)=${CALLERID(dnid)})
the CLI shows
-- Executing [s@macro-dialout-trunk-predial-hook:10] NoOp("SIP/221-0000032a", "*** DNID:0650123123***") in new stack
-- Executing [s@macro-dialout-trunk-predial-hook:12] Set("SIP/221-00000328", "CONNECTEDLINE(num,i)=0650123123")
and I do NOT get the connectedline(name,i) on my display, but 0650123123 is on the display.
 

wardmundy

Nerd Uno
Joined
Oct 12, 2007
Messages
19,168
Reaction score
5,199
I think there may be more FreePBX voodoo that goes on after exiting this macro. So, if you fiddle with the num, you screw up the name.
 

Rrrr

Tink
Joined
May 28, 2009
Messages
343
Reaction score
25
:ph34r: voodoo right, I can only see [macro-dialout-trunk] ending with a normal Dial...

name is being set after setting num...

1) Can it have to do with the datatype being set differently, when assigning CONNECTEDLINE(num,i) to a number 0123123123 or to ${CALLERID(dnid)} (value 0123123123)?
(I tried and printed all datatypes, but could not find a difference yet...)

2) Can a variable in the dial plan be numeric or text and does it make a difference here?
How do I test this for ${CALLERID(dnid)}?
-----------------------
I tried the below alternatives, but no name on display, when num is being set as follows
Code:
exten => s,n,Set(CONNECTEDLINE(num,i)=${CALLERID(dnid)})
Code:
exten => s,n,Set(CONNECTEDLINE(num,i)=${FILTER(0-9,${CALLERID(dnid)})})
 

Rrrr

Tink
Joined
May 28, 2009
Messages
343
Reaction score
25
It works great, however...the issue is described in #62
I note it is probably more apparent to Europeans than USA based systems and it depends on the VOIP provider used to dial out with.
Assume the VOIP provider requires full e164 numbers.
The number presented on dial out is after manipulation by trunk settings.

Example:
In Europe one would dial 06123123123 and if the number is not found in the db, the user would see 496123123123 in the display as the number being dialed out (country code 49 for Germany), which is not a normal number as it does not start with a 0 or 00.
In the USA its less obvious but still: one would dial 650 123 4567 and if the number is not found in the db, the user would see 16501234567 in the display as the number being dialed out.
This is more acceptable for Americans, but not for Europeans.

The obvious solution is to just present DNID, which, to my frustration does not work.
Hence my efforts to try to find out why not.
 

wardmundy

Nerd Uno
Joined
Oct 12, 2007
Messages
19,168
Reaction score
5,199
Sorry, I missed it the first time. This is a FreePBX issue. Perhaps one of their developers will have some thoughts.
 

Rrrr

Tink
Joined
May 28, 2009
Messages
343
Reaction score
25
I see what you mean, I have the same pile-up of log files.
Anyone?
 

wardmundy

Nerd Uno
Joined
Oct 12, 2007
Messages
19,168
Reaction score
5,199
Just add an entry to /etc/crontab to clean up the mess every night:

Code:
30 1 * * * root rm /var/log/asterisk/cdr-csv/* >/dev/null 2>&1

p.s. I'm remembering why I hate GUIs. All of this junk is buried under the covers and you rarely find it before your entire disk fills up with... :001 9898:
 

rossiv

Guru
Joined
Oct 26, 2008
Messages
2,624
Reaction score
139
Not to bump this, but for future reference this code works fine with my Snom 870. Only downside is that it shows up after the far end answers. And sendrpid needs to be set to PAI - bug in Snom's FW I think.
 

kenn10

Well-Known Member
Joined
Dec 16, 2007
Messages
3,764
Reaction score
2,173
Works fine with my Aastra 9143 phones. Again, the caller-id does not display until the far end answers.
 

Members online

No members online now.

Forum statistics

Threads
25,778
Messages
167,504
Members
19,198
Latest member
serhii
Get 3CX - Absolutely Free!

Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.
Top