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 @@ -7,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.2",
version: "0.0.3",
type: "action",
props: {
gorgiasOauth,
Expand Down Expand Up @@ -67,6 +67,15 @@ export default {
label: "Message",
description: "Message of the ticket. Accepts HTML",
},
channel: {
propDefinition: [
gorgiasOauth,
"channel",
],
optional: false,
default: "email",
reloadProps: true,
},
via: {
propDefinition: [
gorgiasOauth,
Expand Down Expand Up @@ -101,13 +110,20 @@ export default {
},
},
additionalProps(props) {
props.toUser.hidden = this.fromAgent;
props.fromCustomer.hidden = this.fromAgent;
props.toCustomer.hidden = !this.fromAgent;
const isInternalNote = this.channel === "internal-note";
props.toUser.hidden = this.fromAgent || isInternalNote;
props.fromCustomer.hidden = this.fromAgent || isInternalNote;
props.toCustomer.hidden = !this.fromAgent || isInternalNote;
props.fromUser.hidden = !this.fromAgent;
return {};
},
methods: {
/**
* Get attachment information from URL
* @param {object} $ - Step object
* @param {string} url - Attachment URL
* @returns {object} Content type and size information
*/
async getAttachmentInfo($, url) {
const { headers } = await axios($, {
method: "HEAD",
Expand All @@ -119,6 +135,13 @@ export default {
size: headers["content-length"],
};
},
/**
* Get email address for user or customer
* @param {object} $ - Step object
* @param {string} id - User or customer ID
* @param {string} type - Type of email to get (from/to)
* @returns {string} Email address
*/
async getEmail($, id, type = "from") {
const {
gorgiasOauth: {
Expand Down Expand Up @@ -147,6 +170,12 @@ export default {
throw new ConfigurationError("Must enter both Attachment URL and Attachment File Name");
}

const isInternalNote = this.channel === "internal-note";

if (isInternalNote && this.fromAgent === false) {
throw new ConfigurationError("From Agent must be set to `true` when creating an internal note");
}

let contentType, size;
if (this.attachmentUrl) {
({
Expand All @@ -167,50 +196,61 @@ export default {
? "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}\``);
// For internal notes, we don't need to validation
if (!isInternalNote) {
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: "email",
source: {
from: {
address: await this.getEmail($, fromId, "from"),
},
to: [
{
address: await this.getEmail($, toId, "to"),
},
],
const messageData = {
channel: this.channel,
body_html: this.message,
via: this.via,
subject: this.subject,
from_agent: this.fromAgent,
sent_datetime: this.sentDatetime,
attachments: this.attachmentUrl && [
{
url: this.attachmentUrl,
name: this.attachmentName,
content_type: contentType,
size,
},
body_html: this.message,
via: this.via,
subject: this.subject,
from_agent: this.fromAgent,
sent_datetime: this.sentDatetime,
attachments: this.attachmentUrl && [
],
sender: {
id: fromId,
},
};

// Only add source and receiver for non-internal notes
if (!isInternalNote) {
messageData.source = {
from: {
address: await this.getEmail($, fromId, "from"),
},
to: [
{
url: this.attachmentUrl,
name: this.attachmentName,
content_type: contentType,
size,
address: await this.getEmail($, toId, "to"),
},
],
sender: {
id: fromId,
},
receiver: {
id: toId,
},
},
};
messageData.receiver = {
id: toId,
};
}

const response = await this.gorgiasOauth.createMessage({
$,
ticketId: this.ticketId,
data: messageData,
});

$.export("$summary", `Succesfully created ticket message with ID: ${response.id}`);
$.export("$summary", `Successfully created ${isInternalNote
? "internal note"
: "ticket message"} with ID: ${response.id}`);

return response;
},
Expand Down
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.1",
"version": "0.5.2",
"description": "Pipedream Gorgias OAuth Components",
"main": "gorgias_oauth.app.mjs",
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import base from "../common/base.mjs";
import eventTypes from "../common/event-types.mjs";
import sampleEmit from "./test-event.mjs";

export default {
...base,
key: "gorgias_oauth-internal-note-created",
name: "New Internal Note",
description: "Emit new event when an internal note is created on a ticket. [See the documentation](https://developers.gorgias.com/reference/the-event-object)",
version: "0.0.1",
type: "source",
props: {
...base.props,
ticketId: {
propDefinition: [
base.props.gorgias_oauth,
"ticketId",
],
optional: true,
},
sender: {
type: "string",
label: "Sender Email",
description: "Email address of the sender",
optional: true,
},
},
hooks: {
...base.hooks,
deploy() {},
},
methods: {
...base.methods,
/**
* Get the event type for internal notes
* @returns {string} The event type
*/
getEventType() {
return eventTypes.TICKET_MESSAGE_CREATED;
},
/**
* Check if a message is relevant for this source
* @param {object} message - The message object
* @returns {boolean} Whether the message is relevant
*/
isRelevant(message) {
return message.source.type === "internal-note"
&& (!this.ticketId || message.ticket_id === this.ticketId)
&& (!this.sender || message.sender?.email === this.sender);
},
/**
* Process and emit relevant events
* @param {object} event - The incoming event
*/
async processEvent(event) {
const { message } = event;
if (this.isRelevant(message)) {
this.emitEvent(message);
}
},
},
sampleEmit,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export default {
id: 123456789,
created_datetime: "2024-01-15T10:30:00Z",
updated_datetime: "2024-01-15T10:30:00Z",
ticket_id: 98765,
channel: "internal-note",
via: "internal-note",
source: {
type: "internal-note",
from: {
address: "[email protected]",
name: "Support Agent"
},
to: []
},
sender: {
id: 456,
email: "[email protected]",
name: "Support Agent"
},
receiver: null,
body_html: "<p>This is an internal note about the customer's issue.</p>",
body_text: "This is an internal note about the customer's issue.",
subject: "Internal Note",
from_agent: true,
sent_datetime: "2024-01-15T10:30:00Z",
attachments: [],
public: false,
stripped_html: "<p>This is an internal note about the customer's issue.</p>",
stripped_text: "This is an internal note about the customer's issue.",
stripped_signature: "",
message_id: "internal-note-123456789",
actions: [],
rule_id: null,
external_id: null,
tags: [],
integration_id: null,
last_sending_error: null,
opened_datetime: null,
clicked_datetime: null,
failed_datetime: null,
errors: []
};
11 changes: 1 addition & 10 deletions pnpm-lock.yaml

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

Loading