Package: Engine-Conversation
Class: Conversation
Introduction
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
.
Instance Method
Category: accessing
currentInput
- Returns the current input of the conversation as a string.httpHeaders
- Returns an object of type HTTPHeader that contains all the http headers passed from the client to the server.httpRequestBody
- Returns an object of type HTTPRequestBody that contains the http request body passed from the client to the server.parameters
- Returns an object of type Parameter 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
For example:
webhook
- Returns an object of type RuntimeWebHook that contains all the information about the runtime webhook request.
Category: advance operations
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.
Class: HTTPHeader
Introduction
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:
Class Method
Category: accessing
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.
Category: removing
removeKey:
- Remove the HTTPHeader with the given name.
Class: HTTPRequestBody
Introduction
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.
Instance Method
Category: accessing
rawData
- Get the raw data of the HTTP request body.
Category: reflective operations
doesNotUnderstand:
- By default, for any message that is not understood by a HTTPRequestBody object, the message will be forwarded to the request body dictionary, which can unerstand all messages for a Dictionary class.If the body of the request is a JSON object, you can extract the 'user_name' key value in this way:
Class: Parameter
Introduction
Environment: container
A key-value pair is known as a parameter object within the context of this conversation.
It inherits from the Dictionary
class, so it has all the methods of a dictionary.
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.
Class Method
Category: accessing
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.
Category: reflective operations
doesNotUnderstand:
- By default, for any message that is not understood by a Parameter object, the message will be forwarded to a class Dictionary, which can unerstand all messages for a Dictionary class.
Class: RuntimeWebHook
Introduction
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.
Instance Method
Category: accessing
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.statusCode
- The HTTP status code from the webhook response. It's an integer value like 200, 404, etc. See the wiki page for more details.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.
Last updated