Enneo

Events & Webhooks

Example: Synchronization with another Ticket System

Synchronization of conversations for tickets with another ticket system as an example

Scenario

In some cases, it's necessary for specific tickets and their associated conversations to be available in an additional ticket system. For instance, a customer's response to a ticket request can also be displayed in the parallel running system. This can be enabled by using a webhook.

Solution

To ensure that new conversations are synchronized in both systems, a webhook can be implemented. Under Settings → Email → Email Accounts, the corresponding email account must be selected. If the webhooks on this account are not yet active, the "Enable Webhooks" switch must be turned on so that the fields for configuring the "New email" webhook appear.

Example of Customer-specific Code

Info

In this code example, error handling is deliberately omitted for better clarity.

The following PHP code uses the enneo SDK to retrieve information from a ticket system and send it to a third-party system.

<?php

use EnneoSDK\ApiEnneo;

require(getenv()['SDK'] ?? 'sdk.php');

/** @var stdClass $in - contains all the defined input parameters from the event */

// get agent profile
$agent = ApiEnneo::get('/api/mind/profile/' . $in->userId)->profile;

// get ticket details
$ticket = ApiEnneo::get('/api/mind/ticket/'. $in->ticketId .'?includeRawData=true');

// get conversations
$conversationData = ApiEnneo::get('/api/mind/ticket/' . $in->ticketId  . '/conversation?includeRawData=true');

// find current conversation
$conversation = null;
foreach ($conversationData->conversations as $c) {
    if ($c->id === $in->conversationId) {
        $conversation = $c;
        break;
    }
}

// prepare payload
$payload = [
    "ticketId" => $ticket->externalTicketId,
    "enneoId" => $ticket->id,
    "agent" => $agent,
    "conversationContent" => $conversation->bodyPlain
];

// send data to third-party-system using predefined custom code
$result = ApiEnneo::executeUdf(
    name: 'send-to-third-party',
    parameters: ['method' => 'POST', 'api' => 'redirect', 'params' => $payload]
);

echo json_encode($result);
import importlib.util
import json
import os

# Load the enneo SDK; the input parameters from the webhook are then available in input_data
spec = importlib.util.spec_from_file_location('sdk', os.getenv('SDK', 'sdk.py'))
sdk = importlib.util.module_from_spec(spec)
spec.loader.exec_module(sdk)
input_data = sdk.load_input_data()
ticket_id = input_data.get('ticketId')

# get agent profile
agent = sdk.ApiEnneo.get(f"/api/mind/profile/{input_data.get('userId')}").get('profile')

# get ticket details
ticket = sdk.ApiEnneo.get(f'/api/mind/ticket/{ticket_id}?includeRawData=true')

# get conversations
conversation_data = sdk.ApiEnneo.get(f'/api/mind/ticket/{ticket_id}/conversation?includeRawData=true')

# find current conversation
conversation = next(
    (c for c in conversation_data.get('conversations', []) if c.get('id') == input_data.get('conversationId')),
    None,
)

# prepare payload
payload = {
    'ticketId': ticket.get('externalTicketId'),
    'enneoId': ticket.get('id'),
    'agent': agent,
    'conversationContent': conversation.get('bodyPlain') if conversation else None,
}

# send data to third-party-system using predefined custom code
result = sdk.ApiEnneo.executeUdf(
    'send-to-third-party',
    {'method': 'POST', 'api': 'redirect', 'params': payload},
)

print(json.dumps(result))

In this example, the user profile is first loaded using the enneo SDK. Afterwards, extended ticket data and conversations are loaded. At the end of the code snippet, the data of the current conversation is transmitted to the external ticket system. Here, a function send-to-third-party is used, which must be previously stored as "User defined Function".