Skip to content



Code Nodes enable a Flow creator to execute custom JavaScript or TypeScript code within the Flow. The editor has full IntelliSense and exposes all Cognigy objects and actions. For better performance, the TypeScript code will be transpiled when the node is saved. If the transpilation fails the code will be saved and an error icon will appear in the top right corner of the Code Node, indicating that there is a potential issue with the code.

The execution of the Code Node will be synchronous, the Flow will continue after the Code Node has finished executing.

Maximum Execution Time

Code Nodes are set by default to run for a maximum of 1000 ms before returning an error. This value is currently not configurable. To execute code that takes longer to execute, we recommend using custom Extensions. The error can be accessed under input.codeNodeError.message

Just as within other Nodes, input, context and profile can be accessed (and modified) within Code Nodes. If the script crashes or takes longer than one second to execute, it will be stopped and throw an error. In case of an uncaught error, the Flow Execution will be stopped.

The actions object provides access to most internal node functions within the Code Node.

For convenience, the lodash ( and moment ( libraries are exposed for use within Code Nodes.

Sending Facebook JSON

You can send Facebook JSON directly from within Code Nodes using the output action. You can do this in two ways:

  • Writing the JSON yourself

    // build the faceboook reply
    const obj = {
        "_cognigy": {
            "_facebook": {      
                "message": {
                    "text": "Hello World",
                    "quick_replies": [
                            "content_type": "text",
                            "condition": "",
                            "title": "Hi",
                            "image_url": "",
                            "payload": "Hi"
    // output the reply
    actions.output("test", obj);

  • Using the facebook-bot-messenger module (more information on GitHub

    // use facebook-bot-messenger to compile reply
    const builder = new MessengerPlatform.QuickRepliesMessageBuilder('Pick a color:');
    builder.addImageOption('Red', 'DEVELOPER_DEFINED_PAYLOAD_FOR_PICKING_RED', '')
        .addImageOption('Green', 'DEVELOPER_DEFINED_PAYLOAD_FOR_PICKING_GREEN', '');
    // output the reply
    actions.output("test", { "_cognigy": { "_facebook": {"message": builder.buildMessage() }}});

Auto-completion in Code-Nodes Editor

When using the "input." operator in the Node Editor of a "Code-Node", all available input objects will be automatically displayed e.g.