forked from MEDIGO/go-zendesk
/
ticket_comment.go
74 lines (65 loc) · 2.18 KB
/
ticket_comment.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package zendesk
import (
"fmt"
"strings"
"time"
"github.com/google/go-querystring/query"
)
// TicketComment represents a comment on a Ticket.
//
// Zendesk Core API docs: https://developer.zendesk.com/rest_api/docs/core/ticket_comments
type TicketComment struct {
ID *int64 `json:"id,omitempty"`
Type *string `json:"type,omitempty"`
Body *string `json:"body,omitempty"`
HTMLBody *string `json:"html_body,omitempty"`
Public *bool `json:"public,omitempty"`
AuthorID *int64 `json:"author_id,omitempty"`
Attachments []Attachment `json:"attachments,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
Uploads []string `json:"uploads,omitempty"`
Via *Via `json:"via,omitempty"`
}
type RedactedString struct {
Text *string `json:"text"`
}
func (c *client) ListTicketComments(id int64) ([]TicketComment, error) {
out := new(APIPayload)
err := c.get(fmt.Sprintf("/api/v2/tickets/%d/comments.json", id), out)
return out.Comments, err
}
func (c *client) ListTicketCommentsFull(id int64, options *ListOptions, sideloads ...SideLoad) (*ListResponse, error) {
params, err := query.Values(options)
if err != nil {
return nil, err
}
sideLoads := &SideLoadOptions{}
for _, opt := range sideloads {
opt(sideLoads)
}
if len(sideLoads.Include) > 0 {
params.Set("include", strings.Join(sideLoads.Include, ","))
}
out := new(APIPayload)
err = c.get(fmt.Sprintf("/api/v2/tickets/%d/comments.json?%s", id, params.Encode()), out)
return &ListResponse{
Comments: out.Comments,
Users: out.Users,
Groups: out.Groups,
NextPage: out.NextPage,
PreviousPage: out.PreviousPage,
Count: out.Count,
}, err
}
// Redact Comment String removes a string in the comment text
//
// Zendesk Core API docs: https://developer.zendesk.com/rest_api/docs/core/ticket_comments#redact-string-in-comment
func (c *client) RedactCommentString(id, ticketID int64, text string) (*TicketComment, error) {
in := &RedactedString{Text: &text}
out := new(APIPayload)
err := c.put(
fmt.Sprintf("/api/v2/tickets/%d/comments/%d/redact.json", ticketID, id),
in,
out)
return out.Comment, err
}