| @@ -26,6 +26,6 @@ func (m *procDummyDef) summary(ss *openIDSessionData) { | |||
| } | |||
| func (m *procDummyDef) intro(ss *openIDSessionData) { | |||
| func (m *procDummyDef) intro(ss *openIDSessionData, in InWechatMsg) { | |||
| } | |||
| @@ -62,7 +62,8 @@ func (m *procEchoDef) summary(ss *openIDSessionData) { | |||
| kfSendTxt(ss.OpenID, msg) | |||
| } | |||
| func (m *procEchoDef) intro(ss *openIDSessionData) { | |||
| func (m *procEchoDef) intro(ss *openIDSessionData, in InWechatMsg) { | |||
| in.replyText("请输入不同类型的微信信息,比如文字,图片,视频,地址,链接,我们将原样回应您") | |||
| kfSendTxt(ss.OpenID, "10分钟静默之后 Echo将自动结束,\n输入 [结束Echo],或者语音 ‘退出退出', 清除Echo模式") | |||
| } | |||
| @@ -85,7 +86,7 @@ func (m *procEchoDef) doCommand(ss *openIDSessionData, in InWechatMsg) { | |||
| m := in.body.(VoiceMsg) | |||
| str = buildVoiceMsg(openID, m.MediaId) | |||
| in.replyXML(str) | |||
| procEcho.recordMsg(ss, "音译:"+m.Recognition) | |||
| procEcho.recordMsg(ss, "音译:"+m.Recognition) | |||
| kfSendTxt(openID, "翻译结果:"+m.Recognition) | |||
| case VideoMsg: | |||
| m := in.body.(VideoMsg) | |||
| @@ -12,7 +12,7 @@ func (m *getBasicUserInfoDef) init(ss *openIDSessionData) { | |||
| } | |||
| func (m *getBasicUserInfoDef) clean(ss *openIDSessionData) { | |||
| ss.Procedure = "" | |||
| } | |||
| func (m *getBasicUserInfoDef) start(ss *openIDSessionData, in InWechatMsg) { | |||
| @@ -25,6 +25,6 @@ func (m *getBasicUserInfoDef) summary(ss *openIDSessionData) { | |||
| } | |||
| func (m *getBasicUserInfoDef) intro(ss *openIDSessionData) { | |||
| func (m *getBasicUserInfoDef) intro(ss *openIDSessionData, in InWechatMsg) { | |||
| } | |||
| @@ -27,16 +27,16 @@ type chatProcedure interface { | |||
| start(*openIDSessionData, InWechatMsg) //for first message | |||
| serve(*openIDSessionData, InWechatMsg) //for all subsequent message | |||
| summary(*openIDSessionData) //after all message has been done | |||
| intro(*openIDSessionData) //initial text/video/voice introduction | |||
| intro(*openIDSessionData, InWechatMsg) //initial text/video/voice introduction | |||
| } | |||
| //AllProc all procedure that we implemented | |||
| var AllProc = map[string]chatProcedure{} | |||
| func initAllProc() { | |||
| registerProc("Dummy", &procDummy) | |||
| //registerProc("Dummy", &procDummy) | |||
| registerProc("Echo", &procEcho) | |||
| registerProc("GetUserBasicInfo", &procGetBasicUserInfo) | |||
| registerProc("用户信息", &procGetBasicUserInfo) | |||
| } | |||
| func registerProc(id string, proc chatProcedure) { | |||
| @@ -13,8 +13,7 @@ var commandMap = map[string]commandFunction{ | |||
| "版本信息": cmdVersion, | |||
| "version": cmdVersion, | |||
| //"所有命令": allCommand, //include it will cause initialization loop | |||
| "echo": cmdEcho, | |||
| "回音": cmdEcho, | |||
| "回音": cmdEcho, | |||
| } | |||
| func (ss *openIDSessionData) serveCommand(in InWechatMsg) (processed bool) { | |||
| @@ -55,6 +54,14 @@ func (ss *openIDSessionData) serveTextCommand(in InWechatMsg) (processed bool) { | |||
| if cmd == "所有命令" || cmd == "all command" { | |||
| return allCommand(ss, in) | |||
| } | |||
| if proc, hasProc := AllProc[cmd]; hasProc { | |||
| proc.init(ss) | |||
| proc.intro(ss, in) | |||
| //proc.start(ss, in) | |||
| processed = true | |||
| return true | |||
| } | |||
| } | |||
| return false //不认识的命令,我们选择这个信息不处理 | |||
| } | |||
| @@ -68,6 +75,11 @@ func allCommand(ss *openIDSessionData, in InWechatMsg) (processed bool) { | |||
| msg = msg + fmt.Sprintf("%0d : %s \n", count, k) | |||
| } | |||
| for k := range AllProc { | |||
| count++ | |||
| msg = msg + fmt.Sprintf("%0d : %s \n", count, k) | |||
| } | |||
| in.replyText(msg) | |||
| return | |||
| } | |||
| @@ -80,9 +92,8 @@ func cmdVersion(ss *openIDSessionData, in InWechatMsg) (processed bool) { | |||
| func cmdEcho(ss *openIDSessionData, in InWechatMsg) (processed bool) { | |||
| processed = true | |||
| in.replyText("请输入不同类型的微信信息,比如文字,图片,视频,地址,链接,我们将原样回应您") | |||
| procEcho.init(ss) | |||
| procEcho.intro(ss) | |||
| procEcho.intro(ss, in) | |||
| procEcho.start(ss, in) | |||
| return | |||
| } | |||