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: {{ci.text}}

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

ciThe Input Object{{ci.text}}
ccThe Context Object{{cc.selectedHotel}}
cpThe Contact Profile Object{{cp.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.

{{ci.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.

{{cc.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.


    "customer_orders": {
        "$cs": {
            "script": "cc.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.



cc.orders === 3 would be true, if the orders variable stored in the Context is 3.

Code Nodes

Within Code Nodes you don't need to use the {{ }} tags. The ci, cc, cp and actions variables are exposed by default, as are _ and moment.


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

Cognigy Objects Life Span

The picture below shows the life span of the different Cognigy objects. The Input object (ci) is created anew on each new user input (each new Flow Execution), the Context object (cc) is stored for the duration of the entire conversation, and the Profile object (cp) 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