From fc098c7d508ab82aaf7a817373b16319a2861547 Mon Sep 17 00:00:00 2001 From: Lan Tian Date: Mon, 29 Jun 2020 15:04:32 +0800 Subject: [PATCH] frontend: improve empty result handling --- frontend/telegram_bot.go | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/frontend/telegram_bot.go b/frontend/telegram_bot.go index 8491f9e..4767e42 100644 --- a/frontend/telegram_bot.go +++ b/frontend/telegram_bot.go @@ -145,22 +145,24 @@ func webHandlerTelegramBot(w http.ResponseWriter, r *http.Request) { } commandResult = strings.TrimSpace(commandResult) - if len(commandResult) > 0 { - // Create a JSON response - w.Header().Add("Content-Type", "application/json") - response := &tgWebhookResponse{ - Method: "sendMessage", - ChatID: request.Message.Chat.ID, - Text: "```\n" + commandResult + "\n```", - ReplyToMessageID: request.Message.MessageID, - ParseMode: "Markdown", - } - data, err := json.Marshal(response) - if err != nil { - println(err.Error()) - return - } - // println(string(data)) - w.Write(data) + if len(commandResult) < 0 { + commandResult = "empty result" } + + // Create a JSON response + w.Header().Add("Content-Type", "application/json") + response := &tgWebhookResponse{ + Method: "sendMessage", + ChatID: request.Message.Chat.ID, + Text: "```\n" + commandResult + "\n```", + ReplyToMessageID: request.Message.MessageID, + ParseMode: "Markdown", + } + data, err := json.Marshal(response) + if err != nil { + println(err.Error()) + return + } + // println(string(data)) + w.Write(data) }