Asterisk dialplan

Dialplan snippets for integration with Odoo.

Max Li avatar
Written by Max Li
Updated over a week ago

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.

extensions.conf:

[globals]
ODOO_URL=http://odoo:8069

; Set connection options for curl.
[sub-setcurlopt]
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
[post-dial-send-dtmf]
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 https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
; If country code is omitted Asterisk Agent's Odoo account's country settings will be used for phonenumbers parsing.

[sub-setcallerid]
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

[sub-dialmanager]
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.

[partner-vip-tag-lookup]
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
[check-vip]
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

[from-sip-external]
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)

[from-internal]
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

Did this answer your question?