frontend: improve empty result handling

This commit is contained in:
Lan Tian 2020-06-29 15:04:32 +08:00
parent 47d7168718
commit fc098c7d50
No known key found for this signature in database
GPG Key ID: 27F31700E751EC22

View File

@ -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)
}