Earlier I wrote " AMI. Versatile Originate. Application in CTI application ". At that time, it seemed to me that the topic was solved, exhausted. But it turned out there is room for improvement.
Classic Originate
Action: Originate
Channel: PJSIP/201
Context: all-peers
Exten: 203
Priority: 1
Callerid: 201
All-peers context example
[all-peers]
exten => _X!,1,Dial(${PJSIP_DIAL_CONTACTS(${EXTEN})},30,Tt)
same => n,Hangup()
201 will call 203
callerid at 201 will be displayed as 201 (the value of the " Callerid " parameter in the Originate command )
callerid at 203 to display as 201 - everything is beautiful
2021-05-17 16:34:17|2021-05-17 16:34:20|2021-05-17 16:34:32|201|PJSIP/201-0000000a|203|PJSIP/203-0000000b
.
:
201 , , ,
, 201 contact. , 201
extensions.conf
[internal-orig]
exten => _X!,1,Set(DST_CONTACT=${PJSIP_DIAL_CONTACTS(${EXTEN})})
same => n,ExecIf($["${DST_CONTACT}x" != "x"]?Dial(${DST_CONTACT},30,Tt))
Originate :
Action: Originate
Channel: Local/201@internal-orig
Context: all-peers
Exten: 203
Priority: 1
Callerid: 201
, . , CDR :
2021-05-17 17:01:09|2021-05-17 17:01:12|2021-05-17 17:01:17|203|Local/201@internal-orig-00000006;2|201|PJSIP/201-00000012
2021-05-17 17:01:09|2021-05-17 17:01:12|2021-05-17 17:01:17|201|Local/201@internal-orig-00000006;1|203|PJSIP/203-00000013
Local
, .
CallerID
AMI origCid=203:
Action: Originate
Channel: Local/201@internal-orig
Context: all-peers
Exten: 203
Priority: 1
Callerid: 201
Variable: origCid=203
"Exten" AMI.
dialplan:
[internal-orig]
exten => _X!,1,Set(D_CONT=${PJSIP_DIAL_CONTACTS(${EXTEN})})
same => n,Set(CALLERID(num)=${origCid})
same => n,ExecIf($["${D_CONT}x" != "x"]?Dial(${D_CONT},${ringlength},Tt))
callerid.
CDR
. .
:
Local (hangup)
Local CDR
.
" " ( Local) U(orig-answer-channel) Dial
orig-answer-channel :
[orig-answer-channel]
exten => s,1,Set(MASTER_CHANNEL(O_SRC_CHAN)=${CHANNEL})
same => n,return
- .
. Local " " :
[all-peers]
exten => _X!,1,ExecIf($[ "${O_SRC_CHAN}x" != "x" ]?ChannelRedirect(${O_SRC_CHAN},${CONTEXT},${EXTEN},1))
same => n,ExecIf($[ "${O_SRC_CHAN}x" != "x" ]?Hangup())
same => n,Dial(${PJSIP_DIAL_CONTACTS(${EXTEN})},30,Tt)
same => n,Hangup()
"all-peers" Local . verbose :
Executing [203@all-peers:1] ExecIf("Local/201@internal-orig-00000009;1", "1?NoCDR()")
Executing [203@all-peers:2] ExecIf("Local/201@internal-orig-00000009;1", "1?ChannelRedirect(PJSIP/201-00000016,all-peers,203,1)")
Executing [203@all-peers:3] ExecIf("Local/201@internal-orig-00000009;1", "1?Hangup()")
"ChannelRedirect" , Local .
Executing [203@all-peers:1] ExecIf("PJSIP/201-00000016", "0?NoCDR()")
Executing [203@all-peers:2] ExecIf("PJSIP/201-00000016", "0?ChannelRedirect(,all-peers,203,1)")
Executing [203@all-peers:3] ExecIf("PJSIP/201-00000016", "0?Hangup()")
Executing [203@all-peers:4] Dial("PJSIP/201-00000016", "PJSIP/203/sip:203@172.16.156.1:59442;ob,30,Tt")
"all-peers" , sip , Originate .
It remains only to add NoCDR to remove cdr records of Local channels.
Final option
The AMI command will take the form:
Action: Originate
Channel: Local/201@internal-orig
Context: all-peers
Exten: 203
Priority: 1
Callerid: 201
Variable: origCid=203
The final dialplan, notice the two NoCDR calls in it :
[internal-orig]
exten => _X!,1,NoCDR()
same => n,Set(MASTER_CHANNEL(O_DST_CHAN)=${origCid})
same => n,Set(CALLERID(num)=${origCid})
same => n,Set(DST_CONTACT=${PJSIP_DIAL_CONTACTS(${EXTEN})})
same => n,ExecIf($["${DST_CONTACT}x" != "x"]?Dial(${DST_CONTACT},${ringlength},TtU(orig-answer-channel),s,1)))
[orig-answer-channel]
exten => s,1,Set(MASTER_CHANNEL(O_SRC_CHAN)=${CHANNEL})
same => n,return
[all-peers]
exten => _X!,1,ExecIf($[ "${O_SRC_CHAN}x" != "x" ]?NoCDR())
same => n,ExecIf($[ "${O_SRC_CHAN}x" != "x" ]?ChannelRedirect(${O_SRC_CHAN},${CONTEXT},${O_DST_CHAN},1))
same => n,ExecIf($[ "${O_SRC_CHAN}x" != "x" ]?Hangup())
same => n,Dial(${PJSIP_DIAL_CONTACTS(${EXTEN})},30,Tt)
same => n,Hangup()
One record will be stored in the CDR
2021-05-17 17:29:07|2021-05-17 17:29:10|2021-05-17 17:29:14|201|PJSIP/201-00000018|203|PJSIP/203-00000019
What you need! :)
Outcomes
I am not suggesting that this is the only solution. Also, I am not claiming that it is acceptable to everyone and is true. I like the implementation, I was pleased with the experience and the result.
We successfully applied the described technique in our free open source PBX MikoPBX .