Przeglądaj źródła

echo server first version done.

master
Patrick Peng Sun 8 lat temu
rodzic
commit
3a00e3c045
1 zmienionych plików z 28 dodań i 16 usunięć
  1. +28
    -16
      procEcho.go

+ 28
- 16
procEcho.go Wyświetl plik

@@ -18,20 +18,33 @@ var procEcho = chatProcedure{
}

func echoInit(ss *openIDSessionData) {
ss.Procedure = idProcEcho
ss.setProcedure(idProcEcho)
ss.refreshExpire(600)
}

func echoClean(ss *openIDSessionData) {
ss.Procedure = ""
log.Println(*ss)
}

func echoStart(ss *openIDSessionData, in InWechatMsg) {
echoCommand(ss, in)
}

func echoServe(ss *openIDSessionData, in InWechatMsg) {
if in.header.MsgType == "text" {
if in.body.(TextMsg).Content == "结束Echo" {
in.replyText("echo 正式结束")
echoClean(ss)
return
}
}

ss.refreshExpire(600)
echoCommand(ss, in)
kfSendTxt(ss.OpenID, "10 分钟之后 Echo将自动结束,\n输入 [结束Echo] 清除Echo模式")
}

func echoSummary(ss *openIDSessionData) {

}
@@ -42,58 +55,57 @@ func echoInto(ss *openIDSessionData) {

func echoCommand(ss *openIDSessionData, in InWechatMsg) {
openID := in.header.FromUserName
processed = true
str, err := BuildTextMsg(openID, "default")
log.Println("echoCommand :" + in.header.MsgType)
switch in.body.(type) {
case TextMsg:
m := in.body.(TextMsg)
str, err = BuildTextMsg(openID, m.Content+"\n\n关键词 [转接] 将后续信息都转接到 客服 测试版")
if m.Content == "转接" {
processed = false
}
in.replyXML(str)
case PicMsg:
m := in.body.(PicMsg)
str = buildPicMsg(openID, m.MediaId)
in.replyXML(str)
case VoiceMsg:
m := in.body.(VoiceMsg)
str = buildVoiceMsg(openID, m.MediaId)
in.replyXML(str)
kfSendTxt(openID, "翻译结果:"+m.Recognition)
case VideoMsg:
m := in.body.(VideoMsg)
str = buildVideoMsg(openID, "e2iNEiSxCX5TV1WbFd0TQMn5lilY3bylh1--lDBwi7I", "航拍春日哈工大", m.MediaId)
in.replyXML(str)
case ShortVideoMsg:
m := in.body.(ShortVideoMsg)
str = buildVideoMsg(openID, "e2iNEiSxCX5TV1WbFd0TQMn5lilY3bylh1--lDBwi7I", "航拍春日哈工大", m.MediaId)
in.replyXML(str)
case LocationMsg:
m := in.body.(LocationMsg)
mid := location2MediaID(m.Location_X, m.Location_Y)
//str, _ = BuildTextMsg(openID, fmt.Sprintf("long=%f, lat=%f, scale=%d", m.Location_X, m.Location_Y, m.Scale))
str, _ = BuildTextMsg(openID, fmt.Sprintf("long=%f, lat=%f, scale=%d", m.Location_X, m.Location_Y, m.Scale))
in.replyXML(str)
str = buildPicMsg(openID, mid)
url := location2URL(m.Location_X, m.Location_Y)
kfSendTxt(openID, url)

case LinkMsg:
m := in.body.(LinkMsg)
kfSendTxt(openID, m.Title+m.Description)
str, _ = BuildTextMsg(openID, m.Url)
in.replyXML(str)
kfSendTxt(openID, m.Title+m.Description)
case EventMsg:
return echoEvents(openID, in)
echoEvents(in)
default:
str, err = BuildTextMsg(openID, "text message")
}

if err != nil {
log.Println("build response failed")
processed = false
}
//state is any state that
return
}

func echoEvents(openID string, in InWechatMsg) (state chatState, processed bool) {
processed = true
func echoEvents(in InWechatMsg) {
openID := in.header.FromUserName
str := ""
m := in.body.(EventMsg)
log.Println("Event = " + m.Event)
@@ -133,7 +145,7 @@ func echoEvents(openID string, in InWechatMsg) (state chatState, processed bool)
default:
str, _ = BuildTextMsg(openID, " unknown event:"+m.Event)
}
state.response = str
in.replyXML(str)
return
}


Ładowanie…
Anuluj
Zapisz