Jump to content

Recommended Posts

Posted

I have recently started to investigate to figure out how I can instruct kazoo to route the call to my specified resource from Click2Call API. With suggestions from 2600hz community forum and after some trial & error, finally, I am able to design a solution to achieve this goal.

Let’s first understand my goal in detail. For example, I have two remote PBX (asterisk1 & asterisk2) which I have added as resources in kazoo. Both asterisk1 and asterisk2 instances have the same extension 70003. Now if I use clicktocall for dialing 70003, how can I instruct kazoo from clicktocall so that it will dial 70003@asterisk1, not 70003@asterisk2? As I am calling ClicktoCall API from my web app and resource selection logic is also resides in my web app, somehow I need to tell ClicktoCall API which resource to route the call while invoking from the web app.

To accomplish this, I have used The rules key on the resource which matches the number dialled. Actually, I have added a unique prefix before the regex pattern in the rules key for each resource. The rules key supports capture groups, in parenthesis. Those will throw away whatever is outside the parenthesis before sending it to the resource. As per my example, For the Asterisk1 resource, I am putting “1(.{5})” for the value of rules, and For the Asterisk2 resource, I am putting “2(.{5})” for the value of rules. So when my web app hits my clicktocall endpoint with the dialled extension of 270003, it will get sent through Asterisk server #2 as 70003. When my clicktocall executes 170003, it will send the call to 70003 on Asterisk server 1, etc.

Resource Details

Details of my resource setup are as below

Asterisk1

{

“data”: {

“name”: “Asterisk1”,

“format_from_uri”: true,

“rules”: [

“1(.{5})”

],

“flags”: [

“Use_Asterisk1”

],

“weight_cost”: 60,

“formatters”: {

“diversion”: [

{

“match_invite_format”: true,

“direction”: “outbound”

}

],

“outbound_caller_id_number”: [

{

“value”: “70001”

}

],

“outbound_caller_id_name”: [

{

“value”: “kazoo”

}

]

},

“gateways”: [

{

“caller_id_type”: “external”,

“channel_selection”: “ascending”,

“codecs”: [

“PCMU”,

“PCMA”,

“OPUS”

],

“custom_sip_headers”: {},

“emergency”: false,

“enabled”: true,

“endpoint_type”: “sip”,

“format_from_uri”: true,

“invite_format”: “route”,

“password”: “asterisk1_password”,

“prefix”: “”,

“progress_timeout”: 30,

“realm”: “asterisk1_ip”,

“server”: “asterisk1_ip”,

“skype_rr”: false,

“suffix”: “”,

“username”: “asterisk1_username”,

“force_port”: false,

“port”: 5060

}

],

“emergency”: false,

“enabled”: true,

“from_account_realm”: false,

“grace_period”: 5,

“rules_test”: [],

“id”: “c1ad847e401cb9c7a3f264a2840b2fff”

},

“revision”: “26-db769ea7891fb82a1d2425a2fe269814”,

“timestamp”: “2021–11–01T20:20:14Z”,

“version”: “4.3.140”,

“node”: “yMeslQexQufV5c-zOCJ0Ow”,

“request_id”: “d20e9b4223a47931f4d19b0a5012ddc8”,

“status”: “success”,

“auth_token”: “auth_token”

}

Asterisk 2

{

“data”: {

“name”: “Asterisk”,

“format_from_uri”: true,

“rules”: [

“2(.{5})”

],

“flags”: [

“Use_Asterisk2”

],

“weight_cost”: 70,

“formatters”: {

“diversion”: [

{

“match_invite_format”: true,

“direction”: “outbound”

}

],

“outbound_caller_id_number”: [

{

“value”: “70001”

}

],

“outbound_caller_id_name”: [

{

“value”: “kazoo”

}

]

},

“gateways”: [

{

“caller_id_type”: “external”,

“channel_selection”: “ascending”,

“codecs”: [

“PCMU”,

“PCMA”,

“OPUS”

],

“custom_sip_headers”: {},

“emergency”: false,

“enabled”: true,

“endpoint_type”: “sip”,

“format_from_uri”: true,

“invite_format”: “route”,

“password”: “asterisk2_password”,

“prefix”: “”,

“progress_timeout”: 30,

“realm”: “asterisk2_ip”,

“server”: “asterisk2_ip”,

“skype_rr”: false,

“suffix”: “”,

“username”: “asterisk2_username”,

“force_port”: false,

“port”: 5060

}

],

“emergency”: false,

“enabled”: true,

“from_account_realm”: false,

“grace_period”: 5,

“rules_test”: [],

“id”: “c1ad847e401cb9c7a3f264a2840b2fff”

},

“revision”: “26-db769ea7891fb82a1d2425a2fe269814”,

“timestamp”: “2021–11–01T20:20:14Z”,

“version”: “4.3.140”,

“node”: “yMeslQexQufV5c-zOCJ0Ow”,

“request_id”: “d20e9b4223a47931f4d19b0a5012ddc8”,

“status”: “success”,

“auth_token”: “auth_token”

}

So if my web app decides, it needs to make call to 70003 extension of Asterisk1 instance, then it will append prefix 1 for Asterisk1 (Setup in rules for Asterisk1 described earlier) before the extension 70003 in the value of contact field.

https://crossbarserver.tld/v2/accounts/5123456789098765432abcd/clicktocall/my_cool_pivot_c2c/connect?contact=170003

Similarly, if my web app decides, it needs to make call to 70003 extension of Asterisk2 instance,then it will append prefix 2 for Asterisk2 (Setup in rules for Asterisk1 described earlier) before the extension 70003 in the value of contact field.

https://crossbarserver.tld/v2/accounts/5123456789098765432abcd/clicktocall/my_cool_pivot_c2c/connect?contact=270003

×
×
  • Create New...