This site is no longer updated.Go to new Conversational Cloud docs

Managing the context


noContext

You can specify the noContext flag for the state tag, which takes a boolean value (false by default).

If noContext=true, the system will not change the context when it switches to a state with that flag. The next request will be processed in the context of the previous one in this case.

Consider the following script:

theme: /
	state: Greeting
		q!: * (hi/good (~day/~morning/~evening)) *
		a: Hello! How are you doing?

		state: DoinGood
			q: * (good/ok/fine) *
			a: I am glad you are fine! How can I help you?

		state: DoinBad
			q: * (bad|not [really] good) *
			a: Sorry to hear that. Maybe I can help?

	state: CatchAll
		event!: noMatch
		a: Sorry, I don’t understand you. Please try to rephrase.

Greet the chat bot and answer I am OK to the How are you doing? question. The pattern does not cover that answer, so the script will switch to the CatchAll state and the chat bot will ask to rephrase. Say well, everything is fine. Although the pattern is matched, the request will not be recognized as the context of the conversation has changed and nested states are not available.


Set the noContext flag to the CatchAll state:

theme: /
	state: Greeting
		q!: * (hi/good (~day/~morning/~evening)) *
		a: Hello! How are you doing?

		state: DoinGood
			q: * (good/ok/fine) *
			a: I am glad you are fine! How can I help you?

		state: DoinBad
			q: * (bad|not [really] good) *
			a: Sorry to hear that. Maybe I can help?

	state: CatchAll || noContext=true
		event!: noMatch
		a: Sorry, I don’t understand you. Please try to rephrase.

When we switch to the CatchAll state now, the context will not change and the next request will be processed within the Greeting state. So, the well, everything is fine response will be processed in the context of the How are you doing? state and will switch to the DoinGood nested state.

The noContext flag is used to avoid moving the conversation context forward. It is usually used in CatchAll states or in repeated replies.


modal

You can specify the modal flag for the state tag, which takes a boolean value (false by default).

If modal=true, the system will process the request in the context of that state, i.e. the request can only be switched to one of its nested states. If the nested states have no matching answer and the local CatchAll state is missing, the system will return an error. The error log will tell you that no state to switch to was found in the script.

States with the modal=true flag are used when you need some important information from the client that is required for the conversation to go on.

How to use:

theme: /

	state: OrderStatus|| modal = true
		q!: * (where|status) * ~of order *
		a: Hello! Please specify your order number.

		state: GetNumber
			q: * $Number *
			a: Your order is underway!
			go!: /WhatElse

		state: LocalCatchAll
			event: noMatch
			a: This does not look like an order number. Please try again.

	state: WhatElse
		a: How else can I help you?

The user wants to get the status of their order in this script and is prompted to specify the order number. modal = true prevents the conversation from exiting the order number prompt context until the required information is specified.

Use the go tag or the fromState flag to exit a modal state.

Include LocalCatchAll in your script to avoid conversation errors.


fromState

The fromState flag can be set for the q tag and defines a state from which a switch can be made based on this pattern.

You can use the fromState flag to address a question from a certain context to a desired state without using global pattern, or to exit the modal context at a certain request.

How to use:

theme: /

	state: OrderStatus || modal = true
		q!: * (where|status) * ~of order *
		a: Hello! Please specify your order number.

		state: GetNumber
			q: * $Number *
			a: Your order is underway!
			go!: /WhatElse

		state: LocalCatchAll
			event: noMatch
			a: This does not look like an order number. Please try again.

	state: WhatElse
		a: How else can I help you?

	state: Question
		q!: * [answer me] (a/some) question* *
        q: l* [answer me] (a/some) question* * || fromState = /OrderStatus
        a: Of course, I am listening!

Here the client exits the modal state if he or she has a question to the bot.


onlyThisState

The onlyThisState flag is set for the q tag and is used together with the fromState flag.

If the onlyThisState=true flag is set, a switch based on the pattern with that flag can only be made from the state specified in the fromState flag — but not from nested states.

If the onlyThisState flag is not set, the switch can also be made from nested states of the fromState state.

How to use:

theme: /

	state: OrderStatus || modal = true
		q!: * (where|status) * ~of order *
		a: Hello! Please specify your order number.

		state: GetNumber
			q: * $Number *
			a: Your order is underway!
			go!: /WhatElse

		state: LocalCatchAll
			event: noMatch
			a: This does not look like an order number. Please try again.

	state: WhatElse
		a: How else can I help you?

	state: Question
		q!: * [answer me] (a/some) question* *
        q: * [answer me] (a/some) question* * || fromState = /OrderStatus, onlyThisState = true
        a: Of course, I am listening!

In the fromState example, you could switch to /Question from either /OrderStatus or /OrderStatus/LocalCatchAll; but here you can only switch from /OrderStatus.