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

Code Nodes

Description

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 on save. 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 your code.

Code Node without and with error-Icon

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

Just as within other Nodes, ci, cc and cp 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 (https://lodash.com/) and moment (https://momentjs.com/) libraries are exposed.

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', 'http://petersfantastichats.com/img/red.png')
       .addImageOption('Green', 'DEVELOPER_DEFINED_PAYLOAD_FOR_PICKING_GREEN', 'http://petersfantastichats.com/img/green.png');

// output the reply
actions.output("test", { "_cognigy": { "_facebook": {"message": builder.buildMessage() }}});

Updated 11 months ago



Code Nodes


Suggested Edits are limited on API Reference Pages

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