diff --git a/components/unthread/actions/create-conversation/create-conversation.mjs b/components/unthread/actions/create-conversation/create-conversation.mjs new file mode 100644 index 0000000000000..e9a83d0575116 --- /dev/null +++ b/components/unthread/actions/create-conversation/create-conversation.mjs @@ -0,0 +1,145 @@ +import { ConfigurationError } from "@pipedream/platform"; +import { + PRIORITY_OPTIONS, + STATUS_OPTIONS, +} from "../../common/constants.mjs"; +import app from "../../unthread.app.mjs"; + +export default { + key: "unthread-create-conversation", + name: "Create Conversation", + description: "Create a new Conversation. [See the documentation](https://docs.unthread.io/api-introduction/using-api#create-conversation)", + version: "0.0.1", + type: "action", + props: { + app, + type: { + type: "string", + label: "Type", + description: "Type of the conversation", + options: [ + "triage", + "email", + ], + reloadProps: true, + }, + markdown: { + type: "string", + label: "Markdown", + description: "Markdown of the conversation", + }, + status: { + type: "string", + label: "Status", + description: "Status of the conversation", + options: STATUS_OPTIONS, + }, + assignedToUserId: { + propDefinition: [ + app, + "userId", + ], + optional: true, + }, + customerId: { + propDefinition: [ + app, + "customerId", + ], + optional: true, + }, + priority: { + type: "integer", + label: "Priority", + description: "Priority of the conversation", + options: PRIORITY_OPTIONS, + optional: true, + }, + triageChannelId: { + propDefinition: [ + app, + "triageChannelId", + ], + hidden: true, + }, + notes: { + type: "string", + label: "Notes", + description: "Notes of the conversation", + optional: true, + }, + title: { + type: "string", + label: "Title", + description: "Title of the conversation", + optional: true, + }, + excludeAnalytics: { + type: "boolean", + label: "Exclude Analytics", + description: "Exclude Analytics for this conversation", + optional: true, + }, + emailInboxId: { + type: "string", + label: "Email Inbox Id", + description: "ID of the Email Inbox", + hidden: true, + }, + onBehalfOfEmail: { + type: "string", + label: "On Behalf Of Email", + description: "Email on behalf of which the conversation is created", + optional: true, + }, + onBehalfOfName: { + type: "string", + label: "On Behalf Of Name", + description: "Name on behalf of which the conversation is created", + optional: true, + }, + onBehalfOfId: { + type: "string", + label: "On Behalf Of ID", + description: "ID on behalf of which the conversation is created", + optional: true, + }, + }, + async additionalProps(props) { + const isTriage = this.type === "triage"; + props.triageChannelId.hidden = !isTriage; + props.emailInboxId.hidden = isTriage; + + return {}; + }, + async run({ $ }) { + if (this.type === "email" && (!this.onBehalfOfEmail && !this.onBehalfOfId)) { + throw new ConfigurationError("You must provide either 'On Behalf Of Email' or 'On Behalf Of ID' when creating an email conversation"); + } + const { + app, + onBehalfOfEmail, + onBehalfOfName, + onBehalfOfId, + ...data + } = this; + + const onBehalfOf = {}; + + if (onBehalfOfEmail) onBehalfOf.email = onBehalfOfEmail; + if (onBehalfOfName) onBehalfOf.name = onBehalfOfName; + if (onBehalfOfId) onBehalfOf.id = onBehalfOfId; + + const response = await app.createConversation({ + $, + data: { + ...data, + onBehalfOf, + }, + }); + + $.export("$summary", `Successfully created Conversation with ID '${response.id}'`); + + return response; + }, +}; diff --git a/components/unthread/actions/create-customer/create-customer.mjs b/components/unthread/actions/create-customer/create-customer.mjs index cc34da006bffe..ba0f886121293 100644 --- a/components/unthread/actions/create-customer/create-customer.mjs +++ b/components/unthread/actions/create-customer/create-customer.mjs @@ -4,7 +4,7 @@ export default { key: "unthread-create-customer", name: "Create Customer", description: "Create a new Customer. [See the documentation](https://docs.unthread.io/api-introduction/using-api#create-customer)", - version: "0.0.1", + version: "0.0.2", type: "action", props: { app, diff --git a/components/unthread/actions/delete-customer/delete-customer.mjs b/components/unthread/actions/delete-customer/delete-customer.mjs index 821da0758175e..0c792e33537df 100644 --- a/components/unthread/actions/delete-customer/delete-customer.mjs +++ b/components/unthread/actions/delete-customer/delete-customer.mjs @@ -4,7 +4,7 @@ export default { key: "unthread-delete-customer", name: "Delete Customer", description: "Delete a Customer. [See the documentation](https://docs.unthread.io/api-introduction/using-api#delete-customer)", - version: "0.0.1", + version: "0.0.2", type: "action", props: { app, diff --git a/components/unthread/actions/update-customer/update-customer.mjs b/components/unthread/actions/update-customer/update-customer.mjs index 3e16c80179380..9653abe974938 100644 --- a/components/unthread/actions/update-customer/update-customer.mjs +++ b/components/unthread/actions/update-customer/update-customer.mjs @@ -4,7 +4,7 @@ export default { key: "unthread-update-customer", name: "Update Customer", description: "Update a Customer. [See the documentation](https://docs.unthread.io/api-introduction/using-api#update-customer)", - version: "0.0.1", + version: "0.0.2", type: "action", props: { app, diff --git a/components/unthread/common/constants.mjs b/components/unthread/common/constants.mjs new file mode 100644 index 0000000000000..36c458f8c4d7c --- /dev/null +++ b/components/unthread/common/constants.mjs @@ -0,0 +1,27 @@ +export const LIMIT = 100; + +export const STATUS_OPTIONS = [ + "open", + "in_progress", + "on_hold", + "closed", +]; + +export const PRIORITY_OPTIONS = [ + { + label: "3", + value: 3, + }, + { + label: "5", + value: 5, + }, + { + label: "7", + value: 7, + }, + { + label: "9", + value: 9, + }, +]; diff --git a/components/unthread/package.json b/components/unthread/package.json index 7a7fac5e0bd7e..d2f5821104c34 100644 --- a/components/unthread/package.json +++ b/components/unthread/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/unthread", - "version": "0.1.0", + "version": "0.2.0", "description": "Pipedream Unthread Components", "main": "unthread.app.mjs", "keywords": [ @@ -13,6 +13,6 @@ "access": "public" }, "dependencies": { - "@pipedream/platform": "^1.6.6" + "@pipedream/platform": "^3.0.3" } } diff --git a/components/unthread/unthread.app.mjs b/components/unthread/unthread.app.mjs index 4c20e61aab0c2..f84dfb16cf3df 100644 --- a/components/unthread/unthread.app.mjs +++ b/components/unthread/unthread.app.mjs @@ -1,44 +1,83 @@ import { axios } from "@pipedream/platform"; +import { LIMIT } from "./common/constants.mjs"; export default { type: "app", app: "unthread", propDefinitions: { + userId: { + type: "string", + label: "Assigned To User ID", + description: "ID of the User to whom the conversation is assigned", + async options({ prevContext }) { + const { + data, cursors, + } = await this.listUsers({ + data: { + limit: LIMIT, + cursor: prevContext.nextCursor, + }, + }); + + return { + options: data.map(({ + id: value, email: label, + }) => ({ + label, + value, + })), + context: { + nextCursor: cursors.next, + }, + }; + }, + }, customerId: { type: "string", label: "Customer ID", description: "ID of the Customer", - async options() { - const response = await this.listCustomers(); - const customersIds = response.data; - return customersIds.map(({ - id, name, - }) => ({ - value: id, - label: name, - })); + async options({ prevContext }) { + const { + data, cursors, + } = await this.listCustomers({ + data: { + limit: LIMIT, + cursor: prevContext.nextCursor, + }, + }); + + return { + options: data.map(({ + id: value, name: label, + }) => ({ + label, + value, + })), + context: { + nextCursor: cursors.next, + }, + }; }, }, - slackChannelId: { - type: "string", - label: "Slack Channel ID", - description: "ID the customer's Slack Channel", - }, name: { type: "string", label: "Name", description: "Name of the customer", }, + slackChannelId: { + type: "string", + label: "Slack Channel ID", + description: "ID the customer's Slack Channel", + }, emailDomains: { type: "string[]", label: "Email Domains", description: "Email Domains of the customer, i.e.: `gmail.com`", }, - defaultTriageChannelId: { + triageChannelId: { type: "string", - label: "Default Triage Channel", - description: "ID of the default triage Channel of this customer", - optional: true, + label: "Triage Channel ID", + description: "ID the customer's Triage Channel. [See the documentation](https://docs.unthread.io/account-setup/connect-channels) for further information.", }, disableAutomatedTicketing: { type: "boolean", @@ -46,6 +85,12 @@ export default { description: "Disable Automated Ticketing for this customer", optional: true, }, + defaultTriageChannelId: { + type: "string", + label: "Default Triage Channel", + description: "ID of the default triage Channel of this customer", + optional: true, + }, slackTeamId: { type: "string", label: "Slack Team ID", @@ -64,6 +109,7 @@ export default { headers, ...otherOpts } = opts; + return axios($, { ...otherOpts, url: this._baseUrl() + path, @@ -73,14 +119,21 @@ export default { }, }); }, - async createCustomer(args = {}) { + createConversation(args = {}) { + return this._makeRequest({ + method: "post", + path: "/conversations", + ...args, + }); + }, + createCustomer(args = {}) { return this._makeRequest({ method: "post", path: "/customers", ...args, }); }, - async updateCustomer({ + updateCustomer({ customerId, ...args }) { return this._makeRequest({ @@ -89,7 +142,7 @@ export default { ...args, }); }, - async deleteCustomer({ + deleteCustomer({ customerId, ...args }) { return this._makeRequest({ @@ -98,12 +151,19 @@ export default { ...args, }); }, - async listCustomers(args = {}) { + listCustomers(args = {}) { return this._makeRequest({ method: "post", path: "/customers/list", ...args, }); }, + listUsers(args = {}) { + return this._makeRequest({ + method: "post", + path: "/users/list", + ...args, + }); + }, }, }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 238fbc657204a..6e15382e68272 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1554,8 +1554,7 @@ importers: components/calllerapi: {} - components/callminer: - specifiers: {} + components/callminer: {} components/callpage: dependencies: @@ -3283,8 +3282,7 @@ importers: components/eodhd_apis: {} - components/epic_games: - specifiers: {} + components/epic_games: {} components/epsy: dependencies: @@ -6030,8 +6028,7 @@ importers: components/logistia_route_planner: {} - components/logo_dev: - specifiers: {} + components/logo_dev: {} components/logoraisr: {} @@ -11221,8 +11218,8 @@ importers: components/unthread: dependencies: '@pipedream/platform': - specifier: ^1.6.6 - version: 1.6.6 + specifier: ^3.0.3 + version: 3.0.3 components/upbooks: dependencies: