Answer the question
In order to leave comments, you need to log in
File format describing actions?
Good evening colleagues.
Theoretical questions.
How can you parse this format and perform certain actions?
For example:
{
"$kind": "Microsoft.AdaptiveDialog",
"$designer": {
"id": "433224",
"name": "EchoBot-0"
},
"autoEndDialog": true,
"defaultResultProperty": "dialog.result",
"triggers": [
{
"$kind": "Microsoft.OnUnknownIntent",
"$designer": {
"id": "821845"
},
"actions": [
{
"$kind": "Microsoft.SendActivity",
"$designer": {
"id": "003038"
},
"activity": "${SendActivity_003038()}"
}
]
},
{
"$kind": "Microsoft.OnConversationUpdateActivity",
"$designer": {
"id": "376720"
},
"actions": [
{
"$kind": "Microsoft.Foreach",
"$designer": {
"id": "518944",
"name": "Loop: for each item"
},
"itemsProperty": "turn.Activity.membersAdded",
"actions": [
{
"$kind": "Microsoft.IfCondition",
"$designer": {
"id": "641773",
"name": "Branch: if/else"
},
"condition": "string(dialog.foreach.value.id) != string(turn.Activity.Recipient.id)",
"actions": [
{
"$kind": "Microsoft.SendActivity",
"$designer": {
"id": "859266",
"name": "Send a response"
},
"activity": "${SendActivity_Welcome()}"
}
]
}
]
}
]
},
{
"$kind": "Microsoft.OnActivity",
"$designer": {
"id": "pv7CmQ"
},
"actions": [
{
"$kind": "Microsoft.SendActivity",
"$designer": {
"id": "hUW5JC"
},
"activity": "${SendActivity_hUW5JC()}"
},
{
"$kind": "Microsoft.TextInput",
"$designer": {
"id": "yXxTFP"
},
"disabled": false,
"maxTurnCount": 3,
"alwaysPrompt": false,
"allowInterruptions": false,
"prompt": "${TextInput_Prompt_yXxTFP()}",
"property": "user.name"
},
{
"$kind": "Microsoft.IfCondition",
"$designer": {
"id": "HCfN1O"
},
"condition": "user.name.length > 10",
"actions": [
{
"$kind": "Microsoft.SendActivity",
"$designer": {
"id": "LCUNef"
},
"activity": "${SendActivity_LCUNef()}"
}
],
"elseActions": [
{
"$kind": "Microsoft.SendActivity",
"$designer": {
"id": "hDfr7K"
},
"activity": "${SendActivity_hDfr7K()}"
}
]
}
]
}
],
"generator": "echobot-0.lg",
"$schema": "https://raw.githubusercontent.com/microsoft/BotFramework-Composer/stable/Composer/packages/server/schemas/sdk.schema"
}
Answer the question
In order to leave comments, you need to log in
The file appears to be in json format. Google "json <your programming language>" to find a library to parse this format. Then it is necessary to process the semantics of the language.
The "$designer" fields seem to be ignored. Next, each important element has a "$kind" field. Read the description in the diagram, which is the link at the end of the file " https://raw.githubusercontent.com/microsoft/BotFra... "
In fact, this is a given program in a programming language that is very inconvenient for a person. Each action is a node in json. It has a kind that defines what kind of instruction it is and any additional fields that describe the parameters of this instruction. The branch instruction type contains commands for both branches of execution and a condition. This language seems to have loops, built-in functions. It looks like the user can set some of his own functions, the call of which you will also have to handle.
After parsing the file with a json parser, you need to write a processing for each type of action that is in this file. It will be a full-fledged interpreter of this strange programming language.
For example, "Microsoft.ForEach". Look for this line in the diagram, it will occur 6 times. Interesting place No. 3 - it describes what fields this type of action can have. There are a bunch of obvious fields like designer and kind, but there is the "actions" we need. The description says that this is an array of actions that will be called on all elements of the list. Those. having met the foreach node in the file, you need to take the "actions" field and apply all actions from there to all elements of the input list.
And so it is necessary to write processing for each "kind" action. The easiest way to write it is in some interpreted language, where there is something like eval (). Because, for example, in IfCondition there is a condition field that will have to be calculated. It will be necessary to maintain some kind of dictionary for all variables, local and global, maintain a call stack and a dictionary of all known user subroutines.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question