From 5b5a09ccbddc2b35e080a9df0237ce6cc97a25a3 Mon Sep 17 00:00:00 2001 From: Lan Tian Date: Wed, 31 Mar 2021 22:43:46 +0800 Subject: [PATCH] frontend: clamp telegram api response to 4096 chars --- frontend/go.mod | 1 + frontend/go.sum | 2 ++ frontend/telegram_bot.go | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/frontend/go.mod b/frontend/go.mod index 277344d..e8eaedd 100644 --- a/frontend/go.mod +++ b/frontend/go.mod @@ -5,4 +5,5 @@ go 1.15 require ( github.com/elazarl/go-bindata-assetfs v1.0.1 github.com/gorilla/handlers v1.5.1 + github.com/kevinburke/go-bindata v3.22.0+incompatible // indirect ) diff --git a/frontend/go.sum b/frontend/go.sum index b1f7671..a8da501 100644 --- a/frontend/go.sum +++ b/frontend/go.sum @@ -4,3 +4,5 @@ github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8S github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4= github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q= +github.com/kevinburke/go-bindata v3.22.0+incompatible h1:/JmqEhIWQ7GRScV0WjX/0tqBrC5D21ALg0H0U/KZ/ts= +github.com/kevinburke/go-bindata v3.22.0+incompatible/go.mod h1:/pEEZ72flUW2p0yi30bslSp9YqD9pysLxunQDdb2CPM= diff --git a/frontend/telegram_bot.go b/frontend/telegram_bot.go index 446e89a..b7d45d6 100644 --- a/frontend/telegram_bot.go +++ b/frontend/telegram_bot.go @@ -138,6 +138,10 @@ func webHandlerTelegramBot(w http.ResponseWriter, r *http.Request) { commandResult = "empty result" } + if len(commandResult) > 4096 { + commandResult = commandResult[0:4096] + } + // Create a JSON response w.Header().Add("Content-Type", "application/json") response := &tgWebhookResponse{