From c60c5dfbc7037baa0f7309a640dd1ff1941e5f34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=96=87=E9=9D=99?= <1319697849@qq.com> Date: Tue, 13 May 2025 17:10:10 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E5=8E=86=E5=8F=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/speech.go | 17 +++++++++--- model/speechNlpResp.go | 14 ++++++++++ service/speechNlu/domain.go | 53 +++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 3 deletions(-) diff --git a/model/speech.go b/model/speech.go index 552040a..f7909a1 100644 --- a/model/speech.go +++ b/model/speech.go @@ -35,9 +35,10 @@ type SpeechWsResp struct { WidgetName string `json:"widgetName"` SubTitle string `json:"subTitle"` Name string `json:"name"` - Extra struct { - ContentTranslation string `json:"content_translation"` - Title string `json:"title"` + Extra *struct { + ContentTranslation string `json:"content_translation"` + Title string `json:"title"` + Result interface{} `json:"result"` } `json:"extra"` Title string `json:"title"` Buttons []struct { @@ -108,3 +109,13 @@ type Content struct { ResType string `json:"resType"` } `json:"extra"` } + +type Result struct { + Day int `json:"day"` + Title string `json:"title"` + Month int `json:"month"` + SubTitle string `json:"subTitle"` + Date string `json:"date"` + Year int `json:"year"` + Event string `json:"event"` +} diff --git a/model/speechNlpResp.go b/model/speechNlpResp.go index e86e910..a90004b 100644 --- a/model/speechNlpResp.go +++ b/model/speechNlpResp.go @@ -55,3 +55,17 @@ func (d *SpeechDomainParams) CheckCommandParam() bool { } return true } + +func (d *SpeechDomainParams) CheckWidExtra() bool { + if !d.CheckWidget() || d.SpeechWsResp.Dm.Widget.Extra == nil { + return false + } + return true +} + +func (d *SpeechDomainParams) CheckWidResult() bool { + if !d.CheckWidExtra() || d.SpeechWsResp.Dm.Widget.Extra.Result == nil { + return false + } + return true +} diff --git a/service/speechNlu/domain.go b/service/speechNlu/domain.go index 7939431..eaf4448 100644 --- a/service/speechNlu/domain.go +++ b/service/speechNlu/domain.go @@ -95,6 +95,59 @@ func calendarDomain(params *model.SpeechDomainParams) []byte { res.Header.Semantic.Intent = "search_dateDiff" res.Header.Semantic.SkillId = res.Header.Semantic.Domain + "." + res.Header.Semantic.Intent + if params.SpeechWsResp.Dm.IntentName == "查询历史事件" { + res.Header.Semantic.Domain = "chat" + res.Header.Semantic.Intent = "chat" + res.Header.Semantic.SkillId = "history.search_today" + if !params.CheckWidResult() { + if res.ResponseText != "" { + return replyWithChat(res.ResponseText, "doudi") + } + } else { + sliceData, isSlice := params.SpeechWsResp.Dm.Widget.Extra.Result.([]interface{}) + if !isSlice { + global.Logger.WithFields(logger.Fields{ + "requestId": params.RequestId, + "mac": params.Mac, + "mid": params.Mid, + "vender": params.MidType, + }).Error("params.SpeechWsResp.Dm.Widget.Extra.Result不是数组类型") + if res.ResponseText != "" { + return replyWithChat(res.ResponseText, "doudi") + } + return replyWithChat(error_reply, "doudi") + } + + var l int + var resStrb string + if len(sliceData) < global.GetLimitedSetting(params.Mid).HistoryNum { + l = len(sliceData) + } else { // 使用限制的条数 + l = global.GetLimitedSetting(params.Mid).HistoryNum + } + + if len(sliceData) > l { + sliceData = sliceData[:l] + } + + for _, item := range sliceData { + itemBytes, _ := json.Marshal(item) + var con model.Result + if err := json.Unmarshal(itemBytes, &con); err != nil { + global.Logger.WithFields(logger.Fields{ + "requestId": params.RequestId, + "mac": params.Mac, + "mid": params.Mid, + "vender": params.MidType, + }).Errorf("json.Unmarshal元素解析失败: %v", err) + return replyWithChat(error_reply, "doudi") + } + resStrb += fmt.Sprintf("%s", con.Title) + } + res.ResponseText = resStrb + } + } + return Marshal(params, res) } -- GitLab