@@ -10,7 +10,7 @@ import (
10
10
// TicketCommentAPI is an interface containing all ticket comment related API methods
11
11
type TicketCommentAPI interface {
12
12
CreateTicketComment (ctx context.Context , ticketID int64 , ticketComment TicketComment ) (TicketComment , error )
13
- ListTicketComments (ctx context.Context , ticketID int64 ) ([] TicketComment , error )
13
+ ListTicketComments (ctx context.Context , ticketID int64 , opts * ListTicketCommentsOptions ) (* ListTicketCommentsResult , error )
14
14
MakeCommentPrivate (ctx context.Context , ticketID int64 , ticketCommentID int64 ) error
15
15
}
16
16
@@ -89,25 +89,65 @@ func (z *Client) CreateTicketComment(ctx context.Context, ticketID int64, ticket
89
89
return result , err
90
90
}
91
91
92
+ type listTicketCommentsSort string
93
+
94
+ const (
95
+ // TicketCommentCreatedAtAsc defines ASC sort val.
96
+ TicketCommentCreatedAtAsc listTicketCommentsSort = "created_at"
97
+
98
+ // TicketCommentCreatedAtDesc defines DESC sort val.
99
+ TicketCommentCreatedAtDesc listTicketCommentsSort = "-created_at"
100
+
101
+ // ListTicketCommentsMaxPageSize contains the max page size.
102
+ ListTicketCommentsMaxPageSize int = 100
103
+ )
104
+
105
+ // ListTicketCommentOptions contains all the options supported by ListTicketComments endpoint.
106
+ type ListTicketCommentsOptions struct {
107
+ CursorPagination
108
+
109
+ Include string `url:"include,omitempty"`
110
+ IncludeInlineImages string `url:"include_inline_images,omitempty"`
111
+ Sort listTicketCommentsSort `url:"sort,omitempty"`
112
+ }
113
+
114
+ // ListTicketCommentsResult contains the resulting ticket comments
115
+ // and cursor pagination metadata.
116
+ type ListTicketCommentsResult struct {
117
+ TicketComments []TicketComment `json:"comments"`
118
+ Meta CursorPaginationMeta `json:"meta"`
119
+ }
120
+
92
121
// ListTicketComments gets a list of comment for a specified ticket
93
122
//
94
123
// ref: https://developer.zendesk.com/rest_api/docs/support/ticket_comments#list-comments
95
- func (z * Client ) ListTicketComments (ctx context.Context , ticketID int64 ) ([]TicketComment , error ) {
96
- var result struct {
97
- TicketComments []TicketComment `json:"comments"`
124
+ func (z * Client ) ListTicketComments (
125
+ ctx context.Context ,
126
+ ticketID int64 ,
127
+ opts * ListTicketCommentsOptions ,
128
+ ) (* ListTicketCommentsResult , error ) {
129
+ url := fmt .Sprintf ("/tickets/%d/comments.json" , ticketID )
130
+
131
+ var err error
132
+ if opts != nil {
133
+ url , err = addOptions (url , opts )
134
+ if err != nil {
135
+ return nil , err
136
+ }
98
137
}
99
138
100
- body , err := z .get (ctx , fmt . Sprintf ( "/tickets/%d/comments.json" , ticketID ) )
139
+ body , err := z .get (ctx , url )
101
140
if err != nil {
102
- return [] TicketComment {} , err
141
+ return nil , err
103
142
}
104
143
144
+ var result ListTicketCommentsResult
105
145
err = json .Unmarshal (body , & result )
106
146
if err != nil {
107
- return [] TicketComment {} , err
147
+ return nil , err
108
148
}
109
149
110
- return result . TicketComments , err
150
+ return & result , err
111
151
}
112
152
113
153
// MakeCommentPrivate converts an existing ticket comment to an internal note that is not publicly viewable.
0 commit comments