Skip to content

Commit a6cc2ee

Browse files
committed
[Components] richpanel #15105
Sources - New Ticket - New Message Actions - Create Ticket - Add Ticket Message - Update Ticket Status
1 parent 1777796 commit a6cc2ee

File tree

13 files changed

+127
-401
lines changed

13 files changed

+127
-401
lines changed

components/richpanel/actions/add-ticket-message/add-ticket-message.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "richpanel-add-ticket-message",
55
name: "Add Ticket Message",
66
description: "Adds a message to an existing ticket. [See the documentation](https://developer.richpanel.com/reference/update-a-conversation)",
7-
version: "0.0.{{ts}}",
7+
version: "0.0.1",
88
type: "action",
99
props: {
1010
richpanel,
@@ -40,7 +40,7 @@ export default {
4040
},
4141
},
4242
});
43-
$.export("$summary", `Added message to ticket ${this.messageId} successfully`);
43+
$.export("$summary", `Added message to ticket ${this.conversationId} successfully`);
4444
return response;
4545
},
4646
};

components/richpanel/actions/create-ticket/create-ticket.mjs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ConfigurationError } from "@pipedream/platform";
22
import { parseObject } from "../../common/utils.mjs";
33
import richpanel from "../../richpanel.app.mjs";
4+
import { VIA_CHANNEL_OPTIONS } from "./common/constants.mjs";
45

56
export default {
67
key: "richpanel-create-ticket",
@@ -36,23 +37,20 @@ export default {
3637
],
3738
},
3839
viaChannel: {
39-
propDefinition: [
40-
richpanel,
41-
"viaChannel",
42-
],
40+
type: "string",
41+
label: "Via Channel",
42+
description: "The channel via which the ticket is created",
43+
options: VIA_CHANNEL_OPTIONS,
4344
},
4445
viaSourceFrom: {
45-
propDefinition: [
46-
richpanel,
47-
"viaSourceFrom",
48-
],
46+
type: "object",
47+
label: "Via Source From",
48+
description: "The object source from which the ticket was created. **Examples: {\"address\": \"[email protected]\"} or {\"id\": \"+16692668044\"}. It depends on the selected channel**.",
4949
},
5050
viaSourceTo: {
51-
propDefinition: [
52-
richpanel,
53-
"viaSourceTo",
54-
],
55-
optional: true,
51+
type: "object",
52+
label: "Via Source To",
53+
description: "The object source to which the ticket was created. **Examples: {\"address\": \"[email protected]\"} or {\"id\": \"+16692668044\"}. It depends on the selected channel**.",
5654
},
5755
tags: {
5856
propDefinition: [

components/richpanel/actions/update-ticket-status/update-ticket-status.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "richpanel-update-ticket-status",
55
name: "Update Ticket Status",
66
description: "Updates the status of an existing ticket in Richpanel. [See the documentation](https://developer.richpanel.com/reference/update-a-conversation).",
7-
version: "0.0.{{ts}}",
7+
version: "0.0.1",
88
type: "action",
99
props: {
1010
richpanel,
@@ -24,6 +24,7 @@ export default {
2424
async run({ $ }) {
2525
const response = await this.richpanel.updateTicket({
2626
$,
27+
conversationId: this.conversationId,
2728
data: {
2829
ticket: {
2930
status: this.status,

components/richpanel/common/constants.mjs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ export const STATUS_OPTIONS = [
77
label: "Closed",
88
value: "CLOSED",
99
},
10-
{
11-
label: "Snoozed",
12-
value: "SNOOZED",
13-
},
1410
];
1511

1612
export const COMMENT_SENDER_TYPE_OPTIONS = [

components/richpanel/common/utils.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ export const parseObject = (obj) => {
2222
}
2323
return obj;
2424
};
25+
26+
export const camelToSnakeCase = (str) => str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);

components/richpanel/richpanel.app.mjs

Lines changed: 32 additions & 192 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { axios } from "@pipedream/platform";
22
import {
33
COMMENT_SENDER_TYPE_OPTIONS,
44
STATUS_OPTIONS,
5-
VIA_CHANNEL_OPTIONS,
65
} from "./common/constants.mjs";
76

87
export default {
@@ -17,7 +16,7 @@ export default {
1716
status: {
1817
type: "string",
1918
label: "Status",
20-
description: "The status of the new ticket",
19+
description: "The status of the ticket",
2120
options: STATUS_OPTIONS,
2221
},
2322
commentBody: {
@@ -31,22 +30,6 @@ export default {
3130
description: "The sender type of the comment",
3231
options: COMMENT_SENDER_TYPE_OPTIONS,
3332
},
34-
viaChannel: {
35-
type: "string",
36-
label: "Via Channel",
37-
description: "The channel via which the ticket is created",
38-
options: VIA_CHANNEL_OPTIONS,
39-
},
40-
viaSourceFrom: {
41-
type: "object",
42-
label: "Via Source From",
43-
description: "The object source from which the ticket was created. **Examples: {\"address\": \"[email protected]\"} or {\"id\": \"+16692668044\"}. It depends on the selected channel**.",
44-
},
45-
viaSourceTo: {
46-
type: "object",
47-
label: "Via Source To",
48-
description: "The object source to which the ticket was created. **Examples: {\"address\": \"[email protected]\"} or {\"id\": \"+16692668044\"}. It depends on the selected channel**.",
49-
},
5033
tags: {
5134
type: "string[]",
5235
label: "Tags",
@@ -62,137 +45,12 @@ export default {
6245
}));
6346
},
6447
},
65-
66-
eventFilterStatus: {
67-
type: "string[]",
68-
label: "Filter by Status",
69-
description: "Filter emitted events by ticket status",
70-
options: [
71-
{
72-
label: "Open",
73-
value: "OPEN",
74-
},
75-
{
76-
label: "Closed",
77-
value: "CLOSED",
78-
},
79-
{
80-
label: "Snoozed",
81-
value: "SNOOZED",
82-
},
83-
],
84-
},
85-
eventFilterPriority: {
86-
type: "string[]",
87-
label: "Filter by Priority",
88-
description: "Filter emitted events by ticket priority",
89-
options: [
90-
{
91-
label: "Low",
92-
value: "LOW",
93-
},
94-
{
95-
label: "Medium",
96-
value: "MEDIUM",
97-
},
98-
{
99-
label: "High",
100-
value: "HIGH",
101-
},
102-
],
103-
},
104-
eventFilterAssignedAgent: {
105-
type: "string[]",
106-
label: "Filter by Assigned Agent",
107-
description: "Filter emitted events by assigned agent",
108-
async options() {
109-
const tickets = await this.paginate(this.listTickets, {
110-
per_page: 100,
111-
});
112-
const agents = tickets.map((ticket) => ticket.assignee_id).filter(Boolean);
113-
const uniqueAgents = [
114-
...new Set(agents),
115-
];
116-
return uniqueAgents.map((agent) => ({
117-
label: agent,
118-
value: agent,
119-
}));
120-
},
121-
},
122-
eventFilterChannel: {
123-
type: "string[]",
124-
label: "Filter by Channel",
125-
description: "Filter emitted events by communication channel",
126-
options: [
127-
{
128-
label: "Email",
129-
value: "email",
130-
},
131-
{
132-
label: "Chat",
133-
value: "chat",
134-
},
135-
],
136-
},
137-
eventFilterDesiredStatuses: {
138-
type: "string[]",
139-
label: "Desired Statuses to Monitor",
140-
description: "Specify desired statuses to monitor for status updates",
141-
options: [
142-
{
143-
label: "Open",
144-
value: "OPEN",
145-
},
146-
{
147-
label: "Pending",
148-
value: "PENDING",
149-
},
150-
{
151-
label: "Resolved",
152-
value: "RESOLVED",
153-
},
154-
],
155-
},
156-
addMessageId: {
157-
type: "string",
158-
label: "Ticket ID",
159-
description: "ID of the ticket to add a message to",
160-
async options() {
161-
const tickets = await this.paginate(this.listTickets, {
162-
per_page: 100,
163-
});
164-
return tickets.map((ticket) => ({
165-
label: ticket.subject || ticket.id,
166-
value: ticket.id,
167-
}));
168-
},
169-
},
170-
addMessageBody: {
171-
type: "string",
172-
label: "Comment Body",
173-
description: "Body of the comment to add",
174-
},
175-
addMessageSenderType: {
176-
type: "string",
177-
label: "Comment Sender Type",
178-
description: "The sender type of the comment",
179-
options: [
180-
{
181-
label: "Customer",
182-
value: "customer",
183-
},
184-
{
185-
label: "Operator",
186-
value: "operator",
187-
},
188-
],
189-
},
19048
conversationId: {
19149
type: "string",
19250
label: "Ticket ID",
19351
description: "ID of the ticket to update",
19452
async options({ page }) {
195-
const ticket = await this.listTickets({
53+
const { ticket } = await this.listTickets({
19654
params: {
19755
page: page + 1,
19856
},
@@ -208,33 +66,6 @@ export default {
20866
}));
20967
},
21068
},
211-
updateStatus: {
212-
type: "string",
213-
label: "Status",
214-
description: "New status of the ticket",
215-
options: [
216-
{
217-
label: "Open",
218-
value: "OPEN",
219-
},
220-
{
221-
label: "Closed",
222-
value: "CLOSED",
223-
},
224-
{
225-
label: "Snoozed",
226-
value: "SNOOZED",
227-
},
228-
{
229-
label: "Pending",
230-
value: "PENDING",
231-
},
232-
{
233-
label: "Resolved",
234-
value: "RESOLVED",
235-
},
236-
],
237-
},
23869
},
23970
methods: {
24071
_baseUrl() {
@@ -249,14 +80,11 @@ export default {
24980
_makeRequest({
25081
$ = this, path, ...opts
25182
}) {
252-
const config = {
83+
return axios($, {
25384
url: this._baseUrl() + path,
25485
headers: this._headers(),
25586
...opts,
256-
};
257-
console.log("config: ", config);
258-
console.log("config: ", JSON.stringify(config));
259-
return axios($, config);
87+
});
26088
},
26189
createTicket(opts = {}) {
26290
return this._makeRequest({
@@ -273,7 +101,7 @@ export default {
273101
listTickets(opts = {}) {
274102
return this._makeRequest({
275103
path: "/tickets",
276-
opts,
104+
...opts,
277105
});
278106
},
279107
updateTicket({
@@ -286,23 +114,35 @@ export default {
286114
});
287115
},
288116

289-
// Pagination helper method
290-
async paginate(fn, opts = {}) {
291-
let results = [];
292-
let page = 1;
293-
let perPage = opts.per_page || 30;
294-
while (true) {
295-
const response = await fn({
117+
async *paginate({
118+
fn, params = {}, maxResults = null, ...opts
119+
}) {
120+
let hasMore = false;
121+
let count = 0;
122+
let page = 0;
123+
124+
do {
125+
params.page = ++page;
126+
const { ticket } = await fn({
127+
params,
296128
...opts,
297-
page,
298-
per_page: perPage,
299129
});
300-
if (!response || response.length === 0) break;
301-
results = results.concat(response);
302-
if (response.length < perPage) break;
303-
page += 1;
304-
}
305-
return results;
130+
131+
if (!ticket) {
132+
return;
133+
}
134+
135+
for (const d of ticket) {
136+
yield d;
137+
138+
if (maxResults && ++count === maxResults) {
139+
return count;
140+
}
141+
}
142+
143+
hasMore = ticket && ticket.length;
144+
145+
} while (hasMore);
306146
},
307147
},
308148
};

0 commit comments

Comments
 (0)