mirror of
https://github.com/dyrkin/luxmed-bot.git
synced 2025-12-21 13:23:05 +01:00
Slight refactoring
This commit is contained in:
@@ -27,25 +27,21 @@ trait Conversation[D] extends Actor with Domain[D] with Logger {
|
|||||||
|
|
||||||
override def receive: Receive = {
|
override def receive: Receive = {
|
||||||
case InitConversation => init()
|
case InitConversation => init()
|
||||||
case StartConversation | ContinueConversation =>
|
case StartConversation | ContinueConversation => execute()
|
||||||
try {
|
|
||||||
currentStep match {
|
|
||||||
case qa: QuestionAnswer => qa.question.questionFn(currentData)
|
|
||||||
case InternalConfiguration(fn) =>
|
|
||||||
val nextStep = fn(currentData)
|
|
||||||
moveToNextStep(nextStep)
|
|
||||||
case _ => //do nothing
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
case NonFatal(ex) => error("Step execution failed", ex)
|
|
||||||
}
|
|
||||||
case any => makeTransition(any)
|
case any => makeTransition(any)
|
||||||
}
|
}
|
||||||
|
|
||||||
private def moveToNextStep(nextStep: NextStep): Unit = {
|
def execute(): Unit = {
|
||||||
currentStep = nextStep.step
|
try {
|
||||||
nextStep.data.foreach { data =>
|
currentStep match {
|
||||||
currentData = data
|
case qa: QuestionAnswer => qa.question.questionFn(currentData)
|
||||||
|
case InternalConfiguration(fn) =>
|
||||||
|
val nextStep = fn(currentData)
|
||||||
|
moveToNextStep(nextStep)
|
||||||
|
case _ => //do nothing
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
case NonFatal(ex) => error("Step execution failed", ex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,6 +69,13 @@ trait Conversation[D] extends Actor with Domain[D] with Logger {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private def moveToNextStep(nextStep: NextStep): Unit = {
|
||||||
|
currentStep = nextStep.step
|
||||||
|
nextStep.data.foreach { data =>
|
||||||
|
currentData = data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private def init(): Unit = {
|
private def init(): Unit = {
|
||||||
require(startWithStep != null, "Entry point must be defined")
|
require(startWithStep != null, "Entry point must be defined")
|
||||||
currentStep = startWithStep
|
currentStep = startWithStep
|
||||||
|
|||||||
Reference in New Issue
Block a user