Created
June 18, 2021 08:51
-
-
Save JaniKibichi/c5ddf15f04a9dbd8c2c56383b3f09419 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.janikibichi.models.africastalking.ussd | |
object USSDFSMProtocol { | |
def props(sessionId: String): Props = Props(new USSDFSMActor(sessionId: String)) | |
final case class USSDRequest(sessionId: String, phoneNumber: String, networkCode: String, serviceCode: String, text: String) | |
final case class USSDMenu(title: String, body: String, options: String) | |
//FSM STATE | |
sealed trait USSDState | |
final case object CurrentSession extends USSDState | |
//FSM DATA | |
sealed trait USSDData | |
final case object NoSession extends USSDData | |
} | |
class USSDFSMActor(sessionId: String) extends FSM[USSDState, USSDData] { | |
startWith(CurrentSession, NoSession) | |
when(stateName = CurrentSession, stateTimeout = 360.seconds) { | |
case Event(ussdRequest: USSDRequest, NoSession) => | |
stay() | |
} | |
initialize() | |
whenUnhandled { | |
case Event(event, data) => | |
stay() | |
} | |
onTermination { | |
case _ => | |
removeOngoingSession(sessionId) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment