Long items don't work. telegram limit 64. Reject those

This commit is contained in:
Balakrishnan Balasubramanian 2023-06-25 22:15:46 -04:00
parent 3365e66059
commit 1cca2bc8a5

12
main.go
View File

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