Skip to content

Commit

Permalink
Add new Inbox routes
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriansaliou committed Aug 1, 2024
1 parent c94c3f7 commit f91b966
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 12 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ Refer directly to [the library source code](https://github.com/crisp-im/go-crisp

* #### **Website Batch**
* **Batch Resolve Conversations** [`user`]: [Reference](https://docs.crisp.chat/references/rest-api/v1/#batch-resolve-items)
* `client.Website.BatchResolveConversations(websiteID string, sessions []string) (*Response, error)`
* `client.Website.BatchResolveConversations(websiteID string, operation WebsiteBatchConversationsOperation) (*Response, error)`
* **Batch Read Conversations** [`user`]: [Reference](https://docs.crisp.chat/references/rest-api/v1/#batch-read-items)
* `client.Website.BatchReadConversations(websiteID string, sessions []string) (*Response, error)`
* `client.Website.BatchReadConversations(websiteID string, operation WebsiteBatchConversationsOperation) (*Response, error)`
* **Batch Remove Conversations** [`user`]: [Reference](https://docs.crisp.chat/references/rest-api/v1/#batch-remove-items)
* `client.Website.BatchRemoveConversations(websiteID string, sessions []string) (*Response, error)`
* `client.Website.BatchRemoveConversations(websiteID string, operation WebsiteBatchConversationsOperation) (*Response, error)`
* **Batch Remove People** [`user`]: [Reference](https://docs.crisp.chat/references/rest-api/v1/#batch-remove-items)
* `client.Website.BatchRemovePeople(websiteID string, people WebsiteBatchPeopleOperationInner) (*Response, error)`

Expand Down Expand Up @@ -218,7 +218,7 @@ Refer directly to [the library source code](https://github.com/crisp-im/go-crisp
* **List Conversations (Search Variant)** [`user`, `plugin`]: [Reference](https://docs.crisp.chat/references/rest-api/v1/#list-conversations)
* `client.Website.SearchConversations(websiteID string, pageNumber uint, searchQuery string, searchType string) (*[]Conversation, *Response, error)`
* **List Conversations (Filter Variant)** [`user`, `plugin`]: [Reference](https://docs.crisp.chat/references/rest-api/v1/#list-conversations)
* `client.Website.FilterConversations(websiteID string, pageNumber uint, filterUnread bool, filterResolved bool, filterNotResolved bool, filterMention bool, filterAssigned bool, filterUnassigned bool) (*[]Conversation, *Response, error)`
* `client.Website.FilterConversations(websiteID string, pageNumber uint, filterInboxID string, filterUnread bool, filterResolved bool, filterNotResolved bool, filterMention bool, filterAssigned bool, filterUnassigned bool) (*[]Conversation, *Response, error)`
* **List Suggested Conversation Segments** [`user`, `plugin`]: [Reference](https://docs.crisp.chat/references/rest-api/v1/#list-suggested-conversation-segments)
* `client.Website.ListSuggestedConversationSegments(websiteID string, pageNumber uint) (*[]ConversationSuggestedSegment, *Response, error)`
* **Delete Suggested Conversation Segment** [`user`, `plugin`]: [Reference](https://docs.crisp.chat/references/rest-api/v1/#delete-suggested-conversation-segment)
Expand Down Expand Up @@ -295,6 +295,8 @@ Refer directly to [the library source code](https://github.com/crisp-im/go-crisp
* `client.Website.GetConversationRoutingAssign(websiteID string, sessionID string) (*ConversationRoutingAssign, *Response, error)`
* **⭐ Assign Conversation Routing** [`user`, `plugin`]: [Reference](https://docs.crisp.chat/references/rest-api/v1/#assign-conversation-routing)
* `client.Website.AssignConversationRouting(websiteID string, sessionID string, assign ConversationRoutingAssignUpdate) (*Response, error)`
* **Update Conversation Inbox** [`user`, `plugin`]: [Reference](https://docs.crisp.chat/references/rest-api/v1/#update-conversation-inbox)
* `client.Website.UpdateConversationInbox(websiteID string, sessionID string, inboxID *string) (*Response, error)`
* **⭐ Get Conversation Metas** [`user`, `plugin`]: [Reference](https://docs.crisp.chat/references/rest-api/v1/#get-conversation-metas)
* `client.Website.GetConversationMetas(websiteID string, sessionID string) (*ConversationMeta, *Response, error)`
* **⭐ Update Conversation Metas** [`user`, `plugin`]: [Reference](https://docs.crisp.chat/references/rest-api/v1/#update-conversation-metas)
Expand Down Expand Up @@ -650,6 +652,8 @@ Available events are listed below:
* `session:set_mentions`
* **Session Set Routing** [`user`, `plugin`]:
* `session:set_routing`
* **Session Set Inbox** [`user`, `plugin`]:
* `session:set_inbox`
* **Session Removed** [`user`, `plugin`]:
* `session:removed`

Expand Down
14 changes: 14 additions & 0 deletions crisp/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,14 @@ type EventsReceiveSessionSetRouting struct {
RoutingID *string `json:"routing_id"`
}

// EventsReceiveSessionSetInbox maps session:set_inbox
type EventsReceiveSessionSetInbox struct {
EventsGeneric
EventsSessionGeneric
InboxID *string `json:"inbox_id"`
PreviousInboxID *string `json:"previous_inbox_id,omitempty"`
}

// EventsReceiveSessionRemoved maps session:removed
type EventsReceiveSessionRemoved struct {
EventsGeneric
Expand Down Expand Up @@ -1102,6 +1110,12 @@ func (evt EventsReceiveSessionSetRouting) String() string {
}


// String returns the string representation of EventsReceiveSessionSetInbox
func (evt EventsReceiveSessionSetInbox) String() string {
return Stringify(evt)
}


// String returns the string representation of EventsReceiveSessionRemoved
func (evt EventsReceiveSessionRemoved) String() string {
return Stringify(evt)
Expand Down
13 changes: 7 additions & 6 deletions crisp/website_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

// WebsiteBatchConversationsOperation mapping
type WebsiteBatchConversationsOperation struct {
InboxID *string `json:"inbox_id,omitempty"`
Sessions []string `json:"sessions,omitempty"`
}

Expand All @@ -32,25 +33,25 @@ type WebsiteBatchPeopleOperationInnerSearch struct {
}

// BatchResolveConversations resolves given (or all) items in website (conversation variant).
func (service *WebsiteService) BatchResolveConversations(websiteID string, sessions []string) (*Response, error) {
func (service *WebsiteService) BatchResolveConversations(websiteID string, operation WebsiteBatchConversationsOperation) (*Response, error) {
url := fmt.Sprintf("website/%s/batch/resolve", websiteID)
req, _ := service.client.NewRequest("PATCH", url, WebsiteBatchConversationsOperation{Sessions: sessions})
req, _ := service.client.NewRequest("PATCH", url, operation)

return service.client.Do(req, nil)
}

// BatchReadConversations marks given (or all) items as read in website (conversation variant).
func (service *WebsiteService) BatchReadConversations(websiteID string, sessions []string) (*Response, error) {
func (service *WebsiteService) BatchReadConversations(websiteID string, operation WebsiteBatchConversationsOperation) (*Response, error) {
url := fmt.Sprintf("website/%s/batch/read", websiteID)
req, _ := service.client.NewRequest("PATCH", url, WebsiteBatchConversationsOperation{Sessions: sessions})
req, _ := service.client.NewRequest("PATCH", url, operation)

return service.client.Do(req, nil)
}

// BatchRemoveConversations removes given items in website (conversation variant).
func (service *WebsiteService) BatchRemoveConversations(websiteID string, sessions []string) (*Response, error) {
func (service *WebsiteService) BatchRemoveConversations(websiteID string, operation WebsiteBatchConversationsOperation) (*Response, error) {
url := fmt.Sprintf("website/%s/batch/remove", websiteID)
req, _ := service.client.NewRequest("PATCH", url, WebsiteBatchConversationsOperation{Sessions: sessions})
req, _ := service.client.NewRequest("PATCH", url, operation)

return service.client.Do(req, nil)
}
Expand Down
22 changes: 20 additions & 2 deletions crisp/website_conversation.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type ConversationData struct {
type Conversation struct {
SessionID *string `json:"session_id,omitempty"`
WebsiteID *string `json:"website_id,omitempty"`
InboxID *string `json:"inbox_id,omitempty"`
PeopleID *string `json:"people_id,omitempty"`
State *string `json:"state,omitempty"`
Status *uint8 `json:"status,omitempty"`
Expand Down Expand Up @@ -817,6 +818,11 @@ type ConversationOriginalData struct {
Data *ConversationOriginal `json:"data,omitempty"`
}

// ConversationInboxUpdate mapping
type ConversationInboxUpdate struct {
InboxID *string `json:"inbox_id,omitempty"`
}

// ConversationStateData mapping
type ConversationStateData struct {
Data *ConversationState `json:"data,omitempty"`
Expand Down Expand Up @@ -1140,8 +1146,9 @@ func (service *WebsiteService) SearchConversations(websiteID string, pageNumber


// FilterConversations filters conversations for website.
func (service *WebsiteService) FilterConversations(websiteID string, pageNumber uint, filterUnread bool, filterResolved bool, filterNotResolved bool, filterMention bool, filterAssigned bool, filterUnassigned bool) (*[]Conversation, *Response, error) {
func (service *WebsiteService) FilterConversations(websiteID string, pageNumber uint, filterInboxID string, filterUnread bool, filterResolved bool, filterNotResolved bool, filterMention bool, filterAssigned bool, filterUnassigned bool) (*[]Conversation, *Response, error) {
var (
filterInboxIDValue string
filterUnreadValue string
filterResolvedValue string
filterNotResolvedValue string
Expand All @@ -1150,6 +1157,8 @@ func (service *WebsiteService) FilterConversations(websiteID string, pageNumber
filterUnassignedValue string
)

filterInboxIDValue = filterInboxID

if filterUnread == true {
filterUnreadValue = "1"
} else {
Expand Down Expand Up @@ -1186,7 +1195,7 @@ func (service *WebsiteService) FilterConversations(websiteID string, pageNumber
filterUnassignedValue = "0"
}

url := fmt.Sprintf("website/%s/conversations/%d?filter_unread=%s&filter_resolved=%s&filter_not_resolved=%s&filter_mention=%s&filter_assigned=%s&filter_unassigned=%s", websiteID, pageNumber, url.QueryEscape(filterUnreadValue), url.QueryEscape(filterResolvedValue), url.QueryEscape(filterNotResolvedValue), url.QueryEscape(filterMentionValue), url.QueryEscape(filterAssignedValue), url.QueryEscape(filterUnassignedValue))
url := fmt.Sprintf("website/%s/conversations/%d?filter_inbox_id=%s&filter_unread=%s&filter_resolved=%s&filter_not_resolved=%s&filter_mention=%s&filter_assigned=%s&filter_unassigned=%s", websiteID, pageNumber, url.QueryEscape(filterInboxIDValue), url.QueryEscape(filterUnreadValue), url.QueryEscape(filterResolvedValue), url.QueryEscape(filterNotResolvedValue), url.QueryEscape(filterMentionValue), url.QueryEscape(filterAssignedValue), url.QueryEscape(filterUnassignedValue))
req, _ := service.client.NewRequest("GET", url, nil)

conversations := new(ConversationListData)
Expand Down Expand Up @@ -1634,6 +1643,15 @@ func (service *WebsiteService) AssignConversationRouting(websiteID string, sessi
}


// UpdateConversationInbox updates inbox used for conversation.
func (service *WebsiteService) UpdateConversationInbox(websiteID string, sessionID string, inboxID *string) (*Response, error) {
url := fmt.Sprintf("website/%s/conversation/%s/inbox", websiteID, sessionID)
req, _ := service.client.NewRequest("PATCH", url, ConversationInboxUpdate{&inboxID})

return service.client.Do(req, nil)
}


// GetConversationMetas resolves conversation meta information.
func (service *WebsiteService) GetConversationMetas(websiteID string, sessionID string) (*ConversationMeta, *Response, error) {
url := fmt.Sprintf("website/%s/conversation/%s/meta", websiteID, sessionID)
Expand Down
1 change: 1 addition & 0 deletions crisp/website_visitors.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type WebsiteVisitorListData struct {
// WebsiteVisitor mapping
type WebsiteVisitor struct {
SessionID *string `json:"session_id,omitempty"`
InboxID *string `json:"inbox_id,omitempty"`
Nickname *string `json:"nickname,omitempty"`
Email *string `json:"email,omitempty"`
Avatar *string `json:"avatar,omitempty"`
Expand Down

0 comments on commit f91b966

Please sign in to comment.