Example configuration Microsoft Power Automate to send a notification whenever an agent is in a reasoncode state for longer than x seconds
Introduction
This example shows you how you can use Microsoft Power Automate to automatically send you a notification whenever the threshold for an agent to be on a specific reason code is met
Preview:
Configuration
-
Navigate to Microsoft Power Automate.
-
Click "My Flows":
-
Click "New" and "Create from Blank":
-
Type "Recurrence" and provide the recurrence rate in seconds.
Note
Microsoft Power Automate limits the recurrence rate to a minimum of 60 seconds
-
Next you need to initialize 6 variables; to do so add an Action and type Initialize Variable. Repeat this step for each of the variables below.
The first variable is created to store all the uris that have exceeded the KPI threshold. Name the variable, change the type to "String" and leave the value empty.
The second variable is created to store the reasoncode name. Name the variable, change the type to "String" and enter the ReasonCode name.
In the third variable you store the amount of seconds that the KPI needs to meet before sending the notification. Name the variable, change the type to "Integer" and enter an amount (in seconds).
Because Microsoft Flow calculates time from an UTC 0 perspective, you need to correct the timestamps. This variable contains the total hours your timezone differs from UTC 0. This value can be negative. Name the variable, change the type to "Integer" and enter an amount (in hours).
The fifth variable is created to calculate the time the flow is running in your timezone. Name the variable, change the type to "String" and enter:
The last variable is created to store the trigger time later in the flow. Name the variable, change the type to "String" and leave the value empty.
-
Add an Action and type HTTP. This will create an API request, in which it will retrieve data from the AnywhereNow Core API. As method select "GET" and for the URI fill in your Core API:
-
Add an Action and select "Parse JSON". In the content slot select "Body" from the HTTP Output
CopyJSON{
"type":"array",
"items":{
"type":"object",
"properties":{
"SipAddress":{
"type":"string"
},
"PresenceState":{
"type":"integer"
},
"LastPresenceChange":{
"type":"string"
},
"ReasonCode":{
"type":"string"
},
"LastReasonCodeChange":{
"type":"string"
},
"IsFormal":{
"type":"boolean"
}
}
}
} -
Add an Action and type Apply to each and select "Body" from the parse JSON step in the Select an output from previous steps
-
Add an Action and type Set Variable and select Variable 5.6. As value fill in:
CopyExpressionaddSeconds(items('Apply_to_each')?['LastPresenceChange'], variables('NAME OF VARIABLE 5.2'), 'yyyy-MM-dd hh:mm:ss')
replace fill the name of variable 5.2 in the designated spot
-
Add and Action and type Condition. For this condition you need to have 2 conditions in the "And" form
First select variable 5.6. as operator select "is less or equal to"; select variable 5.5 to compare it too
-
The following steps are added in the "If Yes" side of the condition action. There will be no actions for this flow under the "If No" side
Add an Action and type "Compose". Under the expressions tab enter:
CopyExpressionconcat(items('Apply_to_each')?['SipAddress'], ' is on ', variables('ReasonCodeValue'), ' longer than ', variables('Seconds On ReasonCode'), ' seconds')
-
Add an Action and type "Compose". Under the "Dynamic Content " tab, select Output of the previous Compose action and the variable you created at "Step 5.1". Separate them with a line break.
-
Add an Action and type "Set Variable ". Select the variable from the previous step (created at step 5.1) and under value select the output from the previous step
-
Add an Action and type "Compose". As value, select the variable you created at step 5.1
-
Outside the for each action, add and Action and type Condition. As first value type "not(empty(variables('Variable 5.1')))". as operator select "is not equal to". In the second field, under the expression tab, type "true" (without the "")
-
Under the "if No" side, you need to add the final Action, which sends you a notification. You can either chose to send a notification or send out an email to specific email addresses. In this example we chose for an Outlook Email, as this allows for multiple supervisors addresses
CopyExpressionHi,
Currently one or more of your agents are on @{variables('5.2')} for more than your KPI value.
These are the agents that have exceeded the threshold:
@{variables('5.1')}
Please advise your <span class="mc-variable Variables-Global.CompName variable">AnywhereNow</span> Snapper or Inflight Wallboard for more information