-
Notifications
You must be signed in to change notification settings - Fork 0
/
readmark.go
55 lines (44 loc) · 1.35 KB
/
readmark.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package greenapi
import "encoding/json"
type ReadMarkCategory struct {
GreenAPI GreenAPIInterface
}
// ------------------------------------------------------------------ ReadChat
type RequestReadChat struct {
ChatId string `json:"chatId"`
IdMessage string `json:"idMessage,omitempty"`
}
type ReadChatOption func(*RequestReadChat) error
// ID of the incoming message to be marked as read. If not specified, then all unread messages in the chat will be marked as read.
func OptionalIdMessage(idMessage string) ReadChatOption {
return func(r *RequestReadChat) error {
r.IdMessage = idMessage
return nil
}
}
// Marking messages in a chat as read.
//
// https://green-api.com/en/docs/api/marks/ReadChat/
//
// Add optional arguments by passing these functions:
// OptionalIdMessage(idMessage string) <- ID of the incoming message to be marked as read. If not specified, then all unread messages in the chat will be marked as read.
func (c ReadMarkCategory) ReadChat(chatId string, options ...ReadChatOption) (*APIResponse, error) {
err := ValidateChatId(chatId)
if err!=nil {
return nil, err
}
r := &RequestReadChat{
ChatId: chatId,
}
for _, o := range options {
err := o(r)
if err!=nil {
return nil, err
}
}
jsonData, err := json.Marshal(r)
if err != nil {
return nil, err
}
return c.GreenAPI.Request("POST", "readChat", jsonData)
}