diff --git a/chatState.go b/chatState.go index a5fbe68..53acd8d 100644 --- a/chatState.go +++ b/chatState.go @@ -10,6 +10,11 @@ import ( //chat state that we might be use for collecting infomation from user type chatState struct { + //back pointer style information + OpenID string `json:"OpenID"` //whom is this belongs to + Procedure string `json:"Procedure"` //which procedure this belongs to + + //real state information Name string `json:"Name"` //state name Expire int32 `json:"Expire"` //unix timestamp when this state expire Send struct { //anything we need to send? @@ -94,19 +99,38 @@ func startProcedure(openID, procedure string) (err error) { //do the real concret work for processing the state err = processProcedureState(state) + return } -//resume a previous Procedure -func resumeProcedure(procedure string) { - +//resume a previous Procedure's state +func resumeProcedure(openID, procedure string) (err error) { + state, err := getCurrentState(openID, procedure) + if err != nil { + return + } + return processProcedureState(state) } -func stopProcedure(procedure string) { - +//finish a procedure, regardless its been finished or not +//normally not finished normally +func stopProcedure(openID, procedure string) { + path := getProcedurePath(openID, procedure) + os.Remove(path) + log.Println("Clearing [" + openID + "] @ [" + procedure + "]") } func processProcedureState(state chatState) (err error) { + //send what we need to send + if isExpired(state.Expire) { + return errors.New("State has expired " + stae.Name) + } + //mark we have sent. + + //do we need input? waiting for input + + //if not, what is next state + log.Println(state) return }