Skip to content

Commit 99fa451

Browse files
authored
[ACTION] Gorgias — Create a ticket message (#15486)
* create-ticket-message updates per QA * pnpm-lock.yaml * fix * add configuration error
1 parent 738d2fb commit 99fa451

File tree

12 files changed

+116
-48
lines changed

12 files changed

+116
-48
lines changed

components/gorgias_oauth/actions/create-customer/create-customer.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "gorgias_oauth-create-customer",
66
name: "Create Customer",
77
description: "Create a new customer. [See the docs](https://developers.gorgias.com/reference/post_api-customers)",
8-
version: "0.0.5",
8+
version: "0.0.6",
99
type: "action",
1010
props: {
1111
gorgias_oauth,

components/gorgias_oauth/actions/create-ticket-message/create-ticket-message.mjs

Lines changed: 89 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import gorgiasOauth from "../../gorgias_oauth.app.mjs";
2-
import constants from "../../common/constants.mjs";
32
import {
43
axios, ConfigurationError,
54
} from "@pipedream/platform";
@@ -8,7 +7,7 @@ export default {
87
key: "gorgias_oauth-create-ticket-message",
98
name: "Create Ticket Message",
109
description: "Create a message for a ticket in the Gorgias system. [See the documentation](https://developers.gorgias.com/reference/create-ticket-message)",
11-
version: "0.0.1",
10+
version: "0.0.2",
1211
type: "action",
1312
props: {
1413
gorgiasOauth,
@@ -19,25 +18,49 @@ export default {
1918
],
2019
description: "The ID of the ticket to add a message to",
2120
},
22-
channel: {
21+
fromAgent: {
22+
type: "boolean",
23+
label: "From Agent",
24+
description: "Whether the message was sent by your company to a customer, or the opposite",
25+
reloadProps: true,
26+
},
27+
fromUser: {
2328
propDefinition: [
2429
gorgiasOauth,
25-
"channel",
30+
"userId",
2631
],
32+
label: "From User",
33+
description: "User who sent the message",
34+
optional: false,
35+
hidden: true,
2736
},
28-
fromAddress: {
37+
toUser: {
2938
propDefinition: [
3039
gorgiasOauth,
31-
"address",
40+
"userId",
3241
],
33-
label: "From Address",
42+
label: "To User",
43+
description: "The user receiving the message",
44+
optional: false,
45+
hidden: true,
3446
},
35-
toAddress: {
47+
fromCustomer: {
3648
propDefinition: [
3749
gorgiasOauth,
38-
"address",
50+
"customerId",
3951
],
40-
label: "To Address",
52+
label: "From Customer",
53+
description: "The customer who sent the message",
54+
hidden: true,
55+
},
56+
toCustomer: {
57+
propDefinition: [
58+
gorgiasOauth,
59+
"customerId",
60+
],
61+
label: "To Customer",
62+
description: "The customer receiving the message",
63+
hidden: true,
4164
},
4265
message: {
4366
type: "string",
@@ -70,37 +93,21 @@ export default {
7093
description: "The name of the file to attach",
7194
optional: true,
7295
},
73-
fromAgent: {
74-
type: "boolean",
75-
label: "From Agent",
76-
description: "Whether the message was sent by your company to a customer, or the opposite",
77-
default: false,
78-
optional: true,
79-
},
8096
sentDatetime: {
8197
type: "string",
8298
label: "Sent Datetime",
8399
description: "When the message was sent. If ommited, the message will be sent by Gorgias. E.g. `2025-01-27T19:38:52.028Z`",
84100
optional: true,
85101
},
86-
sourceType: {
87-
type: "string",
88-
label: "Source Type",
89-
description: "Describes more detailed channel information of how the message is sent/received",
90-
options: constants.sourceTypes,
91-
optional: true,
92-
},
102+
},
103+
additionalProps(props) {
104+
props.toUser.hidden = this.fromAgent;
105+
props.fromCustomer.hidden = this.fromAgent;
106+
props.toCustomer.hidden = !this.fromAgent;
107+
props.fromUser.hidden = !this.fromAgent;
108+
return {};
93109
},
94110
methods: {
95-
createMessage({
96-
ticketId, ...opts
97-
}) {
98-
return this.gorgiasOauth._makeRequest({
99-
method: "POST",
100-
path: `/tickets/${ticketId}/messages`,
101-
...opts,
102-
});
103-
},
104111
async getAttachmentInfo($, url) {
105112
const { headers } = await axios($, {
106113
method: "HEAD",
@@ -112,6 +119,26 @@ export default {
112119
size: headers["content-length"],
113120
};
114121
},
122+
async getEmail($, id, type = "from") {
123+
const {
124+
gorgiasOauth: {
125+
retrieveUser, retrieveCustomer,
126+
},
127+
} = this;
128+
const fn = this.fromAgent
129+
? type === "from"
130+
? retrieveUser
131+
: retrieveCustomer
132+
: type === "from"
133+
? retrieveCustomer
134+
: retrieveUser;
135+
136+
const { email } = await fn({
137+
$,
138+
id,
139+
});
140+
return email;
141+
},
115142
},
116143
async run({ $ }) {
117144
if ((this.attachmentUrl && !this.attachmentName)
@@ -127,19 +154,37 @@ export default {
127154
} = await this.getAttachmentInfo($, this.attachmentUrl));
128155
}
129156

130-
const response = await this.createMessage({
157+
const fromId = this.fromAgent
158+
? this.fromUser
159+
: this.fromCustomer;
160+
161+
const toId = this.fromAgent
162+
? this.toCustomer
163+
: this.toUser;
164+
165+
if (!fromId) {
166+
throw new ConfigurationError(`"${this.fromAgent
167+
? "From User"
168+
: "From Customer"}" is required when "From Agent" is set to \`${this.fromAgent}\``);
169+
}
170+
if (!toId) {
171+
throw new ConfigurationError(`"${this.fromAgent
172+
? "To Customer"
173+
: "To User"}" is required when "From Agent" is set to \`${this.fromAgent}\``);
174+
}
175+
176+
const response = await this.gorgiasOauth.createMessage({
131177
$,
132178
ticketId: this.ticketId,
133179
data: {
134-
channel: this.channel,
180+
channel: "email",
135181
source: {
136-
type: this.sourceType,
137182
from: {
138-
address: this.fromAddress,
183+
address: await this.getEmail($, fromId, "from"),
139184
},
140185
to: [
141186
{
142-
address: this.toAddress,
187+
address: await this.getEmail($, toId, "to"),
143188
},
144189
],
145190
},
@@ -156,6 +201,12 @@ export default {
156201
size,
157202
},
158203
],
204+
sender: {
205+
id: fromId,
206+
},
207+
receiver: {
208+
id: toId,
209+
},
159210
},
160211
});
161212

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "gorgias_oauth-create-ticket",
55
name: "Create Ticket",
66
description: "Create a new ticket. [See the docs](https://developers.gorgias.com/reference/post_api-tickets)",
7-
version: "0.0.6",
7+
version: "0.0.7",
88
type: "action",
99
props: {
1010
gorgias_oauth,

components/gorgias_oauth/actions/list-tickets/list-tickets.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "gorgias_oauth-list-tickets",
55
name: "List Tickets",
66
description: "List all tickets. [See the docs](https://developers.gorgias.com/reference/get_api-tickets)",
7-
version: "0.0.6",
7+
version: "0.0.7",
88
type: "action",
99
props: {
1010
gorgias_oauth,

components/gorgias_oauth/actions/retrieve-customer/retrieve-customer.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "gorgias_oauth-retrieve-customer",
55
name: "Retrieve a Customer",
66
description: "Retrieve a customer. [See the docs](https://developers.gorgias.com/reference/get_api-customers-id-)",
7-
version: "0.0.5",
7+
version: "0.0.6",
88
type: "action",
99
props: {
1010
gorgias_oauth,

components/gorgias_oauth/actions/update-customer/update-customer.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default {
1010
key: "gorgias_oauth-update-customer",
1111
name: "Update Customer",
1212
description: "Update a customer. [See the docs](https://developers.gorgias.com/reference/put_api-customers-id-)",
13-
version: "0.0.5",
13+
version: "0.0.6",
1414
type: "action",
1515
props: {
1616
gorgias_oauth,

components/gorgias_oauth/actions/update-ticket/update-ticket.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "gorgias_oauth-update-ticket",
66
name: "Update Ticket",
77
description: "Updates a predefined ticket in the Gorgias system. [See the documentation](https://developers.gorgias.com/reference/update-ticket)",
8-
version: "0.0.2",
8+
version: "0.0.3",
99
type: "action",
1010
props: {
1111
gorgiasOauth,

components/gorgias_oauth/gorgias_oauth.app.mjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,14 @@ export default {
329329
path: `customers/${id}`,
330330
});
331331
},
332+
async retrieveUser({
333+
$, id,
334+
}) {
335+
return this._makeRequest({
336+
$,
337+
path: `users/${id}`,
338+
});
339+
},
332340
async listCustomers({
333341
$, params,
334342
}) {
@@ -393,5 +401,14 @@ export default {
393401
...opts,
394402
});
395403
},
404+
createMessage({
405+
ticketId, ...opts
406+
}) {
407+
return this._makeRequest({
408+
method: "POST",
409+
path: `/tickets/${ticketId}/messages`,
410+
...opts,
411+
});
412+
},
396413
},
397414
};

components/gorgias_oauth/package.json

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

components/gorgias_oauth/sources/ticket-created/ticket-created.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default {
77
key: "gorgias_oauth-ticket-created",
88
name: "New Ticket",
99
description: "Emit new event when a ticket is created. [See the documentation](https://developers.gorgias.com/reference/the-event-object)",
10-
version: "0.1.6",
10+
version: "0.1.7",
1111
type: "source",
1212
props: {
1313
...base.props,

0 commit comments

Comments
 (0)