Repository: nukosuke/go-zendesk (go)

Issue:
No Redaction support
We would like to use this api for ticket comment redaction: https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_comments/#redact-ticket-comment-in-agent-workspace


Pull request description:
Add ticket comment redaction
Fixes #259 

Patch:
diff --git a/fixture/PUT/redact_ticket_comment.json b/fixture/PUT/redact_ticket_comment.json
new file mode 100644
index 0000000..bea4970
--- /dev/null
+++ b/fixture/PUT/redact_ticket_comment.json
@@ -0,0 +1,10 @@
+{
+  "comment": {
+    "attachments": [],
+    "author_id": 123,
+    "id": 123,
+    "plain_body": "My ID number is ▇▇▇▇!",
+    "public": true,
+    "type": "Comment"
+  }
+}
diff --git a/zendesk/ticket_comment.go b/zendesk/ticket_comment.go
index e1c14b2..59e9ea9 100644
--- a/zendesk/ticket_comment.go
+++ b/zendesk/ticket_comment.go
@@ -33,6 +33,13 @@ type TicketComment struct {
 	Via *Via `json:"via,omitempty"`
 }
 
+// RedactTicketCommentRequest contains the body of the RedactTicketComment PUT request
+type RedactTicketCommentRequest struct {
+	TicketID               int64    `json:"ticket_id"` // Required
+	HTMLBody               string   `json:"html_body,omitempty"`
+	ExternalAttachmentUrls []string `json:"external_attachment_urls,omitempty"`
+}
+
 // NewPublicTicketComment generates and returns a new TicketComment
 func NewPublicTicketComment(body string, authorID int64) TicketComment {
 	public := true
@@ -111,3 +118,16 @@ func (z *Client) MakeCommentPrivate(ctx context.Context, ticketID int64, ticketC
 	_, err := z.put(ctx, path, nil)
 	return err
 }
+
+// RedactTicketComment permanently removes words, strings, or attachments from a ticket comment
+//
+// ref: https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_comments/#redact-ticket-comment-in-agent-workspace
+func (z *Client) RedactTicketComment(
+	ctx context.Context,
+	ticketCommentID int64,
+	body RedactTicketCommentRequest,
+) error {
+	path := fmt.Sprintf("/api/v2/comment_redactions/%d.json", ticketCommentID)
+	_, err := z.put(ctx, path, body)
+	return err
+}


Test patch:
diff --git a/zendesk/ticket_comment_test.go b/zendesk/ticket_comment_test.go
index 731cef0..8943297 100644
--- a/zendesk/ticket_comment_test.go
+++ b/zendesk/ticket_comment_test.go
@@ -100,3 +100,18 @@ func TestMakeCommentPrivate(t *testing.T) {
 		})
 	}
 }
+
+func TestRedactTicketComment(t *testing.T) {
+	mockAPI := newMockAPI(http.MethodPut, "redact_ticket_comment.json")
+	client := newTestClient(mockAPI)
+	defer mockAPI.Close()
+
+	err := client.RedactTicketComment(ctx, 123, RedactTicketCommentRequest{
+		TicketID: 100,
+		HTMLBody: "<div class=\"zd-comment\" dir=\"auto\">My ID number is <redact>847564</redact>!</div>",
+	})
+
+	if err != nil {
+		t.Fatalf("Failed to redact ticket comment: %s", err)
+	}
+}