Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite Scenario DSL #139

Merged
merged 18 commits into from
Mar 9, 2021
Merged

Rewrite Scenario DSL #139

merged 18 commits into from
Mar 9, 2021

Conversation

nikvoloshin
Copy link
Contributor

@nikvoloshin nikvoloshin commented Feb 2, 2021

This PR replaces the old Scenario DSL with the new one in order to support @DslMarker

There are no major changes in DSL functions, they are the same and work like before.

The changes worth mentioning:

  • Scenarios no longer can extend ScenarioBuilder (or Scenario typealias) because of limitations of DslMarker
  • BotEngine no more requires ScenarioModel, it requires the object of new Scenario type
  • Scenario is simply a holder of ScenarioModel, so users no longer need to do MyScenario.model
  • There are multiple functions at com.justai.jaicf.builder.Scenario.kt that builds a scenario and returns Scenario object. So it's up to the user where to store Scenario object in order to pass it to BotEngine.
  • ScenarioBuilder no longer has dependencies parameters, ScenarioModel no longer has plus function. Instead more explicit append function were added. ScenarioBuilder#append is used for append another scenario to the end of this one. Scenario.append is used to append one scenario to the end of another.
  • Users are no longer allowed to define states directly on the top level of scenario building next to append or handle functions. Instead, users have to start scenario building by calling ScenarioBuilder#start function. However, there is com.justai.jaicf.builder.Scenario.kt#startScenario that allows skipping start function call, if a user doesn't need to add handlers or append other scenarios.
  • Channel-specific Scenarios! (see. telephony-example)
  • MANY WAYS TO MERGE SCENARIOS

More on creating scenarios:
To create a Scenario object a user should simply call Scenario or startScenario function.

Option 1:

val MyScenario = Scenario {
  // your scenario
}
BotEngine(scenario = MyScenario, ...)

Option 2:

object MyScenario {
  val scenario = Scenario {
    // your scenario
  }
}
BotEngine(scenario = MyScenario.scenario)

Option 3:

object MyScenario : Scenario {
  override val scenario by Scenario {
    // your scenario
  }
}
BotEngine(scenario = MyScenario)

Closes #84
Closes #42

@Denire

This comment has been minimized.

@Denire

This comment has been minimized.

Copy link
Contributor

@morfeusys morfeusys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only change I'd like to see is simplified scenarios in hello-world example that doesn't use Scenario delegation and also uses activators' type tokens inside actions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Channel-specific scenarios Fix DSL methods nesting in Scenario DSL
3 participants