From aab34aa9415ba718bfd467aaf65174b13b4a429d Mon Sep 17 00:00:00 2001 From: C-Anirudh Date: Fri, 5 Apr 2019 21:56:48 +0530 Subject: [PATCH 1/2] corrected empty messages while using google, yahoo, bing and image search commands --- service/controllers/messages.go | 42 ++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/service/controllers/messages.go b/service/controllers/messages.go index cbeaab5..487cb1f 100644 --- a/service/controllers/messages.go +++ b/service/controllers/messages.go @@ -92,9 +92,15 @@ func routes(routeObject response, w http.ResponseWriter) { // single word operations if Connected() { - if strings.ToLower(firstPars) == "google" { // for google search - query := "https://www.google.co.in/search?q=" + messageExceptFirstPars + if strings.ToLower(firstPars) == "google" { // for google search + query := "" + if len(messageExceptFirstPars) == 0 { + query = "https://www.google.co.in/search?q=google" + } else { + query = "https://www.google.co.in/search?q=" + messageExceptFirstPars + } + result := HandlerGoogle("GET", query) // processing @@ -110,7 +116,13 @@ func routes(routeObject response, w http.ResponseWriter) { TextToSpeech(responseJSON.Message, 0) } else if strings.ToLower(firstPars) == "yahoo" { - query := "https://in.search.yahoo.com/search?p=" + messageExceptFirstPars + query := "" + if len(messageExceptFirstPars) == 0 { + query = "https://in.search.yahoo.com/search?p=yahoo" + } else { + query = "https://in.search.yahoo.com/search?p=" + messageExceptFirstPars + } + result := HandlerYahoo("GET", query) // processing @@ -126,7 +138,13 @@ func routes(routeObject response, w http.ResponseWriter) { TextToSpeech(responseJSON.Message, 0) } else if strings.ToLower(firstPars) == "bing" { - query := "https://www.bing.com/search?q=" + messageExceptFirstPars + query := "" + if len(messageExceptFirstPars) == 0 { + query = "https://www.bing.com/search?q=bing" + } else { + query = "https://www.bing.com/search?q=" + messageExceptFirstPars + } + result := HandlerBing("GET", query) // processing @@ -142,7 +160,13 @@ func routes(routeObject response, w http.ResponseWriter) { TextToSpeech(responseJSON.Message, 0) } else if strings.ToLower(firstPars) == "youtube" { - query := "https://www.youtube.com/results?search_query=" + messageExceptFirstPars + query := "" + if len(messageExceptFirstPars) == 0 { + query = "https://www.youtube.com/results?search_query=youtube" + } else { + query = "https://www.youtube.com/results?search_query=" + messageExceptFirstPars + } + result := HandlerYoutube("GET", query) // processing @@ -158,7 +182,13 @@ func routes(routeObject response, w http.ResponseWriter) { TextToSpeech(responseJSON.Message, 0) } else if strings.ToLower(firstPars) == "image" { - query := "https://www.google.co.in/search?q="+messageExceptFirstPars+"&source=lnms&tbm=isch" + query := "" + if len(messageExceptFirstPars) == 0 { + query = "https://www.google.co.in/search?q="+"images"+"&source=lnms&tbm=isch" + } else { + query = "https://www.google.co.in/search?q="+messageExceptFirstPars+"&source=lnms&tbm=isch" + } + result := HandlerImage("GET", query) // processing From b39b74a899d808d505f7efd816f557c069509071 Mon Sep 17 00:00:00 2001 From: C-Anirudh Date: Fri, 5 Apr 2019 23:37:21 +0530 Subject: [PATCH 2/2] improved weather rendering, added error message --- service/controllers/messages.go | 27 +++++++++++++++------------ view/components/main.html | 12 ++++++++++++ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/service/controllers/messages.go b/service/controllers/messages.go index 487cb1f..810f5de 100644 --- a/service/controllers/messages.go +++ b/service/controllers/messages.go @@ -204,19 +204,22 @@ func routes(routeObject response, w http.ResponseWriter) { } else if strings.ToLower(firstPars) == "weather" { - city := messageArr[len(messageArr)-2] - state := messageArr[len(messageArr)-1] - result := HandlerWeather(city, state) - stringified, _ := json.Marshal(processWeather(result)) - response := jsonResponseWeather{ - Status: true, - Message: "here are the current weather conditions", - Result: string(stringified), + if len(messageArr) == 1 || len(messageArr) < 3 { + w.Write([]byte(`{"status": "success", "message": "ENTER: weather ", "result": ""}`)) + } else { + city := messageArr[len(messageArr)-2] + state := messageArr[len(messageArr)-1] + result := HandlerWeather(city, state) + stringified, _ := json.Marshal(processWeather(result)) + response := jsonResponseWeather{ + Status: true, + Message: "here are the current weather conditions", + Result: string(stringified), + } + jData, _ := json.Marshal(response) + w.Write(jData) + TextToSpeech(response.Message + city + " " + state, 0) } - jData, _ := json.Marshal(response) - w.Write(jData) - TextToSpeech(response.Message + city + " " + state, 0) - } else { // general conversation w.Write([]byte(`{"status": "success", "message": "Hi from reply bot", "result": ""}`)) diff --git a/view/components/main.html b/view/components/main.html index b2ebb71..b98318f 100644 --- a/view/components/main.html +++ b/view/components/main.html @@ -105,6 +105,18 @@

{{$index + 1}}. {{objectQuery.head}}

+
+ +
+ {{message.message}} + + + {{message.sender}} + {{message.time}} + + +
+