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