Skip to content

Commit db457a5

Browse files
authored
Zendesk - adding "ticketData" property to emitted comments (#18266)
* Adding "ticketData" property to emitted comments * Regexp updates for comment parsing
1 parent 0151fa0 commit db457a5

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

components/zendesk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/zendesk",
3-
"version": "0.8.3",
3+
"version": "0.9.0",
44
"description": "Pipedream Zendesk Components",
55
"main": "zendesk.app.mjs",
66
"keywords": [

components/zendesk/sources/new-ticket-comment-added/new-ticket-comment-added.mjs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default {
77
key: "zendesk-new-ticket-comment-added",
88
type: "source",
99
description: "Emit new event when a ticket comment has been added",
10-
version: "0.0.3",
10+
version: "0.1.0",
1111
dedupe: "unique",
1212
props: {
1313
app,
@@ -59,9 +59,14 @@ export default {
5959
},
6060
convertCommentsToJson(raw) {
6161
return [
62-
...raw.matchAll(/#<Comment (.*?)>/g),
62+
...raw.matchAll(/#<Comment (.*?)(value: "[^"]*")(.*?)>/g),
6363
].map((match) => {
64-
const fields = match[1]
64+
const valueField = match[0].match(/(?<=, )value: "([^"]|\\")*[^\\]",/)?.[0];
65+
const baseMatch = match[0].replace(/^#<Comment /, "");
66+
const baseMatchWithoutValue = valueField
67+
? baseMatch.split(valueField).join("")
68+
: baseMatch;
69+
const fields = baseMatchWithoutValue
6570
.split(",")
6671
.map((part) => part.trim())
6772
.map((pair) => {
@@ -81,7 +86,15 @@ export default {
8186
cleaned,
8287
];
8388
});
84-
return Object.fromEntries(fields);
89+
return Object.fromEntries(valueField
90+
? [
91+
...fields,
92+
[
93+
"value",
94+
valueField?.replace(/^value: ?/, ""),
95+
],
96+
]
97+
: fields);
8598
});
8699
},
87100
isRelevant(payload) {
@@ -97,10 +110,16 @@ export default {
97110
},
98111
emitEvent(payload) {
99112
payload.ticketComments = this.convertCommentsToJson(payload.ticketComments);
100-
for (const comment of payload.ticketComments) {
113+
const {
114+
ticketComments, ...ticketData
115+
} = payload;
116+
for (const comment of ticketComments) {
101117
const ts = Date.parse(comment.created_at);
102118
const id = `${payload.ticketId}-${ts}`;
103-
this.$emit(comment, {
119+
this.$emit({
120+
...comment,
121+
ticketData,
122+
}, {
104123
id,
105124
summary: comment.value,
106125
ts,

0 commit comments

Comments
 (0)