diff --git a/model/speech.go b/model/speech.go index 552040acd9aa2ef00985cacaf019303e9ed07357..f7909a1e5290bc758e4cce984bdba4a4ae558e03 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 e86e91040ad9eaa83f90853587dcd5e2cf5906ec..a90004b4239c8a37e17fe870d5cc291bb4145864 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 7939431282568bd2bc62e415d0e68970eb8d41fd..eaf4448c45fda8b7e18d23d56db4b67703671b8e 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) }