Getting the call count (inbound and outbound) using a Data Action

Hi,

We would like to retrieve the current callcount for inbound and outbound calls.
So that we based on those values can make some decisions in routing.

I found the API request that can provide the data, and it almost works except that I don't see the data, if I look at the log I can see that the request succeeded but I have no data I can use.

The request is for multiple trunkIDs the ideal situation would be if the get back the total for inbound and the total for outbound.

What am I missing here?

Best regards,
Rob

GetTrunkStatisticsv1-20200925111608.custom.json (1.6 KB)

Hello,

There are different things to take into account.

The "/api/v2/telephony/providers/edges/trunks/metrics" returns an array of objects.
I mean: [ {...}, {...}]

When you specify multiple trunks using the trunkIds query parameter, the values are comma separated. But when sending the request, you will need to escape the commas. I mean , becomes %2C.
I have managed this in the Data Action Configuration Request using $esc.url macro.

As a comment on the TrunkIds (you may have noticed that already - but just for the sake of this explanation):
if you have configured a Trunk (in the Genesys Desktop Admin UI - Telephony Trunks), and you have 2 Virtual Edges, you will have a trunkId for the first Edge and a second trunkId for the second Edge.
You can check and get your TrunkIds using "/api/v2/telephony/providers/edges/trunks"

In my Data Action below, in the translationMap, I am retrieving the values for inboundCallCount and outboundCallCount using a JSONPath expression, which builds an array of integers (as a matter of fact, not exactly an array...).
"inboundCallsArrayAsStr": "$[*].calls.inboundCallCount"
The $[*] is the JSONPath expression to get all objects contained in the array we got in the API Response.

Now I need to add the values.
One way to do this would be to return the JSONPath arrays in my Data Action, and then use a Sum() function in an Architect expression.
But that wouldn't be fun enough :slight_smile:

To make the sum in the Data Action, we can use the $math macros .
But that is why I said the JSONPath array is not really an array in our translationMap.
It is in fact considered as a string which contains "[1, 0, 2, ...]" and we can't pass this variable directly to the getTotal function (in math macros).
So we will need to work around this - we will parse and convert the translationMap variable to go from "[1, 0, 2, ..]." to an array of integers using a velocity macro.

#set ($inboundCallsArray = $inboundCallsArrayAsStr.replace(\"[\", \"\").replace(\"]\", \"\").replace(\" \", \"\").split(\",\"))

We can then make the sum with:

$math.getTotal(${inboundCallsArray})

And here is the final Data Action I have used.

Input Contract:

{
  "type": "object",
  "required": [
    "trunkIds"
  ],
  "properties": {
    "trunkIds": {
      "type": "string"
    }
  },
  "additionalProperties": true
}

Output Contract:

{
  "type": "object",
  "properties": {
    "nbInboundCalls": {
      "type": "integer"
    },
    "nbOutboundCalls": {
      "type": "integer"
    }
  },
  "additionalProperties": true
}

Configuration Request:

{
  "requestUrlTemplate": "/api/v2/telephony/providers/edges/trunks/metrics?trunkIds=$esc.url(${input.trunkIds})",
  "requestType": "GET",
  "headers": {
    "Content-Type": "application/json"
  },
  "requestTemplate": "${input.rawRequest}"
}

Configuration Response:

{
  "translationMap": {
    "inboundCallsArrayAsStr": "$[*].calls.inboundCallCount",
    "outboundCallsArrayAsStr": "$[*].calls.outboundCallCount"
  },
  "translationMapDefaults": {
    "inboundCallsArrayAsStr": "[0]",
    "outboundCallsArrayAsStr": "[0]"
  },
  "successTemplate": "#set ($inboundCallsArray = $inboundCallsArrayAsStr.replace(\"[\", \"\").replace(\"]\", \"\").replace(\" \", \"\").split(\",\")) #set ($outboundCallsArray = $outboundCallsArrayAsStr.replace(\"[\", \"\").replace(\"]\", \"\").replace(\" \", \"\").split(\",\")) {\"nbInboundCalls\":$math.getTotal(${inboundCallsArray}), \"nbOutboundCalls\":$math.getTotal(${outboundCallsArray})}"
}

Hope this helps.

Regards,

Hi Jerome,

This does more than help, thank you very much for the explanation and the code. :+1:
It's exactly what I was looking for.

Best regards,
Rob

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.