Writing conditional text outputs within CognigyScript Fields

Challenge

Is it possible to customize the output text from a messaging node from within the text field itself?

Solution

Yes! In Cognigy.AI, all CognigyScript fields (indicated by the "AI" button) support javascript conditional statements. This means that you can write a conditional statement, similar to as would be entered in the IF Node, within any CognigyScript field to make a decision between multiple output options.

Here is an example of one such statement:

Use Case: We want to use the plural form of the word "item" in a sentence when anything other than 1 item is ordered, but we only want to have to configure this in a single message output.

You can use the following phrase to achieve this:

You ordered {{ input.slots.NUMBER[0] }} {{ (input.slots.NUMBER[0] === 1)?"item":"items" }}

 

ScreenshotSayNodeLogic.PNG

In output nodes (like Say nodes or Questions nodes) Cognigy evaluates CognigyScript and determines a string output, in this case 'item' or 'items'. In the above example, Cognigy looks at the first number slot match and determines the right output based on the slot value.

Comments

0 comments

Please sign in to leave a comment.

Was this article helpful?
0 out of 0 found this helpful