Skip to content

Convert ChatScript bot code into .Flow v2 bot code using Python #6

@nicolasbotanic

Description

@nicolasbotanic

ChatScript is a bot engine with its own programming language. You can find documentation in following link (you probably won't need it as the code in our sample is very intuitive and easy to understand) https://github.com/bwilcox-1234/ChatScript

.Flow v2 is also a domain specific language for bot programming with minimal syntax. You can find the specification draft here: https://github.com/SeedVault/flow#documentation

We need a Python script to convert a ChatScript bot code into a .Flow v2 bot code.
The minimal requeriment is to convert this ChatScript code sample into the provided .Flow v2 sample below:

ChatScript code

# Ok
#! I don't like ice cream
u: id000 ( I do not like ice cream ) That's ok. Variable test2 value: $test2

# Name and Likes
u: id100 ( my name is _* and I like _* ) 
    $test = nameandlikes
    Your name is '_0 and you like '_1 ... Do you like something else?        
    # No more likes
    # Using reuse function
    a: id120 ( ~no ) $test2 = nomorelikes ^reuse(id000)
    a: id110 ( _* ) $test2 = '_0 $test3 = "nothing yet" That's great! Variable test value: $test        

Resulting .Flow v2 code

{
  "name": "sample",
  "description": "",
  "nodes": [
    {
      "id": "root",
      "name": "root",
      "description": "Root node",
      "context": [
        "global"
      ],
      "paths": [
        {
          "id": "id000",
          "name": "id000",
          "description": "Ok",
          "conditions": {
            "$chatscriptMatch": [
              "I do not like ice cream",
              {
                "$input": []
              }
            ]
          },
          "responses": [
            {
              "$text": [
                "That's ok. Variable test2 value: {test2}"
              ]
            }
          ],
          "exceptions": []
        },
        {
          "id": "id100",
          "name": "id100",
          "description": "Name and Likes",
          "conditions": {
            "$chatscriptMatch": [
              "my name is _* and I like _*",
              {
                "$input": []
              },
              [
                "id100var0",
                "id100var1"
              ]
            ]
          },
          "responses": [
            {
              "$store": [
                "test",
                "nameandlikes"
              ]
            },
            {
              "$text": [
                "Your name is {id100var0} and you like {id100var1} ... do you like something else?"
              ]
            },
            {
              "$goto": "node1"
            }
          ],
          "exceptions": []
        }
      ]
    },
    {
      "id": "node1",
      "name": "node1",
      "description": "",
      "paths": [
        {
          "id": "id110",
          "name": "id110",
          "description": "No more likes\nUsing reuse function",
          "conditions": {
            "$chatscript": [
              "~no",
              {
                "$input": []
              }
            ]
          },
          "responses": [
            {
              "$store": [
                "test2",
                "nomorelikes"
              ]
            },
            {
              "$gotoResponse": "id000"
            }
          ],
          "exceptions": []
        },
        {
          "id": "id120",
          "name": "id120",
          "description": "",
          "conditions": {
            "$chatscript": [
              "_*",
              {
                "$input": []
              },
              [
                "id120var0"
              ]
            ]
          },
          "responses": [
            {
              "$store": [
                "test2",
                {
                  "$variable": [
                    "id120var0"
                  ]
                }
              ]
            },
            {
              "$store": [
                "test3",
                "nothing yet"
              ]
            },
            {
              "$text": "That's great! Variable test value {test}"
            }
          ],
          "exceptions": []
        }
      ]
    }
  ]
}
  • Use at least these .Flow v2 functions: $chatscriptMatch, $text, $goto, $gotoResponse, $store and $variable
  • Use {} for showing interpolated variables inside texts. Use $variable function when there is no need to interpolate its value.
  • .Flow v2 does not support topics yet so no need to handle topics. Just one top file, one topic.
  • Parse unlimited ChatScript rejoinders (the nested code blocks with labels id110 and id120)
  • Only ChatScript "u" rules are currently supported. No "t" or "?" rules
  • Do not add logic into the .Flow v2 bot to follow ChatScript behavior like automatic erasing rules. Just follow explicit instructions based on the top files.
  • Support instructions in one line and multiple lines

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions