Package: Engine-Conversation
Last updated
Was this helpful?
Last updated
Was this helpful?
Environment: container
A conversation object is a container for all the information related to current conversation.
It is the start point to write covnersation rules in a subject. In the rules, you can access the conversation object by using the variable self
or conversation
.
For example, to bind a parameter from a http header, you can write:
All attributes for a conversation object are listed below in category accessing
.
currentInput
- Returns the current input of the conversation as a string.
httpHeaders
- Returns an object of type that contains all the http headers passed from the client to the server.
httpRequestBody
- Returns an object of type that contains the http request body passed from the client to the server.
parameters
- Returns an object of type that contains all the parameters in current scope.
predefinedSubject:
- Returns a predefined subject object of the given subject type.
The subject type can be one of the following:
#:introduction
#:conclusion
#:webhook
For example:
webhook
- Returns an object of type that contains all the information about the runtime webhook request.
awaitHTTPResponse:
- Wait for the HTTP response from the given HTTP client asynchronously.
The conversation will be paused at this point and will be resumed after the HTTP response is received. All responses before this point will be sent to the client.
For example:
check:
- ask for the check step for the parameter value of a given parameter.
The parameter name is given as a string.
For example:
response:
- Show a message as a response.
For example:
At the present moment, it is utilized solely for debugging purposes, allowing us to display additional information during the development of the subject.
Environment: container
A key-value pair is known as a HTTPHeader object for current conversation.
The origin of the initial values of http headers can be
the subject configurations for a web hook call
Such http headers are only accessable in before/after rules for a web hook.
additional http headers when requesting a conversation to Mind Expression.
Such http headers are accessable in all rules.
The key name, a string, serves as the HTTP header name, while the value, also a string, corresponds to the http header value.
To retrieve the value of a http header, you can utilize the following syntax:
Below is an example of setting a default value of a http header:
at:
- Get the value of the HTTPHeader with specified name for current webhook.
at:ifAbsent:
- Get the value of the HTTPHeader with specified name, and specify a default value if absent.
The parameter for the default value can be:
a code block, which will be evaluated if the HTTPHeader is absent.
a value, which will be returned if the HTTPHeader is absent.
at:put:
- Update the value of the HTTPHeader with specified name.
headers
- Get all the HTTP headers as a Dictionary object.
removeKey:
- Remove the HTTPHeader with the given name.
Environment: container
The HTTPRequestBody class represents the body of an HTTP request in current conversation.
This class provides a convenient way to interact with the content of an HTTP request, whether it's a raw string or a structured JSON object.
If the body of the HTTP request is not a json object, you can retrieve it directly by method rawData
.
If the body contains a JSON object, you can interact with it as if it's a dictionary
, allowing you to retrieve values by their keys.
rawData
- Get the raw data of the HTTP request body.
If the body of the request is a JSON object, you can extract the 'user_name' key value in this way:
Environment: container
A key-value pair is known as a parameter object within the context of this conversation.
The parameter's name, given as a string, serves as the key, while its value, also a string, corresponds to the parameter's value.
To retrieve the value of a parameter, you can utilize the following syntax:
Below is an example of setting the value of a parameter:
When extracting a parameter from a web hook response using jsonpath, it will retrieve multiple matching values.
For instance, if the parameter cash_flow
is created using the jsonpath expression $.cash_flow
, the extraction process should be as follows:
By default, the scope of a parameter is local to current subject, but you can also set the scope to global by using the following syntax:
That means, the parameter a_global_parameter
will be available to all subjects within the current scope.
at:
- Get the specified parameter's value with the provided name within the current subject's scope. A default value is returned if the parameter is not set, provided that a default value is available.
at:put:
- Update the specified local parameter's value with the provided name within the current subject's scope.
at:put:as:
- Update the parameter's value with the given name at the specified scope.
The scope can be:
#local
- the parameter will be valid in current subject.
#global
- the parameter will be valid in all subjects.
getSourceOf:
- Get the data source of the parameter with specified name.
The possible data source can be
#:input
- the value of the parameter is derived from the query.
#:history
- the value of the parameter is derived from the previous query.
#:webhook
- the value of the parameter is derived from a web hook response.
#:rules
- the value of the parameter is derived by MindScript rules.
#:default
- The value of the parameter is derived from the default value.
#':http-headers'
- the value of the parameter is derived from http headers.
nil - the data source of the parameter is not available.
at:whenBoundSetHandler:
- Register a block closure to handle the event when the value of the parameter is bound.
For example, if the parameter y
depends on the parameter x
, and we want to reset y
when x
changes, we can write:
removeKey:
- Remove the association for the given parameter by its name.
Environment: container
This class would correspond to the runtime web hooks that are involved in the actual live conversation, handling the HTTP requests and responses.
method
- the HTTP method of the webhook.
It can be one of the following values:
#:get
#:post
request
- The body string of the webhook request; only applicable for POST requests.
If the request is a json string, we can extract the json object by using the following code:
response
- the response string of the webhook.
If the resonse is a json string, we can extract the json object by using the following code:
response
is only available in after rules for a webhook.
When write a rule, we can stop the execution of the rule when webhook fails by using the following code:
statusCode
is only available in after rules for a webhook.
url
- This is the actual URL used to call the webhook, also known as the rendered URL of the webhook.
The HTTP client is an object of type .
doesNotUnderstand:
- By default, for any message that is not understood by a HTTPHeader object, the message will be forwarded to a class , which can unerstand all messages for a Dictionary class.
doesNotUnderstand:
- By default, for any message that is not understood by a HTTPRequestBody object, the message will be forwarded to the request body , which can unerstand all messages for a Dictionary class.
It inherits from the Dictionary
class, so it has all the methods of a .
doesNotUnderstand:
- By default, for any message that is not understood by a Parameter object, the message will be forwarded to a class , which can unerstand all messages for a Dictionary class.
statusCode
- The HTTP status code from the webhook response. It's an integer value like 200, 404, etc. See for more details.