Cognigy

Cognigy.AI Docs

COGNIGY.AI is the Conversational AI Platform focused on the needs of large enterprises to develop, deploy and run Conversational AI’s on any conversational channel.

Given the arising need of voice interfaces as the most natural way of communicating with brands, Cognigy was founded in 2016 by Sascha Poggemann and Phil Heltewig. Our mission: to enable all devices and applications to intelligently communicate with their users via naturally spoken or written dialogue.

Get Started

CognigyScript

CognigyScript is a superset of JavaScript which gives you access to the Input and Context objects within text and JSON.

Using CognigyScript, you can execute powerful scripts to create the replies you want to return to the client.

Within text, you write CognigyScript within {{ }} tags. Example: {{input.text}}

CognigyScript is essentially JavaScript, but has gives you access to the Cognigy objects via exposed variables:

Variable

Description

Example

input

The Input Object

{{input.text}}

context

The Context Object

{{context.selectedHotel}}

profile

The Contact Profile Object

{{profile.firstname}}

Node Arguments

Accessing the CognigyScript functionality differs between different types of arguments.

For Text arguments


Within text arguments of a Cognigy Flow Node, CognigyScript is written using {{ }} tags. It evaluated as it is written. This is indicated by the label CognigyScript above the input field.

🚧

Invalid expressions return an empty string

If the expression is invalid, an empty string is returned.

Example
{{input.text.toUpperCase()}} would return the text the client sent all in upper case.

CognigyScript in Node Arguments is always returned as string, unless you force the type to be preserved. You can do this by appending .preserveType() to your scrip.

Example
{{context.anObject.preserveType()}} will return whatever anObject is, so for example a JavaScript Object.

For JSON arguments


Within JSON arguments, a special notation { "$cs": { "script": "x", "type": "t"} } has to be used to run CognigyScript. We have to supply a script and a return type. If the return type isn't equal to the requested type, Cognigy.AI will try to convert the return type to it.

Example

{
    "customer_orders": {
        "$cs": {
            "script": "context.orders",
            "type": "object"
        }
    }
}
This would try to retrieve the orders object from the Context and assign it to customer_orders. If it doesn't exist, it would return undefined.

## IF Conditions and SWITCH Operands
---

Within conditions, CognigyScript is also written without `{{` tags. It is evaluated just like standard JavaScript would. This is indicated by the label `CognigyScript (direct)` above the input field.


[block:callout]
{
  "type": "info",
  "body": "`context.orders === 3` would be true, if the orders variable stored in the Context is 3.",
  "title": "Example"
}
[/block]

## Code Nodes
---

Within Code Nodes you don't need to use the {{ }} tags. The `input`, `context`, `profile` and `actions` variables are exposed by default, as are `_` and `moment`.

**Example**
const ordercount = context.orders;
switch(ordercount) {
    case 0:
        input.ordertext = "You ordered no items";
        actions.output('Hello', {'action': 1}); // outputs the text 'hello' with data {'action': 1}
        break;
    case 1:
        input.ordertext = "You ordered one item";
        break;
    default:
        input.ordertext = "You ordered many items";
}

Cognigy Objects Life Span

The picture below shows the life span of the different Cognigy objects. The Input object (input) is created anew on each new user input (each new Flow Execution), the Context object (context) is stored for the duration of the entire conversation, and the Profile object (profile) is stored forever. This means that information about the user that you want to persist (e.g. the name of the user), should be stored in the Profile object.

Life Span of Cognigy Objects

Updated about a month ago


CognigyScript


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.