Procházet zdrojové kódy

state needs to be in memory for access

master
Patrick Peng Sun před 8 roky
rodič
revize
7d6600753d
1 změnil soubory, kde provedl 33 přidání a 0 odebrání
  1. +33
    -0
      chatSession.go

+ 33
- 0
chatSession.go Zobrazit soubor

UpdateAt int32 `json:"UpdateAt"` //when is this session updated UpdateAt int32 `json:"UpdateAt"` //when is this session updated
Expire int32 `json:"Expire"` //unix timestamp of when this Procedure expires Expire int32 `json:"Expire"` //unix timestamp of when this Procedure expires
KvPair map[string]string `json:"KvPair"` //key value pair persistant for this session KvPair map[string]string `json:"KvPair"` //key value pair persistant for this session
//
//
//current state for the prcedure
state chatState
} }


func writeSession(ss openIDSessionData) (err error) { func writeSession(ss openIDSessionData) (err error) {
c.KvPair[key] = val c.KvPair[key] = val
c.UpdateAt = int32(time.Now().Unix()) c.UpdateAt = int32(time.Now().Unix())
} }

//main entry point for processing each incoming message
//this stage has session date available
func (c *openIDSessionData) incomingMsg(v InWechatMsg) {
openID := v.header.FromUserName
//are we in an existing procedure
inProc, state := isInProc(openID) //if inside a procedure, resume last saved state
if inProc {
c.state = serveProc(state, v) //transit to new state
} else {
state, processed := serveCommand(openID, v) //menu or txt command e.g. search
if !processed { // transfer to Customer Service (kf)
kfSendTxt(openID, "未识别的命令,已转接校友会理事会,稍后答复您")
}
c.state = state
}

if !isEndingState(state) {
err := saveChatState(openID, state.Procedure, state)
if err != nil {
log.Println("Error Cannot Save chat sate")
log.Println(err)
log.Println(state)
}
} else { //state ending
cleanProcedure(openID, state.Procedure)
}
return
}

Načítá se…
Zrušit
Uložit