Skip to content

Functions

Introduction

Cognigy Functions are Code Blocks that can be run inside your Cognigy.AI installation and help you with long-running asynchronous processes, e.g. interaction with third-party systems HTTP APIs.

Maximum runtime

By default, the maximum runtime for an instance of a Cognigy Function is limited to 15 minutes. On-premise customers with their own Cognigy.AI installation can adjust this limit.

They are independent of Flows but can be triggered from a Flow and can also use the "inject" and "notify" APIs to send their results back into a Flow.

When running a Function, you can pass additional parameters which are then available in the Function Code.

You can start using Functions by navigating to "Functions" in the "Build" section of the Agent Sidebar.

Configuration and Monitoring

The "Function Editor" lets you define a Code snippet in JavaScript or TypeScript language.

You can access the parameters and api objects from the Function's arguments.

Interacting with Third-Party Systems

You can use HTTP requests to interact with third-party systems.

const response = await api.httpRequest({
    method: "get",
    url: "https://example.com/api/v2",
    headers: {
        "Accept": "application/json"
    }
});

Interacting with Flows

You can use Functions to interact with Flows using the Inject & Notify APIs. The following examples assume that you pass the userId, sessionId and URLToken through the Function's Parameters.

const { userId, sessionId, URLToken } = parameters;

api.inject({
    userId,
    sessionId,
    URLToken,
    text: "This text was injected though a Function"
});

Performing a "Norify" call

const { userId, sessionId, URLToken } = parameters;

api.notify({
    userId,
    sessionId,
    URLToken,
    text: "This text was injected though a Function"
});

Monitoring

By switching to the "Instances" Tab, you can see an execution history for the currently edited Function. Each execution will list its current execution status, the trigger source, the start time and the finish time.

By hovering an item, you can also see the parameters that were provided for this individual execution.

Triggering a Function

Cognigy Functions can be triggered in three different ways: By pressing the "Run" button in the UI, by executing a "Trigger Function" Node or by calling the REST API.

Using the UI

While visiting the "Function Editor" page for a Function, you can click the "Run" button on the top left of the page. This will run the Function without parameters. If you want to also provide parameters, you can click the "Arrow Button" next to the "Run" button. This will open a Dialog where you can define additional parameters as a JSON object.

Using the REST API

You can trigger a Function by using the REST API, documented in our OpenAPI documentation.

Using a Node

It is also possible to trigger a Function from a Flow by using the Trigger Function Node.

Back to top