Enneo allows storing of custom code in the form of “User Defined Functions” and use it in various areas . These functions can be effectively utilized in the business logic of rule-based AI agents, in webhooks or Event implementations. Basically, wherever custom code or SDKs are used.

Managing User Defined Functions

User defined functions can be managed in the Systems Integration area in the settings. Here, any number of custom functions can be stored.

Functions are stored as code fragments that implement specific application logic and are available in various integration scenarios.

Applications

User Defined Functions provide a variety of applications. For example:

  • Interfaces of the surrounding systems: For instance, for ERP, Task Management, or Archive Systems.
  • Connection of Output Management Systems: For example, for sending out notifications.
  • Outsourcing of complex procedures: In the form of reusable components.

With these functionalities, Enneo enhances adaptability and enables the integration of specific company logic into AI-based customer support.

Calling User Defined Functions

Enneo can store and use user defined functions. The following calls are possible, for example with a user-defined function named ‘my-udf’:

Within Enneo using Python SDK:

sdk.ApiEnneo.executeUdf('my-udf', {"parameter1": "value1", "parameter2": "value2"}, 'serviceWorker')

Within Enneo using PHP SDK:

\EnneoSDK\ApiEnneo::executeUdf('my-udf', ['parameter1' => 'value1', 'parameter2' => 'value2'],'serviceWorker');

Via an external web request:

    POST https://your-subdomain.enneo.ai/api/mind/executor/execute/my-udf
    Payload: '{"parameter1": "value1", "parameter2": "value2"}'

Storage Object for User Defined Functions

Any JSON object can be used as an internal Enneo storage object for custom functions. This allows data to be stored and retrieved using the Enneo SDK.

\EnneoSDK\Setting::set('udfStorage', ['my' => 'data']);
$storedData = \EnneoSDK\Setting::get('udfStorage');

Example: Calling the API of a third-party system

First, the necessary data is set in the storage object for user defined functions:

{
  "thirdParty": {
    "oauth": {
      "clientId": "123456789",
      "grantType": "client_credentials",
      "clientSecret": "abcdefg.....hijklmnop",
      "tokenEndpoint": "https://token-url/oauth2/token",
      "baseUrl": "https://third-party-url/api"
    }
  }
}

In the second step, a custom function fetch-thirdparty-token can be implemented to load the credentials. This approach is particularly useful when the loading of credentials can be reused in several other processes.

<?php

// Load Enneo SDK
require(getenv()['SDK']);

// Load storage object for user defined functions
$udfStorage = \EnneoSDK\Setting::get('udfStorage');


// Load token
$clientId = $udfStorage->thirdParty->oauth->clientId;
$clientSecret = $udfStorage->thirdParty->oauth->clientSecret;

$result = \EnneoSDK\Api::call(
    method: 'POST',
    url: $udfStorage->thirdParty->oauth->tokenEndpoint,
    headers: [
        'Authorization: Basic ' . base64_encode($clientId . ':' . $clientSecret),
        'Content-Type: application/x-www-form-urlencoded',
        'Accept: application/json'
    ],
    params: http_build_query(['grant_type' => $udfStorage->thirdParty->oauth->grantType ?? 'client_credentials',
        'scope' => $udfStorage->thirdParty->oauth->scope ?? null])
);

// The output is in JSON format and can be used in the appropriate code after the call
echo json_encode(['accessToken' => $result->access_token,
    'accessTokenExpiresAt' => date("Y-m-d H:i:s T", time() + $result->expires_in),
    "baseUrl" => $udfStorage->thirdParty->baseUrl,
    "headers" => $udfStorage->thirdParty->headers ?? [],
    "apiName" => $udfStorage->thirdParty->apiName ?? "Customer API",
]);

Subsequently, the function third-party-api-call can be implemented for the actual API call:

<?php
<?php

// Load SDK
require(getenv()['SDK']);

// Load token using previously defined "fetch-thirdparty-token" function
$credentials = \EnneoSDK\ApiEnneo::executeUdf('fetch-thirdparty-token', []);

// Load input parameters
$in = \EnneoSDK\Input::load();

// Prepare headers for the third-party API request
$headers = [
    'Authorization: Bearer '. $credentials->accessToken,
    'Accept: application/json'
];
foreach (($cred->headers ?? []) as $key => $val) {
    $headers[] = "$key: $val";
}

// Make the API call and output
$res = \EnneoSDK\Api::call(
    method: $in->method,
    url: $credentials->baseUrl.'/'.$in->api,
    headers: $headers,
    params: $in->params
);

// Output result
echo json_encode($res);

This structure allows for flexible use and integration of custom code within Enneo, to map specific business logic or to seamlessly connect external systems.

Calling Custom Functions

Custom functions in the code are called using executeUdf:

<?php

// Load Enneo SDK
require(getenv()['SDK']);

// Prepare payload for the API call of the third-party system
$payload = [
    'ticket-id' => 123,
    'key' => 'value'
];

// Call the custom function "third-party-api-call"
// this function takes an object as an input parameter:
// [
//      'method' => 'POST',
//      'api' => 'item',
//      'params' => [
//          'ticket-id' => 123,
//           'key' => 'value'
//      ]
// ]
EnneoSDK\ApiEnneo::executeUdf(
    'third-party-api-call',
    ['method' => 'POST', 'api' => 'item', 'params' => $payload]
);