diff --git a/glist/glist.go b/glist/glist.go index 0d649dd..6464693 100644 --- a/glist/glist.go +++ b/glist/glist.go @@ -109,16 +109,24 @@ func (g *GList) ClearChecked() { persistReqC <- g } +type SendMethod string + +var ( + NEWLIST SendMethod = "sendMessage" + EDITLIST SendMethod = "editMessageText" +) + type button struct { Text string `json:"text"` CallbackData string `json:"callback_data"` } type newListReq struct { - ChatID int `json:"chat_id"` - MessageID *int `json:"message_id,omitempty"` - Text string `json:"text"` - ReplyMarkup struct { + ChatID int `json:"chat_id"` + MessageID *int `json:"message_id,omitempty"` + Text string `json:"text"` + DisableNotification *bool `json:"disable_notification,omitempty"` + ReplyMarkup struct { InlineKeyboard [][]button `json:"inline_keyboard"` } `json:"reply_markup"` } @@ -147,8 +155,12 @@ func makeButtons(items []Entry) [][]button { return buttons } -func (g *GList) GenSendListReq() ([]byte, error) { +func (g *GList) GenSendListReq(method SendMethod) ([]byte, error) { req := newListReq{ChatID: g.ChatID, MessageID: g.MessageID, Text: "List:"} + if method == NEWLIST { + disableNotification := true + req.DisableNotification = &disableNotification + } itemButtons := makeButtons(g.Items) controlButtons := []button{{"clear checked", "clear"}} req.ReplyMarkup.InlineKeyboard = append(itemButtons, controlButtons) diff --git a/glist/glist_test.go b/glist/glist_test.go index 0560596..6ba2a64 100644 --- a/glist/glist_test.go +++ b/glist/glist_test.go @@ -7,12 +7,12 @@ import ( func TestGList(t *testing.T) { g := NewGList(4342, "foo") - data, err := g.GenSendListReq() + data, err := g.GenSendListReq(NEWLIST) if err != nil { t.Fatal(err) } - expected := `{"chat_id":4342,"text":"List:","reply_markup":{"inline_keyboard":[[{"text":"foo","callback_data":"foo"}],[{"text":"clear checked","callback_data":"clear"}]]}}` + expected := `{"chat_id":4342,"text":"List:","disable_notification":true,"reply_markup":{"inline_keyboard":[[{"text":"foo","callback_data":"foo"}],[{"text":"clear checked","callback_data":"clear"}]]}}` if expected != string(data) { t.Fatalf("expected: %s\n got:%s\n", expected, string(data)) } diff --git a/main.go b/main.go index f7e0665..31b8c3c 100644 --- a/main.go +++ b/main.go @@ -177,7 +177,7 @@ func handleTextAdded(gl *glist.GList, text string) { gl.Mutex.Lock() defer gl.Mutex.Unlock() if count == gl.AllMsgCounter { - resp := sendList(gl, "sendMessage") + resp := sendList(gl, glist.NEWLIST) if resp == nil { return } @@ -219,13 +219,13 @@ func handleButtonClick(gl *glist.GList, messageID int, text string) { deleteMessage(gl.ChatID, messageID) gl.MessageID = nil } else { - sendList(gl, "editMessageText") + sendList(gl, glist.EDITLIST) } } -func sendList(gl *glist.GList, method string) []byte { +func sendList(gl *glist.GList, method glist.SendMethod) []byte { url := fmt.Sprintf("https://api.telegram.org/bot%s/%s", apiToken, method) - sendMsgReq, err := gl.GenSendListReq() + sendMsgReq, err := gl.GenSendListReq(method) if err != nil { log.Println(err) return nil