Conversation context

This section describes how external calls work, as well as receiving input and returning output data.

Conversation context

Conversation context is a set of variables, that you may use during the conversation. You can define input, output and additional context variables.

context { // Input context variables input input_var1: number = 0; input input_var2: string | null; // Additional context variables context_var1: number = 0; context_var2: string | null // Output context variables output output_var1: number = 0; output output_var2: string | null; }

The context variables can then be used at any time by prefixing their name with $:

start node Root { do { #log($input_var1); #log($context_var2); #log($output_var1); } }

Conversation input context

Input context is used to define variables and access values that you need as input. This could be information about the interlocutor or any other data.

Each field of the object is passed to your DashaScript application as a corresponding context variable. For that, it should be declared with an input modifier, and of an appropriate data type:

context { input foo: number = 0; // each input variable must either have a default value input bar: string | null; // or be of a nullable type }

To set input data in SDK part pass an object with values to createConversation().

const dasha = require("@dasha.ai/sdk"); const app = await dasha.deploy("path/to/app"); const conv = app.createConversation({ foo: 123, });

It can also be modified at any time before the start of a conversation, via the input property of a conversation object:

conv.input.bar = "aaa";

Conversation output context

Output context is used to define result variables. In the end of the conversation you may need access result conversation data. For example, it could be conversation status or gathered information from interlocutor.

In DashaScript, conversation output variables are declared similarly to the input ones. Use output modifier:

context { output foo: number = 0; // they also must either have a default value output bar: string | null; // or be of a nullable type }

When a conversation has successfully finished, its output is passed along in the output property of the conversation result object. Don't forget to assign values to this variables.

const result = await conv.execute(); console.log(result.output.foo); console.log(result.output.bar);
Found a mistake? Let us know.

Enroll in beta

Request invite to our private Beta program for developers to join the waitlist. No spam, we promise.