Skip to content

Commit

Permalink
Add new API methods 'ArchiveChat' and 'UnarchiveChat'
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Nov 14, 2024
1 parent 04f74e3 commit 9a62867
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions pachca.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9a62867

Please sign in to comment.