Skip to content

Commit 2be7899

Browse files
author
nukosuke
authored
Merge pull request #260 from pierce-m/ticket-comment-redaction
Add ticket comment redaction
2 parents c5a8eb7 + 5acdf46 commit 2be7899

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"comment": {
3+
"attachments": [],
4+
"author_id": 123,
5+
"id": 123,
6+
"plain_body": "My ID number is ▇▇▇▇!",
7+
"public": true,
8+
"type": "Comment"
9+
}
10+
}

zendesk/ticket_comment.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ type TicketComment struct {
3333
Via *Via `json:"via,omitempty"`
3434
}
3535

36+
// RedactTicketCommentRequest contains the body of the RedactTicketComment PUT request
37+
type RedactTicketCommentRequest struct {
38+
TicketID int64 `json:"ticket_id"` // Required
39+
HTMLBody string `json:"html_body,omitempty"`
40+
ExternalAttachmentUrls []string `json:"external_attachment_urls,omitempty"`
41+
}
42+
3643
// NewPublicTicketComment generates and returns a new TicketComment
3744
func NewPublicTicketComment(body string, authorID int64) TicketComment {
3845
public := true
@@ -111,3 +118,16 @@ func (z *Client) MakeCommentPrivate(ctx context.Context, ticketID int64, ticketC
111118
_, err := z.put(ctx, path, nil)
112119
return err
113120
}
121+
122+
// RedactTicketComment permanently removes words, strings, or attachments from a ticket comment
123+
//
124+
// ref: https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_comments/#redact-ticket-comment-in-agent-workspace
125+
func (z *Client) RedactTicketComment(
126+
ctx context.Context,
127+
ticketCommentID int64,
128+
body RedactTicketCommentRequest,
129+
) error {
130+
path := fmt.Sprintf("/api/v2/comment_redactions/%d.json", ticketCommentID)
131+
_, err := z.put(ctx, path, body)
132+
return err
133+
}

zendesk/ticket_comment_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,18 @@ func TestMakeCommentPrivate(t *testing.T) {
100100
})
101101
}
102102
}
103+
104+
func TestRedactTicketComment(t *testing.T) {
105+
mockAPI := newMockAPI(http.MethodPut, "redact_ticket_comment.json")
106+
client := newTestClient(mockAPI)
107+
defer mockAPI.Close()
108+
109+
err := client.RedactTicketComment(ctx, 123, RedactTicketCommentRequest{
110+
TicketID: 100,
111+
HTMLBody: "<div class=\"zd-comment\" dir=\"auto\">My ID number is <redact>847564</redact>!</div>",
112+
})
113+
114+
if err != nil {
115+
t.Fatalf("Failed to redact ticket comment: %s", err)
116+
}
117+
}

0 commit comments

Comments
 (0)