Skip to content

Commit 130c276

Browse files
Merging pull request #15345
* [ACTION] Unthread - Create conversation #15308 Actions - Create Conversation * pnpm update * Update components/unthread/actions/create-conversation/create-conversation.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 5f880bd commit 130c276

File tree

8 files changed

+261
-29
lines changed

8 files changed

+261
-29
lines changed
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import {
3+
PRIORITY_OPTIONS,
4+
STATUS_OPTIONS,
5+
} from "../../common/constants.mjs";
6+
import app from "../../unthread.app.mjs";
7+
8+
export default {
9+
key: "unthread-create-conversation",
10+
name: "Create Conversation",
11+
description: "Create a new Conversation. [See the documentation](https://docs.unthread.io/api-introduction/using-api#create-conversation)",
12+
version: "0.0.1",
13+
type: "action",
14+
props: {
15+
app,
16+
type: {
17+
type: "string",
18+
label: "Type",
19+
description: "Type of the conversation",
20+
options: [
21+
"triage",
22+
"email",
23+
],
24+
reloadProps: true,
25+
},
26+
markdown: {
27+
type: "string",
28+
label: "Markdown",
29+
description: "Markdown of the conversation",
30+
},
31+
status: {
32+
type: "string",
33+
label: "Status",
34+
description: "Status of the conversation",
35+
options: STATUS_OPTIONS,
36+
},
37+
assignedToUserId: {
38+
propDefinition: [
39+
app,
40+
"userId",
41+
],
42+
optional: true,
43+
},
44+
customerId: {
45+
propDefinition: [
46+
app,
47+
"customerId",
48+
],
49+
optional: true,
50+
},
51+
priority: {
52+
type: "integer",
53+
label: "Priority",
54+
description: "Priority of the conversation",
55+
options: PRIORITY_OPTIONS,
56+
optional: true,
57+
},
58+
triageChannelId: {
59+
propDefinition: [
60+
app,
61+
"triageChannelId",
62+
],
63+
hidden: true,
64+
},
65+
notes: {
66+
type: "string",
67+
label: "Notes",
68+
description: "Notes of the conversation",
69+
optional: true,
70+
},
71+
title: {
72+
type: "string",
73+
label: "Title",
74+
description: "Title of the conversation",
75+
optional: true,
76+
},
77+
excludeAnalytics: {
78+
type: "boolean",
79+
label: "Exclude Analytics",
80+
description: "Exclude Analytics for this conversation",
81+
optional: true,
82+
},
83+
emailInboxId: {
84+
type: "string",
85+
label: "Email Inbox Id",
86+
description: "ID of the Email Inbox",
87+
hidden: true,
88+
},
89+
onBehalfOfEmail: {
90+
type: "string",
91+
label: "On Behalf Of Email",
92+
description: "Email on behalf of which the conversation is created",
93+
optional: true,
94+
},
95+
onBehalfOfName: {
96+
type: "string",
97+
label: "On Behalf Of Name",
98+
description: "Name on behalf of which the conversation is created",
99+
optional: true,
100+
},
101+
onBehalfOfId: {
102+
type: "string",
103+
label: "On Behalf Of ID",
104+
description: "ID on behalf of which the conversation is created",
105+
optional: true,
106+
},
107+
},
108+
async additionalProps(props) {
109+
const isTriage = this.type === "triage";
110+
props.triageChannelId.hidden = !isTriage;
111+
props.emailInboxId.hidden = isTriage;
112+
113+
return {};
114+
},
115+
async run({ $ }) {
116+
if (this.type === "email" && (!this.onBehalfOfEmail && !this.onBehalfOfId)) {
117+
throw new ConfigurationError("You must provide either 'On Behalf Of Email' or 'On Behalf Of ID' when creating an email conversation");
118+
}
119+
const {
120+
app,
121+
onBehalfOfEmail,
122+
onBehalfOfName,
123+
onBehalfOfId,
124+
...data
125+
} = this;
126+
127+
const onBehalfOf = {};
128+
129+
if (onBehalfOfEmail) onBehalfOf.email = onBehalfOfEmail;
130+
if (onBehalfOfName) onBehalfOf.name = onBehalfOfName;
131+
if (onBehalfOfId) onBehalfOf.id = onBehalfOfId;
132+
133+
const response = await app.createConversation({
134+
$,
135+
data: {
136+
...data,
137+
onBehalfOf,
138+
},
139+
});
140+
141+
$.export("$summary", `Successfully created Conversation with ID '${response.id}'`);
142+
143+
return response;
144+
},
145+
};

components/unthread/actions/create-customer/create-customer.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "unthread-create-customer",
55
name: "Create Customer",
66
description: "Create a new Customer. [See the documentation](https://docs.unthread.io/api-introduction/using-api#create-customer)",
7-
version: "0.0.1",
7+
version: "0.0.2",
88
type: "action",
99
props: {
1010
app,

components/unthread/actions/delete-customer/delete-customer.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "unthread-delete-customer",
55
name: "Delete Customer",
66
description: "Delete a Customer. [See the documentation](https://docs.unthread.io/api-introduction/using-api#delete-customer)",
7-
version: "0.0.1",
7+
version: "0.0.2",
88
type: "action",
99
props: {
1010
app,

components/unthread/actions/update-customer/update-customer.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "unthread-update-customer",
55
name: "Update Customer",
66
description: "Update a Customer. [See the documentation](https://docs.unthread.io/api-introduction/using-api#update-customer)",
7-
version: "0.0.1",
7+
version: "0.0.2",
88
type: "action",
99
props: {
1010
app,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export const LIMIT = 100;
2+
3+
export const STATUS_OPTIONS = [
4+
"open",
5+
"in_progress",
6+
"on_hold",
7+
"closed",
8+
];
9+
10+
export const PRIORITY_OPTIONS = [
11+
{
12+
label: "3",
13+
value: 3,
14+
},
15+
{
16+
label: "5",
17+
value: 5,
18+
},
19+
{
20+
label: "7",
21+
value: 7,
22+
},
23+
{
24+
label: "9",
25+
value: 9,
26+
},
27+
];

components/unthread/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/unthread",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Pipedream Unthread Components",
55
"main": "unthread.app.mjs",
66
"keywords": [
@@ -13,6 +13,6 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16-
"@pipedream/platform": "^1.6.6"
16+
"@pipedream/platform": "^3.0.3"
1717
}
1818
}
Lines changed: 82 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,96 @@
11
import { axios } from "@pipedream/platform";
2+
import { LIMIT } from "./common/constants.mjs";
23

34
export default {
45
type: "app",
56
app: "unthread",
67
propDefinitions: {
8+
userId: {
9+
type: "string",
10+
label: "Assigned To User ID",
11+
description: "ID of the User to whom the conversation is assigned",
12+
async options({ prevContext }) {
13+
const {
14+
data, cursors,
15+
} = await this.listUsers({
16+
data: {
17+
limit: LIMIT,
18+
cursor: prevContext.nextCursor,
19+
},
20+
});
21+
22+
return {
23+
options: data.map(({
24+
id: value, email: label,
25+
}) => ({
26+
label,
27+
value,
28+
})),
29+
context: {
30+
nextCursor: cursors.next,
31+
},
32+
};
33+
},
34+
},
735
customerId: {
836
type: "string",
937
label: "Customer ID",
1038
description: "ID of the Customer",
11-
async options() {
12-
const response = await this.listCustomers();
13-
const customersIds = response.data;
14-
return customersIds.map(({
15-
id, name,
16-
}) => ({
17-
value: id,
18-
label: name,
19-
}));
39+
async options({ prevContext }) {
40+
const {
41+
data, cursors,
42+
} = await this.listCustomers({
43+
data: {
44+
limit: LIMIT,
45+
cursor: prevContext.nextCursor,
46+
},
47+
});
48+
49+
return {
50+
options: data.map(({
51+
id: value, name: label,
52+
}) => ({
53+
label,
54+
value,
55+
})),
56+
context: {
57+
nextCursor: cursors.next,
58+
},
59+
};
2060
},
2161
},
22-
slackChannelId: {
23-
type: "string",
24-
label: "Slack Channel ID",
25-
description: "ID the customer's Slack Channel",
26-
},
2762
name: {
2863
type: "string",
2964
label: "Name",
3065
description: "Name of the customer",
3166
},
67+
slackChannelId: {
68+
type: "string",
69+
label: "Slack Channel ID",
70+
description: "ID the customer's Slack Channel",
71+
},
3272
emailDomains: {
3373
type: "string[]",
3474
label: "Email Domains",
3575
description: "Email Domains of the customer, i.e.: `gmail.com`",
3676
},
37-
defaultTriageChannelId: {
77+
triageChannelId: {
3878
type: "string",
39-
label: "Default Triage Channel",
40-
description: "ID of the default triage Channel of this customer",
41-
optional: true,
79+
label: "Triage Channel ID",
80+
description: "ID the customer's Triage Channel. [See the documentation](https://docs.unthread.io/account-setup/connect-channels) for further information.",
4281
},
4382
disableAutomatedTicketing: {
4483
type: "boolean",
4584
label: "Automated Ticketing",
4685
description: "Disable Automated Ticketing for this customer",
4786
optional: true,
4887
},
88+
defaultTriageChannelId: {
89+
type: "string",
90+
label: "Default Triage Channel",
91+
description: "ID of the default triage Channel of this customer",
92+
optional: true,
93+
},
4994
slackTeamId: {
5095
type: "string",
5196
label: "Slack Team ID",
@@ -64,6 +109,7 @@ export default {
64109
headers,
65110
...otherOpts
66111
} = opts;
112+
67113
return axios($, {
68114
...otherOpts,
69115
url: this._baseUrl() + path,
@@ -73,14 +119,21 @@ export default {
73119
},
74120
});
75121
},
76-
async createCustomer(args = {}) {
122+
createConversation(args = {}) {
123+
return this._makeRequest({
124+
method: "post",
125+
path: "/conversations",
126+
...args,
127+
});
128+
},
129+
createCustomer(args = {}) {
77130
return this._makeRequest({
78131
method: "post",
79132
path: "/customers",
80133
...args,
81134
});
82135
},
83-
async updateCustomer({
136+
updateCustomer({
84137
customerId, ...args
85138
}) {
86139
return this._makeRequest({
@@ -89,7 +142,7 @@ export default {
89142
...args,
90143
});
91144
},
92-
async deleteCustomer({
145+
deleteCustomer({
93146
customerId, ...args
94147
}) {
95148
return this._makeRequest({
@@ -98,12 +151,19 @@ export default {
98151
...args,
99152
});
100153
},
101-
async listCustomers(args = {}) {
154+
listCustomers(args = {}) {
102155
return this._makeRequest({
103156
method: "post",
104157
path: "/customers/list",
105158
...args,
106159
});
107160
},
161+
listUsers(args = {}) {
162+
return this._makeRequest({
163+
method: "post",
164+
path: "/users/list",
165+
...args,
166+
});
167+
},
108168
},
109169
};

0 commit comments

Comments
 (0)