Documentation
¶
Index ¶
- Constants
- Variables
- func ValidateToken(token string) error
- type APIError
- type Button
- type ButtonLine
- type Buttons
- type Chat
- type ChatFilter
- type ChatRequest
- type ChatRole
- type Chats
- type Client
- func (c *Client) AddChat(chat *ChatRequest) (*Chat, error)
- func (c *Client) AddChatTags(chatID uint, tagIDs []uint) error
- func (c *Client) AddChatUsers(chatID uint, membersIDs []uint, silent bool) error
- func (c *Client) AddLinkPreview(messageID uint, previews LinkPreviews) error
- func (c *Client) AddMessage(message *MessageRequest) (*Message, error)
- func (c *Client) AddReaction(messageID uint, reaction string) error
- func (c *Client) AddTag(groupTagName string) (*Tag, error)
- func (c *Client) AddThreadMessage(messageID uint, message *MessageRequest) (*Thread, *Message, error)
- func (c *Client) AddThreadMessageText(messageID uint, text string) (*Thread, *Message, error)
- func (c *Client) AddUser(user *UserRequest) (*User, error)
- func (c *Client) ArchiveChat(chatID uint) error
- func (c *Client) CurrentUser() (*User, error)
- func (c *Client) DeleteMessage(messageID uint) error
- func (c *Client) DeleteMessageButtons(messageID uint) error
- func (c *Client) DeleteReaction(messageID uint, reaction string) error
- func (c *Client) DeleteTag(groupTagID uint) error
- func (c *Client) DeleteUser(userID uint) error
- func (c *Client) DeleteWebhookEvent(eventID string) error
- func (c *Client) EditChat(chatID uint, chat *ChatRequest) (*Chat, error)
- func (c *Client) EditMessage(messageID uint, message *MessageRequest) (*Message, error)
- func (c *Client) EditTag(groupTagID uint, groupTagName string) (*Tag, error)
- func (c *Client) EditUser(userID uint, user *UserRequest) (*User, error)
- func (c *Client) Engine() *req.Engine
- func (c *Client) ExcludeChatTag(chatID, tagID uint) error
- func (c *Client) ExcludeChatUser(chatID, userID uint) error
- func (c *Client) GetChat(chatID uint) (*Chat, error)
- func (c *Client) GetChatUsers(chatID uint, memberRole ChatRole) (Users, error)
- func (c *Client) GetChats(filter ...ChatFilter) (Chats, error)
- func (c *Client) GetMessage(messageID uint) (*Message, error)
- func (c *Client) GetMessageReads(messageID uint) ([]uint, error)
- func (c *Client) GetMessages(chatID uint, limit int) (Messages, error)
- func (c *Client) GetProperties() (Properties, error)
- func (c *Client) GetReactions(messageID uint) (Reactions, error)
- func (c *Client) GetTag(groupTagID uint) (*Tag, error)
- func (c *Client) GetTagUsers(groupTagID uint) (Users, error)
- func (c *Client) GetTags(names ...string) (Tags, error)
- func (c *Client) GetThread(threadID uint) (*Thread, error)
- func (c *Client) GetUser(userID uint) (*User, error)
- func (c *Client) GetUsers(searchQuery ...string) (Users, error)
- func (c *Client) GetWebhookEvents(maxPages int) ([]*WebhookEvent, error)
- func (c *Client) NewThread(messageID uint) (*Thread, error)
- func (c *Client) OpenView(view *ViewRequest) error
- func (c *Client) PinMessage(messageID uint) error
- func (c *Client) SendMessageToChat(chatID uint, text string) (*Message, error)
- func (c *Client) SendMessageToThread(threadID uint, text string) (*Message, error)
- func (c *Client) SendMessageToUser(userID uint, text string) (*Message, error)
- func (c *Client) SetChatUserRole(chatID, userID uint, role ChatRole) error
- func (c *Client) SetUserAgent(app, ver string)
- func (c *Client) UnarchiveChat(chatID uint) error
- func (c *Client) UnpinMessage(messageID uint) error
- func (c *Client) UpdateBot(botID uint, webhookURL string) error
- func (c *Client) UpdateMessage(messageID uint, text string) (*Message, error)
- func (c *Client) UploadFile(file string) (*File, error)
- type Date
- type EntityType
- type File
- type FileType
- type Files
- type Forwarding
- type InviteStatus
- type LinkPreview
- type LinkPreviews
- type Message
- type MessageRequest
- type Messages
- type Metadata
- type Paginate
- type Properties
- type Property
- func (p *Property) Date() time.Time
- func (p *Property) Int() int
- func (p *Property) IsDate() bool
- func (p *Property) IsLink() bool
- func (p *Property) IsNumber() bool
- func (p *Property) IsSet() bool
- func (p *Property) IsText() bool
- func (p *Property) String() string
- func (p *Property) ToDate() (time.Time, error)
- func (p *Property) ToInt() (int, error)
- type PropertyRequest
- type PropertyRequests
- type PropertyType
- type Reaction
- type ReactionRequest
- type Reactions
- type S3Error
- type Status
- type Tag
- type Tags
- type Thread
- type Upload
- type User
- func (u *User) FullName() string
- func (u *User) HasAvatar() bool
- func (u *User) HasTag(tag string) bool
- func (u *User) IsActive() bool
- func (u *User) IsAdmin() bool
- func (u *User) IsGuest() bool
- func (u *User) IsInvited() bool
- func (u *User) IsMultiGuest() bool
- func (u *User) IsPaid() bool
- func (u *User) IsRegular() bool
- func (u *User) URL() string
- type UserRequest
- type UserRole
- type Users
- func (u Users) Active() Users
- func (u Users) Admins() Users
- func (u Users) Bots() Users
- func (u Users) Find(nicknameOrEmail string) *User
- func (u Users) Get(id uint) *User
- func (u Users) Guests() Users
- func (u Users) InChat(chat *Chat) Users
- func (u Users) Invited() Users
- func (u Users) MultiGuests() Users
- func (u Users) Paid() Users
- func (u Users) People() Users
- func (u Users) Regular() Users
- func (u Users) Suspended() Users
- func (u Users) WithTag(tag string) Users
- func (u Users) WithoutGuests() Users
- type View
- type ViewErrors
- type ViewRequest
- type ViewType
- type WebhookEvent
Constants ¶
const ( SORT_FIELD_ID = "id" SORT_FIELD_LAST_MESSAGE = "last_message_at" )
const ( SORT_ORDER_ASC = "asc" SORT_ORDER_DESC = "desc" )
const API_URL = "https://api.pachca.com/api/shared/v1"
API_URL is URL of Pachca API
const APP_URL = "https://app.pachca.com"
APP_URL is application URL used to generate links
const MAX_PAGES = 1_000
MAX_PAGES is the maximum number of pages using for listing items
const MAX_PER_PAGE = 50
MAX_PER_PAGE is the maximum number of entities per page
Variables ¶
var ( ErrNilClient = errors.New("client is nil") ErrNilUserRequest = errors.New("user request is nil") ErrNilChatRequest = errors.New("chat request is nil") ErrNilMessageRequest = errors.New("message request is nil") ErrNilPropertyRequest = errors.New("property request is nil") ErrNilViewRequest = errors.New("view request is nil") ErrNilView = errors.New("view data is nil") ErrEmptyToken = errors.New("token is empty") ErrEmptyTag = errors.New("group tag is empty") ErrEmptyMessage = errors.New("message text is empty") ErrEmptyUserEmail = errors.New("user email is required for creating user account") ErrEmptyChatName = errors.New("name is required for creating new chat") ErrEmptyUsersIDS = errors.New("users IDs are empty") ErrEmptyTagsIDS = errors.New("tags IDs are empty") ErrEmptyFilePath = errors.New("path to file is empty") ErrInvalidToken = errors.New("token has wrong format") ErrInvalidMessageID = errors.New("message ID must be greater than 0") ErrInvalidChatID = errors.New("chat ID must be greater than 0") ErrInvalidUserID = errors.New("user ID must be greater than 0") ErrInvalidThreadID = errors.New("thread ID must be greater than 0") ErrInvalidTagID = errors.New("group tag ID must be greater than 0") ErrInvalidEntityID = errors.New("entity ID must be greater than 0") ErrInvalidBotID = errors.New("bot ID must be greater than 0") ErrInvalidEventID = errors.New("invalid event ID") ErrBlankReaction = errors.New("non-blank emoji is required") ErrEmptyPreviews = errors.New("previews map has no data") ErrInvalidMessageLimit = errors.New("number of messages must be greater than 0") ErrViewHasNoBlocks = errors.New("view has no blocks") ErrEmptyTriggerID = errors.New("view has empty trigger ID") ErrInvalidMaxPages = errors.New("minimum number of result pages must be greater than 0") ErrEmptyWebhookURL = errors.New("webhook URL is empty") )
Functions ¶
func ValidateToken ¶
ValidateToken validates API access token
Types ¶
type APIError ¶
type APIError struct {
Key string `json:"key"`
Value string `json:"value"`
Message string `json:"message"`
Code string `json:"code"`
StatusCode int
}
APIError contains API error info
type Button ¶
type Button struct {
Text string `json:"text"`
URL string `json:"url,omitempty"`
Data string `json:"data,omitempty"`
}
Button contains info about message button
type Chat ¶
type Chat struct {
Members []uint `json:"member_ids"`
GroupTags []uint `json:"group_tag_ids"`
ID uint `json:"id"`
OwnerID uint `json:"owner_id"`
Name string `json:"name"`
MeetRoomURL string `json:"meet_room_url"`
CreatedAt Date `json:"created_at"`
LastMessageAt Date `json:"last_message_at"`
IsPublic bool `json:"public"`
IsChannel bool `json:"channel"`
IsPersonal bool `json:"personal"`
}
Chat contains info about channel
type ChatFilter ¶
type ChatFilter struct {
Sort map[string]string
LastMessageAfter time.Time
LastMessageBefore time.Time
Public bool
}
ChatFilter is configuration for filtering chats
func (ChatFilter) ToQuery ¶
func (f ChatFilter) ToQuery() req.Query
ToQuery converts filter struct to request query
type ChatRequest ¶
type ChatRequest struct {
Name string `json:"name,omitempty"`
Members []uint `json:"member_ids,omitempty"`
Groups []uint `json:"group_tag_ids,omitempty"`
IsChannel bool `json:"channel,omitempty"`
IsPublic bool `json:"public,omitempty"`
IsPersonal bool `json:"personal,omitempty"`
}
ChatRequest is a struct with information needed to create or modify a chat
type Chats ¶
type Chats []*Chat
Chats is slice of chats
type Client ¶
type Client struct {
BatchSize int // BatchSize is a number of items for paginated requests
MaxFileSize int64 // Maximum file size to upload
// contains filtered or unexported fields
}
Client is Pachca API client
func (*Client) AddChat ¶
func (c *Client) AddChat(chat *ChatRequest) (*Chat, error)
AddChat creates new chat
func (*Client) AddChatTags ¶
AddChatTags adds group tags to the chat
func (*Client) AddChatUsers ¶
AddChatUsers adds users with given IDs to the chat, channel or thread
func (*Client) AddLinkPreview ¶ added in v0.5.0
func (c *Client) AddLinkPreview(messageID uint, previews LinkPreviews) error
AddLinkPreview adds link previews to message with given ID
func (*Client) AddMessage ¶
func (c *Client) AddMessage(message *MessageRequest) (*Message, error)
AddMessage creates new message to user or chat
func (*Client) AddReaction ¶
AddReaction adds given emoji reaction to the message. To add custom reaction add it name after amoji using ":" as separator. For example "😲:omg".
func (*Client) AddThreadMessage ¶
func (c *Client) AddThreadMessage(messageID uint, message *MessageRequest) (*Thread, *Message, error)
AddThreadMessage helper to create thread and add new message to it
func (*Client) AddThreadMessageText ¶ added in v0.2.0
AddThreadMessageText helper to create thread and add new message with given text to it
func (*Client) AddUser ¶
func (c *Client) AddUser(user *UserRequest) (*User, error)
AddUser creates a new user
func (*Client) ArchiveChat ¶ added in v0.3.0
ArchiveChat sends chat to archive
func (*Client) CurrentUser ¶ added in v0.7.0
CurrentUser returns info about current user
func (*Client) DeleteMessage ¶
DeleteMessage deletes message with given ID
func (*Client) DeleteMessageButtons ¶ added in v0.16.0
DeleteMessageButtons is a helper for deleting buttons from a message
func (*Client) DeleteReaction ¶
DeleteReaction removes given emoji reaction from the message
func (*Client) DeleteUser ¶
DeleteUser deletes an existing user
func (*Client) DeleteWebhookEvent ¶ added in v0.20.0
DeleteWebhookEvent deletes webhook event with given ID
func (*Client) EditChat ¶
func (c *Client) EditChat(chatID uint, chat *ChatRequest) (*Chat, error)
EditChat modifies chat
func (*Client) EditMessage ¶
func (c *Client) EditMessage(messageID uint, message *MessageRequest) (*Message, error)
EditMessage modifies message
func (*Client) EditUser ¶
func (c *Client) EditUser(userID uint, user *UserRequest) (*User, error)
EditUser modifies an existing user
func (*Client) ExcludeChatTag ¶
ExcludeChatTag excludes the group tag from the chat
func (*Client) ExcludeChatUser ¶
ExcludeChatUser excludes the user from the chat
func (*Client) GetChatUsers ¶ added in v0.10.0
GetChatUsers returns all users of given chat
func (*Client) GetChats ¶
func (c *Client) GetChats(filter ...ChatFilter) (Chats, error)
GetChats returns all chats and conversations
func (*Client) GetMessage ¶
GetMessage returns info about message
func (*Client) GetMessageReads ¶ added in v0.4.0
GetMessageReads returns a slice with IDs of users who have read the message
func (*Client) GetMessages ¶ added in v0.8.0
GetMessages returns messages from given chat
func (*Client) GetProperties ¶
func (c *Client) GetProperties() (Properties, error)
GetProperties returns custom properties
func (*Client) GetReactions ¶
GetReactions returns slice with reactions added to given message
func (*Client) GetTagUsers ¶
GetTagUsers returns slice with users with given tag
func (*Client) GetWebhookEvents ¶ added in v0.20.0
func (c *Client) GetWebhookEvents(maxPages int) ([]*WebhookEvent, error)
GetWebhookEvents returns webhook events. Each event's Payload field contains raw JSON that must be decoded using webhook.DecodeJSON to extract the specific webhook type (Message, Reaction, etc.).
Example:
events, _ := client.GetWebhookEvents(10)
for _, ev := range events {
wh, _ := webhook.DecodeJSON(ev.Payload)
// Handle webhook based on type
}
func (*Client) OpenView ¶ added in v0.13.0
func (c *Client) OpenView(view *ViewRequest) error
OpenView opens view with form
func (*Client) PinMessage ¶
PinMessage pins message to chat
func (*Client) SendMessageToChat ¶
SendMessageToChat helper to send message to chat with given ID
func (*Client) SendMessageToThread ¶
SendMessageToThread helper to send message to thread with given ID
func (*Client) SendMessageToUser ¶
SendMessageToUser helper to send message to user with given ID
func (*Client) SetChatUserRole ¶ added in v0.4.0
SetChatUserRole sets user role in given chat
func (*Client) SetUserAgent ¶
SetUserAgent sets user-agent info
func (*Client) UnarchiveChat ¶ added in v0.3.0
UnarchiveChat restores chat from archive
func (*Client) UnpinMessage ¶
UnpinMessage unpins message from chat
func (*Client) UpdateMessage ¶ added in v0.6.0
UpdateMessage helper to change message text
func (*Client) UploadFile ¶
UploadFile uploads new file and returns key of it
type EntityType ¶
type EntityType string
EntityType is type of entity type
const ( ENTITY_TYPE_DISCUSSION EntityType = "discussion" ENTITY_TYPE_THREAD EntityType = "thread" ENTITY_TYPE_USER EntityType = "user" )
type File ¶
type File struct {
ID uint `json:"id,omitempty"`
Key string `json:"key"`
Name string `json:"name"`
Type FileType `json:"file_type,omitempty"`
URL string `json:"url,omitempty"`
Size int64 `json:"size"`
Width int `json:"width,omitzero"`
Height int `json:"height,omitzero"`
}
File contains info about message attachment
type Forwarding ¶
type Forwarding struct {
OriginalMessageID uint `json:"original_message_id"`
OriginalChatID uint `json:"original_chat_id"`
AuthorID uint `json:"author_id"`
OriginalThreadID uint `json:"original_thread_id"`
OriginalThreadMessageID uint `json:"original_thread_message_id"`
OriginalThreadParentChatID uint `json:"original_thread_parent_chat_id"`
OriginalCreatedAt Date `json:"original_created_at"`
}
Forwarding contains info about message forwarding
type InviteStatus ¶
type InviteStatus string
InviteStatus is type of invite status
const ( INVITE_SENT InviteStatus = "sent" INVITE_CONFIRMED InviteStatus = "confirmed" )
type LinkPreview ¶ added in v0.5.0
type LinkPreview struct {
Title string `json:"title"`
Description string `json:"description"`
ImageURL string `json:"image_url,omitempty"`
Image *File `json:"image,omitempty"`
}
LinkPreview contains link preview data
type LinkPreviews ¶ added in v0.5.0
type LinkPreviews map[string]*LinkPreview
LinkPreviews is map (url → preview data) with link previews
type Message ¶
type Message struct {
ID uint `json:"id"`
EntityID uint `json:"entity_id"`
ChatID uint `json:"chat_id"`
ParentMessageID uint `json:"parent_message_id"`
UserID uint `json:"user_id"`
EntityType EntityType `json:"entity_type"`
Content string `json:"content"`
CreatedAt Date `json:"created_at"`
Thread *Thread `json:"thread"`
Files Files `json:"files"`
Buttons Buttons `json:"buttons"`
Forwarding *Forwarding `json:"forwarding"`
}
Message contains info about message
type MessageRequest ¶
type MessageRequest struct {
EntityType EntityType `json:"entity_type,omitempty"`
EntityID uint `json:"entity_id,omitempty"`
ParentMessageID uint `json:"parent_message_id,omitempty"`
Content string `json:"content"`
DisplayAvatarURL string `json:"display_avatar_url,omitempty"`
DisplayName string `json:"display_name,omitempty"`
Files Files `json:"files,omitzero"`
Buttons Buttons `json:"buttons,omitzero"`
SkipInviteMentions bool `json:"skip_invite_mentions,omitempty"`
}
MessageRequest is a struct with information needed to create or modify a message
type Metadata ¶ added in v0.10.0
type Metadata struct {
Paginate *Paginate `json:"paginate"`
}
Metadata is listing metadata
type Paginate ¶ added in v0.10.0
type Paginate struct {
NextPage string `json:"next_page"`
}
Paginate contains cursor to the next page
type Properties ¶
type Properties []*Property
Properties is a slice of properties
func (Properties) Find ¶ added in v0.1.0
func (p Properties) Find(name string) *Property
Find returns custom property with given name
func (Properties) FindAny ¶ added in v0.1.0
func (p Properties) FindAny(name ...string) *Property
FindAny returns first found property with one of given names
func (Properties) Get ¶
func (p Properties) Get(id uint) *Property
Get returns custom property with given ID
func (Properties) Has ¶ added in v0.1.0
func (p Properties) Has(name string) bool
Has returns true if properties contains property with given name
func (Properties) HasAny ¶ added in v0.1.0
func (p Properties) HasAny(name ...string) bool
HasAny returns true if properties contains property with one of given names
func (Properties) Names ¶ added in v0.0.2
func (p Properties) Names() []string
Names returns slice with properties names
type Property ¶
type Property struct {
ID uint `json:"id"`
Type PropertyType `json:"data_type"`
Name string `json:"name"`
Value string `json:"value"`
}
Property is custom property
type PropertyRequest ¶ added in v0.1.1
PropertyRequest is a struct with property info
func NewPropertyRequest ¶ added in v0.1.1
func NewPropertyRequest(id uint, value any) *PropertyRequest
NewPropertyRequest creates new custom property
type PropertyRequests ¶ added in v0.1.1
type PropertyRequests []*PropertyRequest
PropertyRequests is a slice with properties requests
type PropertyType ¶
type PropertyType string
PropertyType is type for property type
const ( PROP_TYPE_DATE PropertyType = "date" PROP_TYPE_LINK PropertyType = "link" PROP_TYPE_NUMBER PropertyType = "number" PROP_TYPE_TEXT PropertyType = "text" )
type Reaction ¶
type Reaction struct {
UserID uint `json:"user_id"`
CreatedAt Date `json:"created_at"`
Emoji string `json:"code"`
Name string `json:"name"`
}
Reaction contains reaction info
type ReactionRequest ¶ added in v0.12.0
ReactionRequest is a payload for message reaction
type Status ¶
type Status struct {
Emoji string `json:"emoji"`
Title string `json:"title"`
ExpiresAt Date `json:"expires_at"`
}
Status is user status
type Tag ¶
type Tag struct {
ID uint `json:"id"`
Name string `json:"name"`
UsersCount int `json:"users_count"`
}
Tag contains info about tag
type Tags ¶
type Tags []*Tag
Tags is a slice of tags
type Thread ¶
type Thread struct {
ID uint `json:"id"`
ChatID uint `json:"chat_id"`
MessageID uint `json:"message_id"`
MessageChatID uint `json:"message_chat_id"`
UpdatedAt Date `json:"updated_at"`
}
Thread contains info about thread
type Upload ¶
type Upload struct {
ContentDisposition string `json:"Content-Disposition"`
ACL string `json:"acl"`
Policy string `json:"policy"`
Credential string `json:"x-amz-credential"`
Algorithm string `json:"x-amz-algorithm"`
Date string `json:"x-amz-date"`
Signature string `json:"x-amz-signature"`
Key string `json:"key"`
DirectURL string `json:"direct_url"`
}
Upload contains upload info used for uploading files
type User ¶
type User struct {
ID uint `json:"id"`
CreatedAt Date `json:"created_at"`
LastActivityAt Date `json:"last_activity_at"`
ImageURL string `json:"image_url"`
Email string `json:"email"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Nickname string `json:"nickname"`
Role UserRole `json:"role"`
PhoneNumber string `json:"phone_number"`
TimeZone string `json:"time_zone"`
Title string `json:"title"`
InviteStatus InviteStatus `json:"invite_status"`
Department string `json:"department"`
Properties Properties `json:"custom_properties"`
Tags []string `json:"list_tags"`
Status *Status `json:"user_status"`
IsBot bool `json:"bot"`
IsSuspended bool `json:"suspended"`
IsSSO bool `json:"sso"`
}
User contains info about user
func (*User) IsMultiGuest ¶ added in v0.10.2
IsMultiGuest returns true if user is multi-guest
type UserRequest ¶
type UserRequest struct {
Email string `json:"email,omitempty"`
FirstName string `json:"first_name,omitempty"`
LastName string `json:"last_name,omitempty"`
Nickname string `json:"nickname,omitempty"`
Role UserRole `json:"role,omitempty"`
PhoneNumber string `json:"phone_number,omitempty"`
Title string `json:"title,omitempty"`
Department string `json:"department,omitempty"`
Properties PropertyRequests `json:"custom_properties,omitempty"`
Tags []string `json:"list_tags,omitempty"`
IsSuspended bool `json:"suspended,omitempty"`
SkipEmailNotify bool `json:"skip_email_notify,omitempty"`
}
UserRequest is a struct with information needed to create or modify a user
type Users ¶
type Users []*User
Users is a slice of users
func (Users) MultiGuests ¶ added in v0.10.2
MultiGuests returns slice with multi-guests
func (Users) WithoutGuests ¶ added in v0.5.1
WithoutGuests returns slice with users without guests
type View ¶ added in v0.13.0
type View struct {
Title string `json:"title"`
CloseText string `json:"close_text,omitempty"`
SubmitText string `json:"submit_text,omitempty"`
Blocks []block.Block `json:"blocks"`
}
View contains form view
type ViewErrors ¶ added in v0.13.0
ViewErrors is a map with view errors
type ViewRequest ¶ added in v0.13.0
type ViewRequest struct {
Type ViewType `json:"type"`
TriggerID string `json:"trigger_id"`
Metadata string `json:"private_metadata,omitempty"`
CallbackID string `json:"callback_id,omitempty"`
View *View `json:"view"`
}
ViewRequest is a payload for open a view
type ViewType ¶ added in v0.13.0
type ViewType string
ViewType is type for view
const (
VIEW_MODAL ViewType = "modal"
)
type WebhookEvent ¶
type WebhookEvent struct {
ID string `json:"id"`
EventType string `json:"event_type"`
Payload json.RawMessage `json:"payload"`
}
WebhookEvent contains webhook event data