mirror of
https://github.com/dyrkin/luxmed-bot.git
synced 2025-12-21 13:23:05 +01:00
Print step name for unhandled message
This commit is contained in:
@@ -59,4 +59,9 @@ trait Logger {
|
|||||||
log.info(msg)
|
log.info(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def trace(msg: => String): Unit = {
|
||||||
|
if (log.isTraceEnabled)
|
||||||
|
log.trace(msg)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ dependencies {
|
|||||||
compile project(':bot')
|
compile project(':bot')
|
||||||
compile project(':common')
|
compile project(':common')
|
||||||
|
|
||||||
|
compile('com.lihaoyi:sourcecode_2.12:0.1.4')
|
||||||
|
|
||||||
compile('org.springframework.boot:spring-boot-starter')
|
compile('org.springframework.boot:spring-boot-starter')
|
||||||
compile('org.springframework.boot:spring-boot-starter-data-jpa')
|
compile('org.springframework.boot:spring-boot-starter-data-jpa')
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ trait StaticDataForBooking extends Conversation[BookingData] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected def staticData(staticDataConfig: => StaticDataConfig)(functions: BookingData => Step => MessageProcessorFn)(requestNext: Step): Step = {
|
protected def staticData(staticDataConfig: => StaticDataConfig)(functions: BookingData => Step => MessageProcessorFn)(requestNext: Step)(implicit functionName: sourcecode.Name): Step = {
|
||||||
ask { _ =>
|
ask { _ =>
|
||||||
staticData ! InitConversation
|
staticData ! InitConversation
|
||||||
staticData ! StartConversation
|
staticData ! StartConversation
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ trait Conversation[D] extends Actor with Domain[D] with Logger {
|
|||||||
|
|
||||||
private val defaultMsgHandler: MessageProcessorFn = {
|
private val defaultMsgHandler: MessageProcessorFn = {
|
||||||
case Msg(any, data) =>
|
case Msg(any, data) =>
|
||||||
debug(s"Unhandled message received. [$any, $data]")
|
warn(s"Unhandled message received in step '${currentStep.stepName}'. Message: [$any]. Data: [$data]")
|
||||||
NextStep(currentStep, Some(data))
|
NextStep(currentStep, Some(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ trait Conversation[D] extends Actor with Domain[D] with Logger {
|
|||||||
try {
|
try {
|
||||||
currentStep match {
|
currentStep match {
|
||||||
case qa: Dialogue => qa.askFn(currentData)
|
case qa: Dialogue => qa.askFn(currentData)
|
||||||
case Process(fn) =>
|
case Process(_, fn) =>
|
||||||
val nextStep = fn(currentData)
|
val nextStep = fn(currentData)
|
||||||
moveToNextStep(nextStep)
|
moveToNextStep(nextStep)
|
||||||
case _ => //do nothing
|
case _ => //do nothing
|
||||||
@@ -56,10 +56,10 @@ trait Conversation[D] extends Actor with Domain[D] with Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
currentStep match {
|
currentStep match {
|
||||||
case Dialogue(_, fn) =>
|
case Dialogue(_, _, fn) =>
|
||||||
val fact = Msg(any, currentData)
|
val fact = Msg(any, currentData)
|
||||||
handle(fact, fn, msgHandler)
|
handle(fact, fn, msgHandler)
|
||||||
case Monologue(fn) =>
|
case Monologue(_, fn) =>
|
||||||
val fact = Msg(any, currentData)
|
val fact = Msg(any, currentData)
|
||||||
handle(fact, fn, msgHandler)
|
handle(fact, fn, msgHandler)
|
||||||
case _ => //do nothing
|
case _ => //do nothing
|
||||||
@@ -67,6 +67,7 @@ trait Conversation[D] extends Actor with Domain[D] with Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private def moveToNextStep(nextStep: NextStep): Unit = {
|
private def moveToNextStep(nextStep: NextStep): Unit = {
|
||||||
|
debug(s"Moving from step '${currentStep.stepName}' to step '${nextStep.step.stepName}'")
|
||||||
currentStep = nextStep.step
|
currentStep = nextStep.step
|
||||||
nextStep.data.foreach { data =>
|
nextStep.data.foreach { data =>
|
||||||
currentData = data
|
currentData = data
|
||||||
@@ -84,14 +85,20 @@ trait Conversation[D] extends Actor with Domain[D] with Logger {
|
|||||||
init()
|
init()
|
||||||
}
|
}
|
||||||
|
|
||||||
protected def monologue(answerFn: MessageProcessorFn): Monologue = Monologue(answerFn)
|
protected def monologue(answerFn: MessageProcessorFn)(implicit functionName: sourcecode.Name): Monologue = Monologue(functionName.value, answerFn)
|
||||||
|
|
||||||
protected def ask(askFn: D => Unit): Ask = Ask(askFn)
|
protected def ask(askFn: D => Unit): Ask = Ask(askFn)
|
||||||
|
|
||||||
protected def process(processFn: ProcessFn): Process = Process(processFn)
|
protected def process(processFn: ProcessFn)(implicit functionName: sourcecode.Name): Process = Process(functionName.value, processFn)
|
||||||
|
|
||||||
protected def end(): NextStep = NextStep(End)
|
protected def end(): NextStep = NextStep(End)
|
||||||
|
|
||||||
|
protected implicit class AskOps(ask: Ask) {
|
||||||
|
def onReply(replyProcessorFn: MessageProcessorFn)(implicit functionName: sourcecode.Name): Dialogue = {
|
||||||
|
Dialogue(functionName.value, ask.askFn, replyProcessorFn)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected def goto(step: Step): NextStep = {
|
protected def goto(step: Step): NextStep = {
|
||||||
self ! ContinueConversation
|
self ! ContinueConversation
|
||||||
NextStep(step)
|
NextStep(step)
|
||||||
|
|||||||
@@ -9,24 +9,24 @@ trait Domain[D] {
|
|||||||
|
|
||||||
protected case class Msg(message: Any, data: D)
|
protected case class Msg(message: Any, data: D)
|
||||||
|
|
||||||
sealed trait Step
|
sealed trait Step {
|
||||||
|
def stepName: String
|
||||||
|
}
|
||||||
|
|
||||||
private[conversation] object End extends Step
|
private[conversation] object End extends Step {
|
||||||
|
val stepName: String = "end"
|
||||||
|
}
|
||||||
|
|
||||||
protected case class Process(processFn: ProcessFn) extends Step
|
protected case class Process(stepName: String, processFn: ProcessFn) extends Step
|
||||||
|
|
||||||
protected case class Dialogue(askFn: AskFn, replyProcessorFn: MessageProcessorFn) extends Step
|
protected case class Dialogue(stepName: String, askFn: AskFn, replyProcessorFn: MessageProcessorFn) extends Step
|
||||||
|
|
||||||
protected case class Monologue(replyProcessorFn: MessageProcessorFn) extends Step
|
protected case class Monologue(stepName: String, replyProcessorFn: MessageProcessorFn) extends Step
|
||||||
|
|
||||||
private[conversation] case class NextStep(step: Step, data: Option[D] = None)
|
private[conversation] case class NextStep(step: Step, data: Option[D] = None)
|
||||||
|
|
||||||
private[conversation] case class Ask(askFn: AskFn)
|
private[conversation] case class Ask(askFn: AskFn)
|
||||||
|
|
||||||
protected implicit class RichQuestion(ask: Ask) {
|
|
||||||
def onReply(replyProcessorFn: MessageProcessorFn): Dialogue = Dialogue(ask.askFn, replyProcessorFn)
|
|
||||||
}
|
|
||||||
|
|
||||||
protected implicit class NextStepOps(nextStep: NextStep) {
|
protected implicit class NextStepOps(nextStep: NextStep) {
|
||||||
def using(data: D): NextStep = {
|
def using(data: D): NextStep = {
|
||||||
nextStep.copy(data = Some(data))
|
nextStep.copy(data = Some(data))
|
||||||
|
|||||||
Reference in New Issue
Block a user