Commit c60c5dfb authored by 赵文静's avatar 赵文静

补充历史

parent 099c71af
......@@ -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"`
}
......@@ -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
}
......@@ -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)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment