Events & Webhooks
Example: Processing Multiple AI Agents and/or Follow-Up Responses in Dark Mode
A procedure for the automatic execution of multiple AI agents and/or customer follow-up responses
Scenario
By default, Enneo only performs automatic execution (dark processing) of AI agents upon the first incoming email of a ticket and only when exactly one AI agent has been detected. There are two scenarios where standard dark processing does not apply:
- Multiple AI agents are detected: A customer raises several concerns in the same email, e.g., a termination and a revocation. Enneo does recognize both AI agents but does not automatically execute any of them due to safety reasons.
- Follow-up responses: A customer replies to an existing ticket. While the AI processing does run (tags, AI agent recognition, parameter extraction), the automatic execution is not triggered again.
In both cases, instead, the ticket is assigned to a human operator. This behavior can be adjusted with an event hook.
Possible Solution
An event hook can react to incoming tickets or customer responses, check the detected AI agents, and trigger the automatic execution for each one.
Step 1: Set up event hook
Under Settings -> System Integration -> Events, create one or both of the following event hooks:
- TicketCreated — is triggered after receiving a new ticket and completing the AI processing. Use this if you want multiple AI agents to be executed automatically in the initial email.
- TicketResponse — is triggered when a response to an existing ticket is received from a customer, and the AI processing is completed. Use this if you also want AI agents to be automatically executed in follow-up responses.
The following code can be used for both events. It loads all recognized AI agents (intents) in ready status and runs each one individually:
POST /api/mind/ticket/:ticketId/autoexecute?executeAgentId=:aiAgentId&allowMultipleIntents=true&allowWithReplies=trueInfo
The parameter executeAgentId is the numerical ID of the AI agent to be executed. It gets set for one AI agent per call.
The parameter allowMultipleIntents=true allows the automatic execution even if multiple AI agents have been detected on the ticket. Without this parameter, execution is declined for safety reasons when multiple agents are detected.
The parameter allowWithReplies=true allows the automatic execution even if the ticket contains incoming customer responses. Without this parameter, execution is declined once there is a customer response on the ticket. This parameter is only relevant for the TicketResponse event.
Info
In this example code, error handling is deliberately omitted for better readability.
<?php
use EnneoSDK\ApiEnneo;
require(getenv()['SDK'] ?? 'sdk.php');
/** @var stdClass $in - contains all defined input parameters from the event */
// Load ticket data
$ticket = ApiEnneo::getTicket($in->ticketId);
// Only process open tickets
if ($ticket->status !== 'open') {
echo json_encode(['autoExecute' => false, 'reason' => 'Ticket is not open']);
return;
}
// Load intents (detected AI agents)
$intents = ApiEnneo::get(endpoint: '/api/mind/intent/byTicketId/' . $in->ticketId);
// Collect all intents in "ready" status
$readyIntents = array_filter($intents->intents, fn($i) => $i->status === 'ready');
if (empty($readyIntents)) {
echo json_encode(['autoExecute' => false, 'reason' => 'No intents found in ready status']);
return;
}
// Optional: Additional checks, such as customer recognition or tags
// if (!$ticket->contractId) {
// echo json_encode(['autoExecute' => false, 'reason' => 'No contract recognized']);
// return;
// }
// Optional: Automatically execute only certain AI agents
// $allowedAgentIds = [4, 5, 12, 34];
// $readyIntents = array_filter($readyIntents, fn($i) => in_array($i->aiAgentId, $allowedAgentIds));
// Execute each detected AI agent individually
$results = [];
foreach ($readyIntents as $intent) {
$result = ApiEnneo::post(
endpoint: '/api/mind/ticket/' . $in->ticketId . '/autoexecute?executeAgentId=' . $intent->aiAgentId . '&allowMultipleIntents=true&allowWithReplies=true'
);
$results[] = ['agentId' => $intent->aiAgentId, 'name' => $intent->name, 'result' => $result];
}
echo json_encode(['autoExecute' => true, 'executedAgents' => count($results), 'results' => $results]);import importlib.util
import os
import json
file_path = os.getenv('SDK', 'sdk.py')
spec = importlib.util.spec_from_file_location('sdk', file_path)
sdk = importlib.util.module_from_spec(spec)
spec.loader.exec_module(sdk)
# Load input parameters from the event
in_data = sdk.load_input_data()
# Load ticket data
ticket = sdk.ApiEnneo.get_ticket(in_data['ticketId'])
# Only process open tickets
if ticket.get('status') != 'open':
print(json.dumps({'autoExecute': False, 'reason': 'Ticket is not open'}))
exit()
# Load Intents (detected AI agents)
intents_response = sdk.ApiEnneo.get(endpoint=f'/api/mind/intent/byTicketId/{in_data["ticketId"]}')
intents = intents_response.get('intents', [])
# Collect all Intents in "ready" status
ready_intents = [i for i in intents if i.get('status') == 'ready']
if not ready_intents:
print(json.dumps({'autoExecute': False, 'reason': 'No intents found in ready status'}))
exit()
# Optional: Additional checks, for instance, customer recognition or tags
# if not ticket.get('contractId'):
# print(json.dumps({'autoExecute': False, 'reason': 'No contract recognized'}))
# exit()
# Optional: Automatically execute only certain AI agents
# allowed_agent_ids = [4, 5, 12, 34]
# ready_intents = [i for i in ready_intents if i['aiAgentId'] in allowed_agent_ids]
# Execute each detected AI agent individually
results = []
for intent in ready_intents:
agent_id = intent['aiAgentId']
result = sdk.ApiEnneo.post(
endpoint=f'/api/mind/ticket/{in_data["ticketId"]}/autoexecute?executeAgentId={agent_id}&allowMultipleIntents=true&allowWithReplies=true',
body={}
)
results.append({'agentId': agent_id, 'name': intent.get('name'), 'result': result})
print(json.dumps({'autoExecute': True, 'executedAgents': len(results), 'results': results}))Step 2: Automatic Processing by Enneo
After each call to the Autoexecute endpoint, enneo automatically carries out the following steps:
- The response created by the AI agent is sent to the customer.
- The ticket is closed.
- The ticket is marked as fully automated (L5).
In the case of multiple AI agents, each one is executed separately, and the results are processed in sequence.
Notes
- The TicketCreated event is suitable for the initial email with multiple concerns. The TicketResponse event is ideal for follow-up responses. Both events can be configured with the same code simultaneously.
- The
allowWithReplies=trueparameter is necessary because enneo standardly blocks the automatic execution as soon as an incoming customer response exists in the ticket. For the TicketCreated event, this parameter has no effect because there are no responses yet. - The
allowMultipleIntents=trueparameter is necessary because without it, execution is declined for safety reasons when multiple agents are detected. - The
executeAgentIdparameter ensures that only the desired AI agent is executed per call. - It is recommended to maintain a whitelist (
allowedAgentIds) in the code, specifying the AI agents that are allowed for automatic execution.