A way to "extract" the name of who call from a phonebook in cdr?

I want to see the name of who call (defined by me of course).
Actually I use this solution

on extensions.conf


same => n,ExecIf($["${CALLERID(all)}" = "phone <13444>"]?set(CDR(userfield)=My friend))

and then define a userfield voice in cdr (mysql or static).

When I receive call from phone 13444 appear “My friend” name in cdr table (select userfield from cdr). The problem is if my friend became 10 or 50 or more different contacts, I have to define 50 or more contacts in extensions.conf . Is possible to define a “phonebook” and then extract the name to cdr?

On Tuesday 28 January 2025 at 17:38:25, pnirru via Asterisk Community wrote:

I want to see the name of who call (defined by me of course).

Is possible to define a “phonebook” and then extract the name to cdr?

I would use a database such as MariaDB to store the phonebook, and ODBC to
query it from Asterisk.

Something like:

set up ODBC to connect to a database (maybe on the local machine, maybe
remote, depends on what you can set up most easily). Then define:

/etc/asterisk/func_odbc.conf
[Phonebook]
dsn=Asterisk
readsql=Select CDRname from phonebook where CallerID=‘${ARG1}’

and then in your dialplan:

same => n,set(CDR(userfield)=${ODBC_Phonebook(${CALLERID(all)})})

Your database should have a table named phonebook with two fields named
CallerID and CDRname, for example:

CallerID='phone <13444>'
CDRname='My friend'

Antony.


“Good health” is merely the slowest rate at which you can die.

                                               Please reply to the list;
                                                     please *don't* CC me.
1 Like

http://www.asteriskdocs.org/en/3rd_Edition/asterisk-book-html-chunk/asterisk-DB.html

(Note this is quite old, and some of the database drivers may no longer be supported.)

1 Like

Thanks works fine, but I don’t understand why not in my sip “inbound” context.


[telecom]
exten => _XXXXX.,1,NoOp()
same => n,Set(CALLERID(number)=12233456)
same => n,Dial(PJSIP/${EXTEN}@tim-uscita,30,tTkK)
same => n,Hangup()

exten = +912233456,1,Answer()
same => n,Verbose(2, Chiamata in entrata da "${CALLERID(num)}")
same => n,Set(CALLERID(num)=${CALLERID(num):3})
same => n,Set(CDR(original_dst)=${PHONEEXTNUMBER})
same => n,Dial(${TELEFONOANALOGICO1}&${TELEFONOANALOGICO2}&${TELEFONOANALOGICO5}&${TELEFONOSIP1},20,tTkK)
same => n,set(CDR(userfield)=${ODBC_Phonebook(${CALLERID(all)})})
same => n,GotoIf($["${DIALSTATUS}" = "BUSY"]?busy:unavail)                              ;se è occupato invia a busy altrimenti unavail
same => n(unavail),VoiceMail(12233456@interni,u)                                         ;voicemail, argomento mailbox@contesto
same => n,Hangup()                                                                      ;chiude
same => n(busy),VoiceMail($12233456@interni,b)                                            ;voicemail per busy
same => n,Hangup()

In this one works perfect


[subDialUser]
exten => _[0-9].,1,Noop(Dial extension ${EXTEN},channel: ${ARG1}, mailbox: ${ARG2})     ;definiamo le variabili
same => n,Noop(mboxcontext: ${ARG3}, timeout ${ARG4})                                   ;idem
same => n,ExecIf($["${CALLERID(num)}" = "4001"]?set(CALLERID(all)=Telefono Analogico 1 <4001>))
same => n,ExecIf($["${CALLERID(num)}" = "4002"]?set(CALLERID(all)=Telefono Analogico 2 <4002>))
same => n,ExecIf($["${CALLERID(num)}" = "4003"]?set(CALLERID(all)=Telefono Analogico 3 <4003>))
same => n,ExecIf($["${CALLERID(num)}" = "4004"]?set(CALLERID(all)=Telefono Analogico 4 <4004>))
same => n,ExecIf($["${CALLERID(num)}" = "4005"]?set(CALLERID(all)=Telefono Analogico 5 <4005>))
same => n,ExecIf($["${CALLERID(num)}" = "12233456"]?set(CALLERID(all)=Telefono SIP<12233456>))
same => n,set(CDR(userfield)=${ODBC_Phonebook(${CALLERID(all)})})
same => n,Dial(${ARG1},${ARG4},tTkK)                                                         ;chiama canale,timeout
same => n,GotoIf($["${DIALSTATUS}" = "BUSY"]?busy:unavail)                              ;se è occupato invia a busy altrimenti unavail
same => n(unavail),VoiceMail(${ARG2}@${ARG3},u)                                         ;voicemail, argomento mailbox@contesto
same => n,Hangup()                                                                      ;chiude
same => n(busy),VoiceMail(${ARG2}@${ARG3},b)                                            ;voicemail per busy
same => n,Hangup()

Consider for my internal context the callerid arrive as this

| 2025-01-31 00:38:09 | "Telefono Analogico 1" <4001> | Mirko Rossi |
| 2025-01-31 00:47:11 | "" <+912345678>               |             |
| 2025-01-31 00:47:11 | "" <+912345678>               |             |
| 2025-01-31 00:47:11 | "" <+912345678>               |             |
| 2025-01-31 00:47:14 | "" <12345678>                 |             |
| 2025-01-31 00:47:14 | "" <12345678>                 |             |
| 2025-01-31 00:47:14 | "" <12345678>                 |             |

I have tried using CALLERID(num) instead of all but still don’t work

EDIT: works fine, only I had to insert the sql data like this one

insert into phonebook (CDRname, CallerID) values (‘Myname’,‘012345667’);

Thanks for help