Asterisk Dialplan Integration

Play a message to unknown partners

Imagine a case when you accept calls only from your partners.

So existing partners can be directly connected but new customers must first be acknowledged. To make this work you can create a special dialplan where the system first tries to find caller’s name in Odoo’s partners database.

Below you can find an example of such a dialplan.


; Set connection options for curl.
exten => _X.,1,Set(CURLOPT(conntimeout)=1)
exten => _X.,n,Set(CURLOPT(dnstimeout)=1)
exten => _X.,n,Set(CURLOPT(httptimeout)=1)
exten => _X.,n,Set(CURLOPT(ssl_verifypeer)=0)
exten => _X.,n,Return

; Set CURL options.
exten => _X.,1,Gosub(sub-setcurlopt,${EXTEN},1)
; Set caller's name into CALLER_NAME variable.
same => n,Set(CALLER_NAME=${CURL(${ODOO_URL}/asterisk_plus/get_caller_name?number=${CALLERID(number)})})
same => n,ExecIf($["${CALLER_NAME}" != ""]?found)
same => n,Playback(customer-not-found-pls-contact-sales)
same => n,Hangup()
same => n(found),Playback(welcome-customer)
same => n,Queue(support)

Dialplan configuration

Asterisk Plus exposes additional functionality by providing the following controllers:

  1. You can get the contact’s name by accessing asterisk_plus/get_caller_name?number=${CALLERID(number)}

  2. If the Contact for the phone number has a manager set, use asterisk_plus/get_partner_manager?number=${CALLERID(number)} to get the manager’s number

  3. You can get the Contact’s tags by using /asterisk_plus/get_caller_tags?number=${CALLERID(number)}

Here are some examples of integration, using Asterisk dialplans.



; Set connection options for curl.
exten => _X.,1,Set(CURLOPT(conntimeout)=3)
exten => _X.,n,Set(CURLOPT(dnstimeout)=3)
exten => _X.,n,Set(CURLOPT(httptimeout)=3)
exten => _X.,n,Set(CURLOPT(ssl_verifypeer)=0)
exten => _X.,n,Return

; Partner's extension click2call e.g. +1234567890##101
exten => s,1,NoOp(DTMF digits: ${dtmf_digits})
same => n,ExecIf($["${dtmf_digits}" = ""]?Return)
same => n,Wait(${dtmf_delay})
same => n,SendDTMF(${dtmf_digits})
same => n,Return

;Set Caller ID name from Odoo
; Get caller ID name from Odoo, replace odoo to your Odoo's hostname / IP address
; Arguments:
; - number: calling number, strip + if comes with +.
; - db: Odoo's database name, ommit if you have one db or use dbfilter.
; - country: 2 letters country code, See
; If country code is omitted Asterisk Agent's Odoo account's country settings will be used for phonenumbers parsing.

exten => _X.,1,Gosub(sub-setcurlopt,${EXTEN},1)
;   You need to cut leading + on numbers incoming from trunks before passing it to get_caller_name.
exten => _X.,n,Set(CALLERID(name)=${CURL(${ODOO_URL}/asterisk_plus/get_caller_name?number=${CALLERID(number)})})
exten => _X.,n,Return

; Get partner’s manager (salesperson) channel

exten => _X.,1,Set(manager_channel=${CURL(${ODOO_URL}/asterisk_plus/get_partner_manager?number=${CALLERID(number)})})
exten => _X.,n,ExecIf($["${manager_channel}" != ""]?Dial(${manager_channel},60,t))
exten => _X.,n,Return

; Get partner's tags to create a special call routing (e.g. VIP queue)
; You can also get caller tags from Odoo with the following controller Here is an example:

; Partner tags
; VIP - tag name in this example.

exten => _X.,1,Set(CURLOPT(conntimeout)=3)
exten => _X.,n,Set(CURLOPT(dnstimeout)=3)
exten => _X.,n,Set(CURLOPT(httptimeout)=3)
exten => _X.,n,Set(CURLOPT(ssl_verifypeer)=0)
exten => _X.,n,Set(tags=${CURL(${ODOO_URL}/asterisk_plus/get_caller_tags?number=${CALLERID(number)})})
exten => _X.,n,NoOp(Tags: ${tags})
exten => _X.,n,Set(match=${REGEX("VIP" ${tags})})
exten => _X.,n,NoOp(Match: ${match})
exten => _X.,n,Return(${match})

; Check VIP tag
exten => _X.,1,Gosub(partner-vip-tag-lookup,${EXTEN},1,VIP)
exten => _X.,n,GotoIf($["${GOSUB_RETVAL}" = "1"]?vip-queue,${EXTEN},1)

; Incoming call handling

exten => _X.,1,Gosub(sub-setcallerid,${EXTEN},1) ; Set partner's caller name
exten => _X.,n,MixMonitor(${UNIQUEID}.wav) ; Record call
exten => _X.,n,Gosub(sub-dialmanager,${EXTEN},1) ; Try to connect to manager
; Put here some logic to handle if manager channel is busy for example put in the queue.
exten => _X.,n,Queue(sales)

exten => _X.,1,MixMonitor(${UNIQUEID}.wav) ; Activate call recording.
exten => _XXXX,2,Dial(SIP/${EXTEN},30) ; Local users calling
exten => _XXXXX.,2,Dial(SIP/provider/${EXTEN},30,TU(post-dial-send-dtmf) ; Outgoing calls pattern