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
@@ -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;
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
27 changes: 27 additions & 0 deletions components/unthread/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -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,
},
];
4 changes: 2 additions & 2 deletions components/unthread/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/unthread",
"version": "0.1.0",
"version": "0.2.0",
"description": "Pipedream Unthread Components",
"main": "unthread.app.mjs",
"keywords": [
Expand All @@ -13,6 +13,6 @@
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^1.6.6"
"@pipedream/platform": "^3.0.3"
}
}
104 changes: 82 additions & 22 deletions components/unthread/unthread.app.mjs
Original file line number Diff line number Diff line change
@@ -1,51 +1,96 @@
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",
label: "Automated Ticketing",
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",
Expand All @@ -64,6 +109,7 @@ export default {
headers,
...otherOpts
} = opts;

return axios($, {
...otherOpts,
url: this._baseUrl() + path,
Expand All @@ -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({
Expand All @@ -89,7 +142,7 @@ export default {
...args,
});
},
async deleteCustomer({
deleteCustomer({
customerId, ...args
}) {
return this._makeRequest({
Expand All @@ -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,
});
},
},
};
Loading
Loading