Skip to content

Commit 10e798c

Browse files
committed
new components
1 parent 28e91bb commit 10e798c

File tree

14 files changed

+497
-2
lines changed

14 files changed

+497
-2
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import gorgias_oauth from "../../gorgias_oauth.app.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
3+
import constants from "../../common/constants.mjs";
4+
5+
export default {
6+
key: "gorgias_oauth-create-macro",
7+
name: "Create Macro",
8+
description: "Create a macro. [See the documentation](https://developers.gorgias.com/reference/create-macro)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
gorgias_oauth,
13+
name: {
14+
type: "string",
15+
label: "Name",
16+
description: "The name of the Macro. Tips: choose a name that can be easily searched.",
17+
},
18+
intent: {
19+
type: "string",
20+
label: "Intent",
21+
description: "The intention of the macro should be used for",
22+
optional: true,
23+
options: constants.macroIntents,
24+
},
25+
language: {
26+
propDefinition: [
27+
gorgias_oauth,
28+
"language",
29+
],
30+
description: "The language of the macro",
31+
},
32+
actions: {
33+
type: "string[]",
34+
label: "Actions",
35+
description: `A list of actions to be applied on tickets. [See the documentation](https://developers.gorgias.com/reference/create-macro) for more info.
36+
\nExample: [{
37+
"arguments": {
38+
"tags": "question, order-status"
39+
},
40+
"name": "addTags",
41+
"title": "add tags",
42+
"type": "user"
43+
}]`,
44+
optional: true,
45+
},
46+
},
47+
async run({ $ }) {
48+
const data = {
49+
name: this.name,
50+
intent: this.intent,
51+
language: this.language,
52+
actions: parseObject(this.actions),
53+
};
54+
const response = await this.gorgias_oauth.createMacro({
55+
$,
56+
data,
57+
});
58+
$.export("$summary", `Successfully created macro ${response.id}`);
59+
return response;
60+
},
61+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import gorgias_oauth from "../../gorgias_oauth.app.mjs";
2+
3+
export default {
4+
key: "gorgias_oauth-delete-macro",
5+
name: "Delete Macro",
6+
description: "Delete a macro. [See the documentation](https://developers.gorgias.com/reference/delete-macro)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
gorgias_oauth,
11+
macroId: {
12+
propDefinition: [
13+
gorgias_oauth,
14+
"macroId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.gorgias_oauth.deleteMacro({
20+
$,
21+
id: this.macroId,
22+
});
23+
$.export("$summary", `Successfully deleted macro ${this.macroId}`);
24+
return response;
25+
},
26+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import gorgias_oauth from "../../gorgias_oauth.app.mjs";
2+
3+
export default {
4+
key: "gorgias_oauth-get-ticket",
5+
name: "Get Ticket",
6+
description: "Get a ticket. [See the documentation](https://developers.gorgias.com/reference/get-ticket)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
gorgias_oauth,
11+
ticketId: {
12+
propDefinition: [
13+
gorgias_oauth,
14+
"ticketId",
15+
],
16+
description: "The ID of a ticket to get",
17+
},
18+
},
19+
async run({ $ }) {
20+
const response = await this.gorgias_oauth.retrieveTicket({
21+
$,
22+
id: this.ticketId,
23+
});
24+
$.export("$summary", `Successfully retrieved ticket with ID: ${this.ticketId}`);
25+
return response;
26+
},
27+
};
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import gorgias_oauth from "../../gorgias_oauth.app.mjs";
2+
3+
export default {
4+
key: "gorgias_oauth-list-macros",
5+
name: "List Macros",
6+
description: "List all macros. [See the documentation](https://developers.gorgias.com/reference/list-macros)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
gorgias_oauth,
11+
search: {
12+
type: "string",
13+
label: "Search",
14+
description: "Filter macros containing the given search query",
15+
optional: true,
16+
},
17+
limit: {
18+
propDefinition: [
19+
gorgias_oauth,
20+
"limit",
21+
],
22+
},
23+
},
24+
async run({ $ }) {
25+
const params = {
26+
search: this.search,
27+
limit: this.limit,
28+
};
29+
30+
const macros = [];
31+
const paginator = this.gorgias_oauth.paginate({
32+
$,
33+
fn: this.gorgias_oauth.listMacros,
34+
params,
35+
});
36+
for await (const macro of paginator) {
37+
macros.push(macro);
38+
}
39+
40+
const suffix = macros.length === 1
41+
? ""
42+
: "s";
43+
$.export("$summary", `Returned ${macros.length} macro${suffix}`);
44+
return macros;
45+
},
46+
};
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import gorgias_oauth from "../../gorgias_oauth.app.mjs";
2+
import constants from "../../common/constants.mjs";
3+
import { parseObject } from "../../common/utils.mjs";
4+
5+
export default {
6+
key: "gorgias_oauth-update-macro",
7+
name: "Update Macro",
8+
description: "Update a macro. [See the documentation](https://developers.gorgias.com/reference/update-macro)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
gorgias_oauth,
13+
macroId: {
14+
propDefinition: [
15+
gorgias_oauth,
16+
"macroId",
17+
],
18+
},
19+
name: {
20+
type: "string",
21+
label: "Name",
22+
description: "The name of the Macro. Tips: choose a name that can be easily searched.",
23+
optional: true,
24+
},
25+
intent: {
26+
type: "string",
27+
label: "Intent",
28+
description: "The intention of the macro should be used for",
29+
optional: true,
30+
options: constants.macroIntents,
31+
},
32+
language: {
33+
propDefinition: [
34+
gorgias_oauth,
35+
"language",
36+
],
37+
description: "The language of the macro",
38+
},
39+
actions: {
40+
type: "string[]",
41+
label: "Actions",
42+
description: `A list of actions to be applied on tickets. [See the documentation](https://developers.gorgias.com/reference/create-macro) for more info.
43+
\nExample: [{
44+
"arguments": {
45+
"tags": "question, order-status"
46+
},
47+
"name": "addTags",
48+
"title": "add tags",
49+
"type": "user"
50+
}]`,
51+
optional: true,
52+
},
53+
},
54+
async run({ $ }) {
55+
const macro = await this.gorgias_oauth.getMacro({
56+
$,
57+
id: this.macroId,
58+
});
59+
const data = {
60+
name: this.name || macro.name,
61+
intent: this.intent,
62+
language: this.language,
63+
actions: parseObject(this.actions),
64+
};
65+
const response = await this.gorgias_oauth.updateMacro({
66+
$,
67+
id: this.macroId,
68+
data,
69+
});
70+
$.export("$summary", `Successfully updated macro ${response.id}`);
71+
return response;
72+
},
73+
};

components/gorgias_oauth/common/constants.mjs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,36 @@ const sourceTypes = [
100100
"whatsapp-message",
101101
];
102102

103+
const macroIntents = [
104+
"discount/request",
105+
"exchange/request",
106+
"exchange/status",
107+
"feedback",
108+
"order/damaged",
109+
"order/cancel",
110+
"order/change",
111+
"order/wrong",
112+
"other/no_reply",
113+
"other/question",
114+
"other/thanks",
115+
"product/recommendation",
116+
"product/question",
117+
"refund/request",
118+
"refund/status",
119+
"return/request",
120+
"return/status",
121+
"shipping/change",
122+
"shipping/delivery-issue",
123+
"shipping/policy",
124+
"shipping/status",
125+
"stock/request",
126+
"subscription/cancel",
127+
"subscription/change",
128+
];
129+
103130
export default {
104131
channels,
105132
vias,
106133
sourceTypes,
134+
macroIntents,
107135
};

components/gorgias_oauth/gorgias_oauth.app.mjs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,30 @@ export default {
8080
};
8181
},
8282
},
83+
macroId: {
84+
type: "integer",
85+
label: "Macro ID",
86+
description: "The ID of a macro",
87+
async options({ prevContext }) {
88+
const {
89+
data: macros,
90+
meta,
91+
} = await this.listMacros({
92+
params: {
93+
cursor: prevContext.nextCursor,
94+
},
95+
});
96+
return {
97+
options: macros.map((macro) => ({
98+
label: macro.name,
99+
value: macro.id,
100+
})),
101+
context: {
102+
nextCursor: meta.next_cursor,
103+
},
104+
};
105+
},
106+
},
83107
address: {
84108
type: "string",
85109
label: "Address",
@@ -410,5 +434,48 @@ export default {
410434
...opts,
411435
});
412436
},
437+
getMacro({
438+
$, id,
439+
}) {
440+
return this._makeRequest({
441+
$,
442+
path: `/macros/${id}`,
443+
});
444+
},
445+
listMacros(opts = {}) {
446+
return this._makeRequest({
447+
path: "/macros",
448+
...opts,
449+
});
450+
},
451+
createMacro({
452+
$, data,
453+
}) {
454+
return this._makeRequest({
455+
$,
456+
path: "/macros",
457+
method: "POST",
458+
data,
459+
});
460+
},
461+
updateMacro({
462+
$, id, data,
463+
}) {
464+
return this._makeRequest({
465+
$,
466+
path: `/macros/${id}`,
467+
method: "PUT",
468+
data,
469+
});
470+
},
471+
deleteMacro({
472+
$, id,
473+
}) {
474+
return this._makeRequest({
475+
$,
476+
path: `/macros/${id}`,
477+
method: "DELETE",
478+
});
479+
},
413480
},
414481
};

components/gorgias_oauth/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/gorgias_oauth",
3-
"version": "0.5.2",
3+
"version": "0.6.2",
44
"description": "Pipedream Gorgias OAuth Components",
55
"main": "gorgias_oauth.app.mjs",
66
"keywords": [
@@ -15,7 +15,7 @@
1515
"access": "public"
1616
},
1717
"dependencies": {
18-
"@pipedream/platform": "^2.0.0",
18+
"@pipedream/platform": "^3.1.0",
1919
"lodash-es": "^4.17.21"
2020
}
2121
}

0 commit comments

Comments
 (0)