diff --git a/go.mod b/go.mod index 345627b..9138287 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.22.8 require ( github.com/essentialkaos/check v1.4.1 - github.com/essentialkaos/ek/v13 v13.10.0 + github.com/essentialkaos/ek/v13 v13.11.0 ) require ( diff --git a/go.sum b/go.sum index 581c987..df2e787 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/essentialkaos/check v1.4.1 h1:SuxXzrbokPGTPWxGRnzy0hXvtb44mtVrdNxgPa1s4c8= github.com/essentialkaos/check v1.4.1/go.mod h1:xQOYwFvnxfVZyt5Qvjoa1SxcRqu5VyP77pgALr3iu+M= -github.com/essentialkaos/ek/v13 v13.10.0 h1:uoLNjiDRJ/bOPAciq8Ff92r+XHgTm+rBI4ItOtZje9k= -github.com/essentialkaos/ek/v13 v13.10.0/go.mod h1:6G9EPJ/k4N0mugTLqPuWS/fb7K5JwoEqZSkNSfBCsgg= +github.com/essentialkaos/ek/v13 v13.11.0 h1:vpIk6wiycQGzLcC/zZrxWP2CguJxeoNj9fjuGiYAmJ8= +github.com/essentialkaos/ek/v13 v13.11.0/go.mod h1:GAoS44v5gtd3Yc1qqfgXsaJNoC0dMw1ueW5Fc9TTHUg= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= diff --git a/pachca.go b/pachca.go index 2d66333..2f777ac 100644 --- a/pachca.go +++ b/pachca.go @@ -1232,6 +1232,52 @@ func (c *Client) ExcludeChatTag(chatID, tagID uint64) error { return nil } +// ArchiveChat sends chat to archive +// +// https://crm.pachca.com/dev/chats/archive/ +func (c *Client) ArchiveChat(chatID uint64) error { + switch { + case c == nil || c.engine == nil: + return ErrNilClient + case chatID == 0: + return ErrInvalidChatID + } + + err := c.sendRequest( + req.PUT, getURL("/chats/%d/archive", chatID), + nil, nil, nil, + ) + + if err != nil { + return fmt.Errorf("Can't archive chat %d: %w", chatID, err) + } + + return nil +} + +// UnarchiveChat restores chat from archive +// +// https://crm.pachca.com/dev/chats/unarchive/ +func (c *Client) UnarchiveChat(chatID uint64) error { + switch { + case c == nil || c.engine == nil: + return ErrNilClient + case chatID == 0: + return ErrInvalidChatID + } + + err := c.sendRequest( + req.PUT, getURL("/chats/%d/unarchive", chatID), + nil, nil, nil, + ) + + if err != nil { + return fmt.Errorf("Can't unarchive chat %d: %w", chatID, err) + } + + return nil +} + // MESSAGES ///////////////////////////////////////////////////////////////////////// // // GetMessage returns info about message