From 6c713ac9b936216933a08e824e0eba9ed8698673 Mon Sep 17 00:00:00 2001 From: jiangyong27 Date: Tue, 23 Jan 2024 22:06:52 +0800 Subject: [PATCH] servicer list2 --- qyweixin/app_customer.go | 81 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 73 insertions(+), 8 deletions(-) diff --git a/qyweixin/app_customer.go b/qyweixin/app_customer.go index dd02fb5..69367ce 100644 --- a/qyweixin/app_customer.go +++ b/qyweixin/app_customer.go @@ -3,17 +3,38 @@ package qyweixin import ( "encoding/json" "fmt" - "github.com/smbrave/goutil" "github.com/spf13/cast" "gitlab.batiao8.com/open/gosdk/util" "gitlab.batiao8.com/open/gosdk/wechat/message" "time" ) +var ( + ChangeTypeFromPool = 1 + ChangeTypeTransform = 2 + ChangeTypeFinish = 3 + ChangeTypeRepeat = 4 + + OriginCustomer = 3 //用户发送的 + OriginSystem = 4 //系统发送的 + OriginServicer = 5 //客服发送的 + OriginAi = 6 //AI发送的 + + EventTypeEnterSession = "enter_session" + EventTypeSessionChange = "session_status_change" + + CustomerStateEnterSession = 0 + CustomerStateRobot = 1 + CustomerStateWaitPool = 2 + CustomerStateServicing = 3 + CustomerStateComplete = 4 +) + type CustomerAccount struct { Name string KfId string } + type CustomerMessage struct { Msgid string Msgtype string @@ -23,17 +44,38 @@ type CustomerMessage struct { Origin int SendTime int64 SyncTime int64 - Content string + Text *CustomerText + Event *CustomerEvent + Image *CustomerImage } + type CustomerServicer struct { Userid string Status int } + type CustomerState struct { State int Servicer string } +type CustomerText struct { + Content string + MenuId string +} + +type CustomerImage struct { + MediaId string +} + +type CustomerEvent struct { + EventType string `json:"event_type"` + Scene string `json:"scene"` + ChangeType int `json:"change_type"` + OldServicerUserid string `json:"old_servicer_userid"` + NewServicerUserid string `json:"new_servicer_userid"` +} + type AppCustomer struct { App } @@ -198,8 +240,10 @@ func (m *CustomerMessage) From(data map[string]interface{}) { if m.Msgtype == message.MsgTypeEvent { m.parseEvent(data) - } else { - m.parseMessage(m.Msgtype, data) + } else if m.Msgtype == string(message.MsgTypeText) { + m.parseText(data) + } else if m.Msgtype == message.MsgTypeImage { + m.parseText(data) } } @@ -218,16 +262,37 @@ func (m *CustomerMessage) parseEvent(data map[string]interface{}) error { m.OpenKfid = openKfid } - m.Content = goutil.EncodeJSON(event) + m.Event = &CustomerEvent{ + EventType: cast.ToString(event["event_type"]), + Scene: cast.ToString(event["scene"]), + ChangeType: cast.ToInt(event["change_type"]), + NewServicerUserid: cast.ToString(event["new_servicer_userid"]), + OldServicerUserid: cast.ToString(event["old_servicer_userid"]), + } return nil } -func (m *CustomerMessage) parseMessage(msgKey string, data map[string]interface{}) error { - image, err := cast.ToStringMapE(data[msgKey]) +func (m *CustomerMessage) parseText(data map[string]interface{}) error { + image, err := cast.ToStringMapE(data["text"]) if err != nil { return err } - m.Content = goutil.EncodeJSON(image) + m.Text = &CustomerText{ + Content: cast.ToString(image["content"]), + MenuId: cast.ToString(image["menu_id"]), + } + return nil +} + +func (m *CustomerMessage) parseImage(data map[string]interface{}) error { + image, err := cast.ToStringMapE(data["image"]) + if err != nil { + return err + } + + m.Image = &CustomerImage{ + MediaId: cast.ToString(image["media_id"]), + } return nil }