<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.usetuner.ai/api/v1/workspaces/{workspace_id}/agents/{agent_id}/settings/alert-definitions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => 'Repeated failed identity checks',
'window_ms' => 300000,
'recipients' => [
'oncall@example.com'
],
'notification_channels' => [
'email'
],
'condition_tree' => [
'children' => [
[
'lhs' => 'call_outcome',
'op' => 'eq',
'rhs' => 'Failed',
'type' => 'predicate'
],
[
'children' => [
[
'lhs' => 'red_flag',
'op' => 'eq',
'rhs' => 'Hallucination',
'type' => 'predicate'
],
[
'lhs' => 'red_flag_count',
'op' => 'gte',
'rhs' => 3,
'type' => 'predicate'
]
],
'op' => 'OR',
'type' => 'group'
]
],
'op' => 'AND',
'type' => 'group'
],
'description' => 'Notify the support team when identity checks keep failing.',
'severity' => 'warning',
'state' => 'active',
'cooldown_ms' => 900000,
'threshold_n' => 5,
'threshold_type' => 'count',
'threshold_percentage' => 20,
'threshold_minimum' => 10
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}