diff --git a/components/frontapp/actions/add-comment/add-comment.mjs b/components/frontapp/actions/add-comment/add-comment.mjs index 399742563e934..72e214fe8840f 100644 --- a/components/frontapp/actions/add-comment/add-comment.mjs +++ b/components/frontapp/actions/add-comment/add-comment.mjs @@ -5,7 +5,7 @@ export default { key: "frontapp-add-comment", name: "Add Comment", description: "Add a comment to a conversation. [See the documentation](https://dev.frontapp.com/reference/add-comment)", - version: "0.0.1", + version: "0.0.2", type: "action", props: { frontApp, diff --git a/components/frontapp/actions/archive-conversation/archive-conversation.mjs b/components/frontapp/actions/archive-conversation/archive-conversation.mjs index ea17d398d66b3..e5d3f85ac5c61 100644 --- a/components/frontapp/actions/archive-conversation/archive-conversation.mjs +++ b/components/frontapp/actions/archive-conversation/archive-conversation.mjs @@ -4,7 +4,7 @@ export default { key: "frontapp-archive-conversation", name: "Archive Conversation", description: "Archives a conversation. [See the documentation](https://dev.frontapp.com/reference/patch_conversations-conversation-id)", - version: "0.0.1", + version: "0.0.2", type: "action", props: { frontApp, diff --git a/components/frontapp/actions/assign-conversation/assign-conversation.mjs b/components/frontapp/actions/assign-conversation/assign-conversation.mjs index 2332fa1c45639..e2229f8c4d79f 100644 --- a/components/frontapp/actions/assign-conversation/assign-conversation.mjs +++ b/components/frontapp/actions/assign-conversation/assign-conversation.mjs @@ -4,7 +4,7 @@ export default { key: "frontapp-assign-conversation", name: "Assign Conversation", description: "Assign or unassign a conversation. [See the documentation](https://dev.frontapp.com/reference/update-conversation-assignee)", - version: "0.0.1", + version: "0.0.2", type: "action", props: { frontApp, diff --git a/components/frontapp/actions/create-draft-reply/create-draft-reply.mjs b/components/frontapp/actions/create-draft-reply/create-draft-reply.mjs index 56fa9c241505a..5a1da95bcb01e 100644 --- a/components/frontapp/actions/create-draft-reply/create-draft-reply.mjs +++ b/components/frontapp/actions/create-draft-reply/create-draft-reply.mjs @@ -5,7 +5,7 @@ export default { key: "frontapp-create-draft-reply", name: "Create Draft Reply", description: "Create a new draft as a reply to the last message in the conversation. [See the documentation](https://dev.frontapp.com/reference/create-draft-reply)", - version: "0.0.1", + version: "0.0.2", type: "action", props: { frontApp, diff --git a/components/frontapp/actions/create-draft/create-draft.mjs b/components/frontapp/actions/create-draft/create-draft.mjs index c324eac39cd55..38b22e07992eb 100644 --- a/components/frontapp/actions/create-draft/create-draft.mjs +++ b/components/frontapp/actions/create-draft/create-draft.mjs @@ -5,7 +5,7 @@ export default { key: "frontapp-create-draft", name: "Create Draft", description: "Create a draft message which is the first message of a new conversation. [See the documentation](https://dev.frontapp.com/reference/create-draft)", - version: "0.0.1", + version: "0.0.2", type: "action", props: { frontApp, diff --git a/components/frontapp/actions/create-inbox/create-inbox.mjs b/components/frontapp/actions/create-inbox/create-inbox.mjs new file mode 100644 index 0000000000000..356f99096c389 --- /dev/null +++ b/components/frontapp/actions/create-inbox/create-inbox.mjs @@ -0,0 +1,47 @@ +import frontApp from "../../frontapp.app.mjs"; + +export default { + key: "frontapp-create-inbox", + name: "Create Inbox", + description: "Create an inbox in the default team (workspace). [See the documentation](https://dev.frontapp.com/reference/create-inbox).", + version: "0.0.1", + type: "action", + props: { + frontApp, + name: { + type: "string", + label: "Name", + description: "The name of the inbox", + }, + teammateIds: { + propDefinition: [ + frontApp, + "teammateId", + ], + type: "string[]", + label: "Teammate IDs", + description: "One or more IDs of teammates that should have access to the inbox", + optional: true, + }, + }, + async run({ $ }) { + const { + frontApp, + name, + teammateIds, + } = this; + + const data = { + name, + teammate_ids: teammateIds, + }; + + const response = await frontApp.createInbox({ + data, + $, + }); + + $.export("$summary", `Successfully created inbox "${name}"`); + return response; + }, +}; diff --git a/components/frontapp/actions/create-message-template/create-message-template.mjs b/components/frontapp/actions/create-message-template/create-message-template.mjs new file mode 100644 index 0000000000000..d22e078e3b164 --- /dev/null +++ b/components/frontapp/actions/create-message-template/create-message-template.mjs @@ -0,0 +1,125 @@ +import FormData from "form-data"; +import { getFileStreamAndMetadata } from "@pipedream/platform"; +import frontApp from "../../frontapp.app.mjs"; + +export default { + key: "frontapp-create-message-template", + name: "Create Message Template", + description: "Create a new message template. [See the documentation](https://dev.frontapp.com/reference/create-message-template).", + version: "0.0.1", + type: "action", + props: { + frontApp, + name: { + type: "string", + label: "Name", + description: "Name of the message template", + }, + subject: { + type: "string", + label: "Subject", + description: "Subject of the message template", + optional: true, + }, + body: { + type: "string", + label: "Body", + description: "Body of the message template. You can supply HTML with inline CSS to structure and style your template", + }, + folderId: { + propDefinition: [ + frontApp, + "folderId", + ], + description: "ID of the message template folder to place this message template in", + }, + inboxIds: { + type: "string[]", + label: "Inbox IDs", + description: "The specific inboxes this template is available in. If not specified, it will be available in all inboxes", + propDefinition: [ + frontApp, + "inboxId", + ], + optional: true, + }, + attachments: { + propDefinition: [ + frontApp, + "attachments", + ], + }, + syncDir: { + type: "dir", + accessMode: "read", + sync: true, + optional: true, + }, + }, + async run({ $ }) { + const { + frontApp, + name, + subject, + body, + folderId, + inboxIds, + attachments, + } = this; + + let data, headers = {}; + + // Handle attachments if provided + if (attachments?.length > 0) { + const formData = new FormData(); + + formData.append("name", name); + formData.append("body", body); + if (subject !== undefined) { + formData.append("subject", subject); + } + if (folderId !== undefined) { + formData.append("folder_id", folderId); + } + if (typeof inboxIds === "string") { + formData.append("inbox_ids", inboxIds); + } else if (Array.isArray(inboxIds)) { + for (const inboxId of inboxIds) { + formData.append("inbox_ids", inboxId); + } + } + + for (const attachment of attachments) { + const { + stream, metadata, + } = await getFileStreamAndMetadata(attachment); + formData.append("attachments", stream, { + contentType: metadata.contentType, + knownLength: metadata.size, + filename: metadata.name, + }); + } + + data = formData; + headers = formData.getHeaders(); + } else { + // Simple JSON request without attachments + data = { + name, + subject, + body, + folder_id: folderId, + inbox_ids: inboxIds, + }; + } + + const response = await frontApp.createMessageTemplate({ + data, + headers, + $, + }); + + $.export("$summary", `Successfully created message template "${name}"`); + return response; + }, +}; diff --git a/components/frontapp/actions/delete-message-template/delete-message-template.mjs b/components/frontapp/actions/delete-message-template/delete-message-template.mjs new file mode 100644 index 0000000000000..2c0b20477e032 --- /dev/null +++ b/components/frontapp/actions/delete-message-template/delete-message-template.mjs @@ -0,0 +1,33 @@ +import frontApp from "../../frontapp.app.mjs"; + +export default { + key: "frontapp-delete-message-template", + name: "Delete Message Template", + description: "Delete a message template. [See the documentation](https://dev.frontapp.com/reference/delete-message-template).", + version: "0.0.1", + type: "action", + props: { + frontApp, + messageTemplateId: { + propDefinition: [ + frontApp, + "messageTemplateId", + ], + description: "ID of the message template to delete", + }, + }, + async run({ $ }) { + const { + frontApp, + messageTemplateId, + } = this; + + const response = await frontApp.deleteMessageTemplate({ + messageTemplateId, + $, + }); + + $.export("$summary", `Successfully deleted message template ${messageTemplateId}`); + return response; + }, +}; diff --git a/components/frontapp/actions/get-comment/get-comment.mjs b/components/frontapp/actions/get-comment/get-comment.mjs index c51214587acdf..6d0f12a67c0a0 100644 --- a/components/frontapp/actions/get-comment/get-comment.mjs +++ b/components/frontapp/actions/get-comment/get-comment.mjs @@ -4,7 +4,7 @@ export default { key: "frontapp-get-comment", name: "Get Comment", description: "Retrieve a comment from a conversation. [See the documentation](https://dev.frontapp.com/reference/get-comment)", - version: "0.0.1", + version: "0.0.2", type: "action", props: { frontApp, diff --git a/components/frontapp/actions/get-teammate/get-teammate.mjs b/components/frontapp/actions/get-teammate/get-teammate.mjs index c0cac11fc155c..89c0f41598908 100644 --- a/components/frontapp/actions/get-teammate/get-teammate.mjs +++ b/components/frontapp/actions/get-teammate/get-teammate.mjs @@ -4,7 +4,7 @@ export default { key: "frontapp-get-teammate", name: "Get Teammate", description: "Retrieve a teammate by ID. [See the documentation](https://dev.frontapp.com/reference/get-teammate)", - version: "0.0.1", + version: "0.0.2", type: "action", props: { frontApp, diff --git a/components/frontapp/actions/import-message/import-message.mjs b/components/frontapp/actions/import-message/import-message.mjs index 7d21b63cac714..042ff683a122c 100644 --- a/components/frontapp/actions/import-message/import-message.mjs +++ b/components/frontapp/actions/import-message/import-message.mjs @@ -4,8 +4,8 @@ import frontApp from "../../frontapp.app.mjs"; export default { key: "frontapp-import-message", name: "Import Message", - description: "Appends a new message into an inbox. [See the docs here](https://dev.frontapp.com/reference/import-inbox-message).", - version: "0.1.7", + description: "Appends a new message into an inbox. [See the documentation](https://dev.frontapp.com/reference/import-inbox-message).", + version: "0.1.8", type: "action", props: { frontApp, diff --git a/components/frontapp/actions/list-comment-mentions/list-comment-mentions.mjs b/components/frontapp/actions/list-comment-mentions/list-comment-mentions.mjs index f371f9009d5c4..da31a3f5e230b 100644 --- a/components/frontapp/actions/list-comment-mentions/list-comment-mentions.mjs +++ b/components/frontapp/actions/list-comment-mentions/list-comment-mentions.mjs @@ -4,7 +4,7 @@ export default { key: "frontapp-list-comment-mentions", name: "List Comment Mentions", description: "List the teammates mentioned in a comment. [See the documentation](https://dev.frontapp.com/reference/list-comment-mentions)", - version: "0.0.1", + version: "0.0.2", type: "action", props: { frontApp, diff --git a/components/frontapp/actions/list-comments/list-comments.mjs b/components/frontapp/actions/list-comments/list-comments.mjs index 72331db31cea7..c659f7816b392 100644 --- a/components/frontapp/actions/list-comments/list-comments.mjs +++ b/components/frontapp/actions/list-comments/list-comments.mjs @@ -4,7 +4,7 @@ export default { key: "frontapp-list-comments", name: "List Conversation Comments", description: "List the comments in a conversation. [See the documentation](https://dev.frontapp.com/reference/list-conversation-comments)", - version: "0.0.1", + version: "0.0.2", type: "action", props: { frontApp, diff --git a/components/frontapp/actions/list-conversations/list-conversations.mjs b/components/frontapp/actions/list-conversations/list-conversations.mjs index ee19fe0e67ad9..b458621046c19 100644 --- a/components/frontapp/actions/list-conversations/list-conversations.mjs +++ b/components/frontapp/actions/list-conversations/list-conversations.mjs @@ -4,7 +4,7 @@ export default { key: "frontapp-list-conversations", name: "List Conversations", description: "List conversations in the company. [See the documentation](https://dev.frontapp.com/reference/list-conversations)", - version: "0.0.1", + version: "0.0.2", type: "action", props: { frontApp, diff --git a/components/frontapp/actions/list-message-templates/list-message-templates.mjs b/components/frontapp/actions/list-message-templates/list-message-templates.mjs new file mode 100644 index 0000000000000..719779b414f74 --- /dev/null +++ b/components/frontapp/actions/list-message-templates/list-message-templates.mjs @@ -0,0 +1,70 @@ +import frontApp from "../../frontapp.app.mjs"; + +export default { + key: "frontapp-list-message-templates", + name: "List Message Templates", + description: "List the message templates. [See the documentation](https://dev.frontapp.com/reference/list-message-templates).", + version: "0.0.1", + type: "action", + props: { + frontApp, + sortBy: { + type: "string", + label: "Sort By Field", + description: "Field used to sort the message templates", + options: [ + { + label: "Created At", + value: "created_at", + }, + { + label: "Updated At", + value: "updated_at", + }, + ], + optional: true, + }, + sortOrder: { + type: "string", + label: "Sort Order", + description: "Order by which results should be sorted", + options: [ + { + label: "Ascending", + value: "asc", + }, + { + label: "Descending", + value: "desc", + }, + ], + optional: true, + }, + maxResults: { + propDefinition: [ + frontApp, + "maxResults", + ], + }, + }, + async run({ $ }) { + const items = this.frontApp.paginate({ + fn: this.frontApp.listMessageTemplates, + params: { + sort_by: this.sortBy, + sort_order: this.sortOrder, + }, + maxResults: this.maxResults, + $, + }); + + const results = []; + for await (const item of items) { + results.push(item); + } + $.export("$summary", `Successfully retrieved ${results?.length} message template${results?.length === 1 + ? "" + : "s"}`); + return results; + }, +}; diff --git a/components/frontapp/actions/list-teammates/list-teammates.mjs b/components/frontapp/actions/list-teammates/list-teammates.mjs index 5c1076b955cda..b8867a1aa5c0e 100644 --- a/components/frontapp/actions/list-teammates/list-teammates.mjs +++ b/components/frontapp/actions/list-teammates/list-teammates.mjs @@ -4,7 +4,7 @@ export default { key: "frontapp-list-teammates", name: "List Teammate", description: "List teammates in the company. [See the documentation](https://dev.frontapp.com/reference/list-teammates)", - version: "0.0.1", + version: "0.0.2", type: "action", props: { frontApp, diff --git a/components/frontapp/actions/receive-custom-messages/receive-custom-messages.mjs b/components/frontapp/actions/receive-custom-messages/receive-custom-messages.mjs index 294c0d1df55d6..bf25964f07d41 100644 --- a/components/frontapp/actions/receive-custom-messages/receive-custom-messages.mjs +++ b/components/frontapp/actions/receive-custom-messages/receive-custom-messages.mjs @@ -4,8 +4,8 @@ import frontApp from "../../frontapp.app.mjs"; export default { key: "frontapp-receive-custom-messages", name: "Receive Custom Messages", - description: "Receive a custom message in Front. [See the docs here](https://dev.frontapp.com/reference/post_channels-channel-id-incoming-messages).", - version: "0.0.4", + description: "Receive a custom message in Front. [See the documentation](https://dev.frontapp.com/reference/post_channels-channel-id-incoming-messages).", + version: "0.0.5", type: "action", props: { frontApp, diff --git a/components/frontapp/actions/reply-to-conversation/reply-to-conversation.mjs b/components/frontapp/actions/reply-to-conversation/reply-to-conversation.mjs index 4f227cc4cc884..2f74ec08aea07 100644 --- a/components/frontapp/actions/reply-to-conversation/reply-to-conversation.mjs +++ b/components/frontapp/actions/reply-to-conversation/reply-to-conversation.mjs @@ -4,8 +4,8 @@ import frontApp from "../../frontapp.app.mjs"; export default { key: "frontapp-reply-to-conversation", name: "Reply To Conversation", - description: "Reply to a conversation by sending a message and appending it to the conversation. [See the docs here](https://dev.frontapp.com/reference/post_conversations-conversation-id-messages).", - version: "0.0.3", + description: "Reply to a conversation by sending a message and appending it to the conversation. [See the documentation](https://dev.frontapp.com/reference/post_conversations-conversation-id-messages).", + version: "0.0.4", type: "action", props: { frontApp, diff --git a/components/frontapp/actions/send-new-message/send-new-message.mjs b/components/frontapp/actions/send-new-message/send-new-message.mjs index 748f86e65af4e..3cd9234f34c60 100644 --- a/components/frontapp/actions/send-new-message/send-new-message.mjs +++ b/components/frontapp/actions/send-new-message/send-new-message.mjs @@ -4,8 +4,8 @@ import frontApp from "../../frontapp.app.mjs"; export default { key: "frontapp-send-new-message", name: "Send New Message", - description: "Sends a new message from a channel. It will create a new conversation. [See the docs here](https://dev.frontapp.com/reference/post_channels-channel-id-messages).", - version: "0.2.6", + description: "Sends a new message from a channel. It will create a new conversation. [See the documentation](https://dev.frontapp.com/reference/post_channels-channel-id-messages).", + version: "0.2.7", type: "action", props: { frontApp, diff --git a/components/frontapp/actions/tag-conversation/tag-conversation.mjs b/components/frontapp/actions/tag-conversation/tag-conversation.mjs index cda17006754ff..8ef633625ddff 100644 --- a/components/frontapp/actions/tag-conversation/tag-conversation.mjs +++ b/components/frontapp/actions/tag-conversation/tag-conversation.mjs @@ -4,7 +4,7 @@ export default { key: "frontapp-tag-conversation", name: "Tag Conversation", description: "Add tags to a conversation. [See the documentation](https://dev.frontapp.com/reference/patch_conversations-conversation-id)", - version: "0.0.1", + version: "0.0.2", type: "action", props: { frontApp, diff --git a/components/frontapp/actions/update-conversation/update-conversation.mjs b/components/frontapp/actions/update-conversation/update-conversation.mjs index 4d69740438a6a..99206fca0bbf9 100644 --- a/components/frontapp/actions/update-conversation/update-conversation.mjs +++ b/components/frontapp/actions/update-conversation/update-conversation.mjs @@ -4,8 +4,8 @@ import frontApp from "../../frontapp.app.mjs"; export default { key: "frontapp-update-conversation", name: "Update Conversation", - description: "Updates a conversation. [See the docs here](https://dev.frontapp.com/reference/patch_conversations-conversation-id).", - version: "0.1.6", + description: "Updates a conversation. [See the documentation](https://dev.frontapp.com/reference/patch_conversations-conversation-id).", + version: "0.1.7", type: "action", props: { frontApp, diff --git a/components/frontapp/actions/update-teammate/update-teammate.mjs b/components/frontapp/actions/update-teammate/update-teammate.mjs new file mode 100644 index 0000000000000..c2c7ea33bf167 --- /dev/null +++ b/components/frontapp/actions/update-teammate/update-teammate.mjs @@ -0,0 +1,77 @@ +import frontApp from "../../frontapp.app.mjs"; + +export default { + key: "frontapp-update-teammate", + name: "Update Teammate", + description: "Update a teammate. [See the documentation](https://dev.frontapp.com/reference/update-teammate).", + version: "0.0.1", + type: "action", + props: { + frontApp, + teammateId: { + propDefinition: [ + frontApp, + "teammateId", + ], + description: "ID of the teammate to update", + }, + username: { + type: "string", + label: "Username", + description: "New username. It must be unique and can only contains lowercase letters, numbers and underscores", + optional: true, + }, + firstName: { + type: "string", + label: "First Name", + description: "New first name", + optional: true, + }, + lastName: { + type: "string", + label: "Last Name", + description: "New last name", + optional: true, + }, + isAvailable: { + type: "boolean", + label: "Is Available", + description: "New availability status", + optional: true, + }, + customFields: { + type: "object", + label: "Custom Fields", + description: "Custom fields for this teammate. If included, all current custom fields will be replaced with the object supplied here", + optional: true, + }, + }, + async run({ $ }) { + const { + frontApp, + teammateId, + username, + firstName, + lastName, + isAvailable, + customFields, + } = this; + + const data = { + username, + first_name: firstName, + last_name: lastName, + is_available: isAvailable, + custom_fields: customFields, + }; + + const response = await frontApp.updateTeammate({ + teammateId, + data, + $, + }); + + $.export("$summary", `Successfully updated teammate ${teammateId}`); + return response; + }, +}; diff --git a/components/frontapp/common/utils.mjs b/components/frontapp/common/utils.mjs index aac27a8eca825..6245a23112828 100644 --- a/components/frontapp/common/utils.mjs +++ b/components/frontapp/common/utils.mjs @@ -89,7 +89,7 @@ function buildFormData(formData, data, parentKey) { buildFormData(formData, data[key], parentKey && `${parentKey}[${key}]` || key); }); - } else if (data && parentKey.includes("attachment")) { + } else if (data && parentKey?.includes("attachment")) { formData.append(parentKey, createReadStream(data)); } else if (data) { diff --git a/components/frontapp/frontapp.app.mjs b/components/frontapp/frontapp.app.mjs index 8d3f031c4db91..82b79386b7df1 100644 --- a/components/frontapp/frontapp.app.mjs +++ b/components/frontapp/frontapp.app.mjs @@ -273,13 +273,48 @@ export default { default: 100, optional: true, }, + messageTemplateId: { + type: "string", + label: "Message Template ID", + description: "The message template ID", + async options({ prevContext }) { + return this.paginateOptions({ + prevContext, + listResourcesFn: this.listMessageTemplates, + mapper: ({ + id, name, + }) => ({ + label: name, + value: id, + }), + }); + }, + }, + folderId: { + type: "string", + label: "Folder ID", + description: "ID of the message template folder", + async options({ prevContext }) { + return this.paginateOptions({ + prevContext, + listResourcesFn: this.listMessageTemplateFolders, + mapper: ({ + id, name, + }) => ({ + label: name, + value: id, + }), + }); + }, + optional: true, + }, }, methods: { getUrl(path, url) { return url || `${constants.BASE_URL}${path}`; }, hasMultipartHeader(headers) { - return headers && headers["Content-Type"].includes("multipart/form-data"); + return headers?.["Content-Type"]?.includes("multipart/form-data"); }, getHeaders(headers) { return { @@ -293,7 +328,10 @@ export default { headers, path, url, data: originalData, ...args } = {}) { const hasMultipartHeader = this.hasMultipartHeader(headers); - const data = hasMultipartHeader && utils.getFormData(originalData) || originalData; + const isFormData = originalData instanceof FormData; + const data = (!isFormData && hasMultipartHeader) + ? utils.getFormData(originalData) + : originalData; const currentHeaders = this.getHeaders(headers); const builtHeaders = hasMultipartHeader ? { @@ -510,6 +548,50 @@ export default { ...args, }); }, + async listMessageTemplates(args = {}) { + return this.makeRequest({ + path: "/message_templates", + ...args, + }); + }, + async listMessageTemplateFolders(args = {}) { + return this.makeRequest({ + path: "/message_template_folders", + ...args, + }); + }, + async updateTeammate({ + teammateId, ...args + } = {}) { + return this.makeRequest({ + method: "patch", + path: `/teammates/${teammateId}`, + ...args, + }); + }, + async createInbox(args = {}) { + return this.makeRequest({ + method: "post", + path: "/inboxes", + ...args, + }); + }, + async createMessageTemplate(args = {}) { + return this.makeRequest({ + method: "post", + path: "/message_templates", + ...args, + }); + }, + async deleteMessageTemplate({ + messageTemplateId, ...args + } = {}) { + return this.makeRequest({ + method: "delete", + path: `/message_templates/${messageTemplateId}`, + ...args, + }); + }, async paginateOptions({ prevContext, listResourcesFn, diff --git a/components/frontapp/package.json b/components/frontapp/package.json index f46650a4cda8d..d5e3ca9658284 100644 --- a/components/frontapp/package.json +++ b/components/frontapp/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/frontapp", - "version": "0.6.0", + "version": "0.7.0", "description": "Pipedream Frontapp Components", "main": "frontapp.app.mjs", "keywords": [ @@ -10,7 +10,7 @@ "homepage": "https://pipedream.com/apps/frontapp", "author": "Pipedream (https://pipedream.com/)", "dependencies": { - "@pipedream/platform": "^3.0.3", + "@pipedream/platform": "^3.1.0", "form-data": "^4.0.0" }, "gitHead": "e12480b94cc03bed4808ebc6b13e7fdb3a1ba535", diff --git a/components/frontapp/sources/common/base.mjs b/components/frontapp/sources/common/base.mjs index be15ec62602a5..69c839c4704d2 100644 --- a/components/frontapp/sources/common/base.mjs +++ b/components/frontapp/sources/common/base.mjs @@ -19,7 +19,10 @@ export default { _setLastTs(lastTs) { this.db.set("lastTs", lastTs); }, - async startEvent(maxResults = 0) { + _getItemTs(item) { + return item.created_at * 1000; + }, + async startEvent(maxResults = 0, filterFn = null) { const lastTs = this._getLastTs(); const items = this.frontapp.paginate({ fn: this._getFunction(), @@ -30,10 +33,18 @@ export default { let responseArray = []; for await (const item of items) { - responseArray.push(item); + // If filterFn is provided, use it to filter items, otherwise add all items + if (!filterFn || filterFn(item, lastTs)) { + responseArray.push(item); + } } - if (responseArray.length) this._setLastTs(responseArray[0].emitted_at); + if (responseArray.length) { + if (filterFn) { + responseArray.sort((a, b) => b.created_at - a.created_at); + } + this._setLastTs(this._getEmit(responseArray[0]).ts); + } for (const item of responseArray.reverse()) { this.$emit( diff --git a/components/frontapp/sources/new-conversation-created/new-conversation-created.mjs b/components/frontapp/sources/new-conversation-created/new-conversation-created.mjs new file mode 100644 index 0000000000000..32c8973f538fa --- /dev/null +++ b/components/frontapp/sources/new-conversation-created/new-conversation-created.mjs @@ -0,0 +1,40 @@ +import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "frontapp-new-conversation-created", + name: "New Conversation Created", + description: "Emit new event when a conversation is created. [See the documentation](https://dev.frontapp.com/reference/list-conversations)", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + _getFunction() { + return this.frontapp.listConversations; + }, + _getParams() { + return { + sort_by: "date", + sort_order: "desc", + }; + }, + _getEmit(conversation) { + return { + id: conversation.id, + summary: `New conversation: ${conversation.subject}`, + ts: conversation.created_at * 1000, + }; + }, + }, + hooks: { + async deploy() { + await this.startEvent(25, (item, lastTs) => this._getItemTs(item) > lastTs); + }, + }, + async run() { + await this.startEvent(0, (item, lastTs) => this._getItemTs(item) > lastTs); + }, + sampleEmit, +}; diff --git a/components/frontapp/sources/new-conversation-created/test-event.mjs b/components/frontapp/sources/new-conversation-created/test-event.mjs new file mode 100644 index 0000000000000..0da0e3a74c5db --- /dev/null +++ b/components/frontapp/sources/new-conversation-created/test-event.mjs @@ -0,0 +1,96 @@ +export default { + "_links": { + "self": "string", + "related": { + "events": "string", + "followers": "string", + "messages": "string", + "comments": "string", + "inboxes": "string", + "last_message": "string" + } + }, + "id": "cnv_123abc", + "subject": "New conversation subject", + "status": "open", + "assignee": { + "_links": { + "self": "string", + "related": { + "inboxes": "string", + "conversations": "string" + } + }, + "id": "tea_123abc", + "email": "teammate@example.com", + "username": "teammate", + "first_name": "John", + "last_name": "Doe", + "is_admin": false, + "is_available": true, + "is_blocked": false, + "custom_fields": {} + }, + "recipient": { + "_links": { + "related": { + "contact": "string" + } + }, + "name": "Customer Name", + "handle": "customer@example.com", + "role": "from" + }, + "tags": [ + { + "_links": { + "self": "string", + "related": { + "conversations": "string", + "owner": "string", + "children": "string" + } + }, + "id": "tag_123abc", + "name": "urgent", + "description": "Urgent conversations", + "highlight": "red", + "is_private": false, + "is_visible_in_conversation_lists": true, + "created_at": 1640995200, + "updated_at": 1640995200 + } + ], + "links": [ + { + "_links": { + "self": "string" + }, + "id": "link_123abc", + "name": "Related Ticket", + "type": "string", + "external_url": "https://example.com/ticket/123", + "custom_fields": {} + } + ], + "custom_fields": {}, + "created_at": 1640995200, + "is_private": false, + "scheduled_reminders": [ + { + "_links": { + "related": { + "owner": "string" + } + }, + "created_at": 1640995200, + "scheduled_at": 1641081600, + "updated_at": 1640995200 + } + ], + "metadata": { + "external_conversation_ids": [ + "external_123" + ] + } +}; \ No newline at end of file diff --git a/components/frontapp/sources/new-conversation-state-change/new-conversation-state-change.mjs b/components/frontapp/sources/new-conversation-state-change/new-conversation-state-change.mjs index edc90a1610223..549e0814361e2 100644 --- a/components/frontapp/sources/new-conversation-state-change/new-conversation-state-change.mjs +++ b/components/frontapp/sources/new-conversation-state-change/new-conversation-state-change.mjs @@ -6,8 +6,8 @@ export default { ...common, key: "frontapp-new-conversation-state-change", name: "New Conversation State Change", - description: "Emit new event when a conversation reaches a specific state. [See the docs](https://dev.frontapp.com/reference/list-conversations)", - version: "0.0.2", + description: "Emit new event when a conversation reaches a specific state. [See the documentation](https://dev.frontapp.com/reference/list-conversations)", + version: "0.0.3", type: "source", dedupe: "unique", props: { @@ -15,7 +15,7 @@ export default { types: { type: "string[]", label: "States to Listen For", - description: "Trigger a workflow when a conversation reaches any of these states. [See the docs](https://dev.frontapp.com/reference/list-conversations) for more detail.", + description: "Trigger a workflow when a conversation reaches any of these states. [See the documentation](https://dev.frontapp.com/reference/list-conversations) for more detail.", options: utils.TYPES_OPTIONS, }, }, diff --git a/components/frontapp/sources/new-conversation-tag/new-conversation-tag.mjs b/components/frontapp/sources/new-conversation-tag/new-conversation-tag.mjs index f3a71bffa3ee9..6b25ebb92789f 100644 --- a/components/frontapp/sources/new-conversation-tag/new-conversation-tag.mjs +++ b/components/frontapp/sources/new-conversation-tag/new-conversation-tag.mjs @@ -6,7 +6,7 @@ export default { key: "frontapp-new-conversation-tag", name: "New Conversation Tag", description: "Emit new event when a conversation is tagged with a specific tag or any tag. [See the documentation](https://dev.frontapp.com/reference/events)", - version: "0.0.2", + version: "0.0.3", type: "source", dedupe: "unique", props: { diff --git a/components/frontapp/sources/new-message-template-created/new-message-template-created.mjs b/components/frontapp/sources/new-message-template-created/new-message-template-created.mjs new file mode 100644 index 0000000000000..c28549fc98ea9 --- /dev/null +++ b/components/frontapp/sources/new-message-template-created/new-message-template-created.mjs @@ -0,0 +1,40 @@ +import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "frontapp-new-message-template-created", + name: "New Message Template Created", + description: "Emit new event when a message template is created. [See the documentation](https://dev.frontapp.com/reference/list-message-templates)", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + _getFunction() { + return this.frontapp.listMessageTemplates; + }, + _getParams() { + return { + sort_by: "created_at", + sort_order: "desc", + }; + }, + _getEmit(template) { + return { + id: template.id, + summary: `New template: ${template.name}`, + ts: template.created_at * 1000, + }; + }, + }, + hooks: { + async deploy() { + await this.startEvent(25, (item, lastTs) => this._getItemTs(item) > lastTs); + }, + }, + async run() { + await this.startEvent(0, (item, lastTs) => this._getItemTs(item) > lastTs); + }, + sampleEmit, +}; diff --git a/components/frontapp/sources/new-message-template-created/test-event.mjs b/components/frontapp/sources/new-message-template-created/test-event.mjs new file mode 100644 index 0000000000000..8ee6c9cac0632 --- /dev/null +++ b/components/frontapp/sources/new-message-template-created/test-event.mjs @@ -0,0 +1,56 @@ +export default { + "_links": { + "self": "string", + "related": { + "folder": "string", + "inboxes": "string" + } + }, + "id": "tpl_123abc", + "name": "Welcome Email Template", + "subject": "Welcome to our service!", + "body": "

Welcome to our service! We're excited to have you on board.

Best regards,
The Team

", + "folder_id": "fol_123abc", + "inbox_ids": [ + "inb_123abc", + "inb_456def" + ], + "attachments": [ + { + "filename": "welcome-guide.pdf", + "url": "string", + "content_type": "application/pdf", + "size": 1024000 + } + ], + "created_at": 1640995200, + "updated_at": 1640995200, + "is_available_for_all_inboxes": false, + "folder": { + "_links": { + "self": "string", + "related": { + "owner": "string" + } + }, + "id": "fol_123abc", + "name": "Customer Onboarding", + "description": "Templates for customer onboarding process" + }, + "inboxes": [ + { + "_links": { + "self": "string", + "related": { + "conversations": "string", + "teammates": "string", + "channels": "string", + "owner": "string" + } + }, + "id": "inb_123abc", + "name": "Support Inbox", + "is_private": false + } + ] +}; \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b19dba778b794..b1d3ee77b6eb0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5078,8 +5078,8 @@ importers: components/frontapp: dependencies: '@pipedream/platform': - specifier: ^3.0.3 - version: 3.0.3 + specifier: ^3.1.0 + version: 3.1.0 form-data: specifier: ^4.0.0 version: 4.0.1 @@ -11493,8 +11493,7 @@ importers: components/rewardful: {} - components/rewiser: - specifiers: {} + components/rewiser: {} components/rex: dependencies: @@ -37258,6 +37257,8 @@ snapshots: '@putout/operator-filesystem': 5.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3)) '@putout/operator-json': 2.2.0 putout: 36.13.1(eslint@8.57.1)(typescript@5.6.3) + transitivePeerDependencies: + - supports-color '@putout/operator-regexp@1.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3))': dependencies: