From 1cca2bc8a5aef1600a0977c851c1b99f5c1765e1 Mon Sep 17 00:00:00 2001 From: Balakrishnan Balasubramanian Date: Sun, 25 Jun 2023 22:15:46 -0400 Subject: [PATCH] Long items don't work. telegram limit 64. Reject those --- main.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/main.go b/main.go index 992481c..c838eae 100644 --- a/main.go +++ b/main.go @@ -32,6 +32,7 @@ TGLB_DATA_PATH (default .): Directory path where list data is stored func main() { + log.SetFlags(log.Flags() | log.Lshortfile) apiToken = os.Getenv("TGLB_API_TOKEN") if apiToken == "" { @@ -124,6 +125,16 @@ func main() { if update.Message != nil && update.Message.Text != "" && update.Message.Text[0] != '/' { chatID := update.Message.Chat.ID + if len(update.Message.Text) > 60 { + replyURL := fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage?chat_id=%d&reply_to_message_id=%d&text=ItemTooLong-Max60", apiToken, chatID, update.Message.ID) + resp, err := http.Get(replyURL) + if err != nil { + log.Println(err) + return + } + logBody(resp.Body) + return + } g, _ := chats.LoadOrStore(chatID, glist.NewGList(chatID)) gl := g.(*glist.GList) go handleTextAdded(gl, update.Message.Text) @@ -209,6 +220,7 @@ func sendList(gl *glist.GList, method glist.SendMethod) []byte { log.Println(err) return nil } + log.Println(string(sendMsgReq)) resp, err := http.Post(url, "application/json", bytes.NewReader(sendMsgReq)) if err != nil { log.Println(err)