Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
key: "gorgias_oauth-create-customer",
name: "Create Customer",
description: "Create a new customer. [See the docs](https://developers.gorgias.com/reference/post_api-customers)",
version: "0.0.5",
version: "0.0.6",
type: "action",
props: {
gorgias_oauth,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import gorgiasOauth from "../../gorgias_oauth.app.mjs";
import constants from "../../common/constants.mjs";
import {
axios, ConfigurationError,
} from "@pipedream/platform";
Expand All @@ -8,7 +7,7 @@ export default {
key: "gorgias_oauth-create-ticket-message",
name: "Create Ticket Message",
description: "Create a message for a ticket in the Gorgias system. [See the documentation](https://developers.gorgias.com/reference/create-ticket-message)",
version: "0.0.1",
version: "0.0.2",
type: "action",
props: {
gorgiasOauth,
Expand All @@ -19,25 +18,49 @@ export default {
],
description: "The ID of the ticket to add a message to",
},
channel: {
fromAgent: {
type: "boolean",
label: "From Agent",
description: "Whether the message was sent by your company to a customer, or the opposite",
reloadProps: true,
},
fromUser: {
propDefinition: [
gorgiasOauth,
"channel",
"userId",
],
label: "From User",
description: "User who sent the message",
optional: false,
hidden: true,
},
fromAddress: {
toUser: {
propDefinition: [
gorgiasOauth,
"address",
"userId",
],
label: "From Address",
label: "To User",
description: "The user receiving the message",
optional: false,
hidden: true,
},
toAddress: {
fromCustomer: {
propDefinition: [
gorgiasOauth,
"address",
"customerId",
],
label: "To Address",
label: "From Customer",
description: "The customer who sent the message",
hidden: true,
},
toCustomer: {
propDefinition: [
gorgiasOauth,
"customerId",
],
label: "To Customer",
description: "The customer receiving the message",
hidden: true,
},
message: {
type: "string",
Expand Down Expand Up @@ -70,37 +93,21 @@ export default {
description: "The name of the file to attach",
optional: true,
},
fromAgent: {
type: "boolean",
label: "From Agent",
description: "Whether the message was sent by your company to a customer, or the opposite",
default: false,
optional: true,
},
sentDatetime: {
type: "string",
label: "Sent Datetime",
description: "When the message was sent. If ommited, the message will be sent by Gorgias. E.g. `2025-01-27T19:38:52.028Z`",
optional: true,
},
sourceType: {
type: "string",
label: "Source Type",
description: "Describes more detailed channel information of how the message is sent/received",
options: constants.sourceTypes,
optional: true,
},
},
additionalProps(props) {
props.toUser.hidden = this.fromAgent;
props.fromCustomer.hidden = this.fromAgent;
props.toCustomer.hidden = !this.fromAgent;
props.fromUser.hidden = !this.fromAgent;
return {};
},
methods: {
createMessage({
ticketId, ...opts
}) {
return this.gorgiasOauth._makeRequest({
method: "POST",
path: `/tickets/${ticketId}/messages`,
...opts,
});
},
async getAttachmentInfo($, url) {
const { headers } = await axios($, {
method: "HEAD",
Expand All @@ -112,6 +119,26 @@ export default {
size: headers["content-length"],
};
},
async getEmail($, id, type = "from") {
const {
gorgiasOauth: {
retrieveUser, retrieveCustomer,
},
} = this;
const fn = this.fromAgent
? type === "from"
? retrieveUser
: retrieveCustomer
: type === "from"
? retrieveCustomer
: retrieveUser;

const { email } = await fn({
$,
id,
});
return email;
},
},
async run({ $ }) {
if ((this.attachmentUrl && !this.attachmentName)
Expand All @@ -127,19 +154,37 @@ export default {
} = await this.getAttachmentInfo($, this.attachmentUrl));
}

const response = await this.createMessage({
const fromId = this.fromAgent
? this.fromUser
: this.fromCustomer;

const toId = this.fromAgent
? this.toCustomer
: this.toUser;

if (!fromId) {
throw new ConfigurationError(`"${this.fromAgent
? "From User"
: "From Customer"}" is required when "From Agent" is set to \`${this.fromAgent}\``);
}
if (!toId) {
throw new ConfigurationError(`"${this.fromAgent
? "To Customer"
: "To User"}" is required when "From Agent" is set to \`${this.fromAgent}\``);
}

const response = await this.gorgiasOauth.createMessage({
$,
ticketId: this.ticketId,
data: {
channel: this.channel,
channel: "email",
source: {
type: this.sourceType,
from: {
address: this.fromAddress,
address: await this.getEmail($, fromId, "from"),
},
to: [
{
address: this.toAddress,
address: await this.getEmail($, toId, "to"),
},
],
},
Expand All @@ -156,6 +201,12 @@ export default {
size,
},
],
sender: {
id: fromId,
},
receiver: {
id: toId,
},
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "gorgias_oauth-create-ticket",
name: "Create Ticket",
description: "Create a new ticket. [See the docs](https://developers.gorgias.com/reference/post_api-tickets)",
version: "0.0.6",
version: "0.0.7",
type: "action",
props: {
gorgias_oauth,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "gorgias_oauth-list-tickets",
name: "List Tickets",
description: "List all tickets. [See the docs](https://developers.gorgias.com/reference/get_api-tickets)",
version: "0.0.6",
version: "0.0.7",
type: "action",
props: {
gorgias_oauth,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "gorgias_oauth-retrieve-customer",
name: "Retrieve a Customer",
description: "Retrieve a customer. [See the docs](https://developers.gorgias.com/reference/get_api-customers-id-)",
version: "0.0.5",
version: "0.0.6",
type: "action",
props: {
gorgias_oauth,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default {
key: "gorgias_oauth-update-customer",
name: "Update Customer",
description: "Update a customer. [See the docs](https://developers.gorgias.com/reference/put_api-customers-id-)",
version: "0.0.5",
version: "0.0.6",
type: "action",
props: {
gorgias_oauth,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
key: "gorgias_oauth-update-ticket",
name: "Update Ticket",
description: "Updates a predefined ticket in the Gorgias system. [See the documentation](https://developers.gorgias.com/reference/update-ticket)",
version: "0.0.2",
version: "0.0.3",
type: "action",
props: {
gorgiasOauth,
Expand Down
17 changes: 17 additions & 0 deletions components/gorgias_oauth/gorgias_oauth.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,14 @@ export default {
path: `customers/${id}`,
});
},
async retrieveUser({
$, id,
}) {
return this._makeRequest({
$,
path: `users/${id}`,
});
},
async listCustomers({
$, params,
}) {
Expand Down Expand Up @@ -393,5 +401,14 @@ export default {
...opts,
});
},
createMessage({
ticketId, ...opts
}) {
return this._makeRequest({
method: "POST",
path: `/tickets/${ticketId}/messages`,
...opts,
});
},
},
};
2 changes: 1 addition & 1 deletion components/gorgias_oauth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/gorgias_oauth",
"version": "0.5.0",
"version": "0.5.1",
"description": "Pipedream Gorgias OAuth Components",
"main": "gorgias_oauth.app.mjs",
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
key: "gorgias_oauth-ticket-created",
name: "New Ticket",
description: "Emit new event when a ticket is created. [See the documentation](https://developers.gorgias.com/reference/the-event-object)",
version: "0.1.6",
version: "0.1.7",
type: "source",
props: {
...base.props,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
key: "gorgias_oauth-ticket-message-created",
name: "New Ticket Message",
description: "Emit new event when a ticket message is created. [See the documentation](https://developers.gorgias.com/reference/the-event-object)",
version: "0.1.6",
version: "0.1.7",
type: "source",
props: {
...base.props,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
key: "gorgias_oauth-ticket-updated",
name: "New Updated Ticket",
description: "Emit new event when a ticket is updated. [See the documentation](https://developers.gorgias.com/reference/the-event-object)",
version: "0.1.6",
version: "0.1.7",
type: "source",
props: {
...base.props,
Expand Down
3 changes: 1 addition & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading