Skip to content

Add internal notes support to Gorgias OAuth integration #17605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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;
props.fromUser.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 || isInternalNote;
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,8 @@ export default {
throw new ConfigurationError("Must enter both Attachment URL and Attachment File Name");
}

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

let contentType, size;
if (this.attachmentUrl) {
({
Expand All @@ -162,55 +187,64 @@ export default {
? 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}\``);
// For internal notes, we don't need from/to validation
if (!isInternalNote) {
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: "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 && [
],
};

// Only add source, sender, 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.sender = {
id: fromId,
};
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 constants from "../../common/constants.mjs";
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,
},
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.channel === "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: []
};