Skip to content

Commit 389b3b1

Browse files
committed
[Components] dixa #15252
Sources - New Customer Satisfaction Rating (Instant) - New Conversation Status Changed (Instant) - New Message Added (Instant) - New Tag Added (Instant) Actions - Create Conversation - Add Message - Set Custom Contact Attributes - Tag Conversation
1 parent 9dbb4f1 commit 389b3b1

File tree

18 files changed

+743
-782
lines changed

18 files changed

+743
-782
lines changed

components/dixa/actions/add-message/add-message.mjs

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,65 @@
11
import dixa from "../../dixa.app.mjs";
2-
import { axios } from "@pipedream/platform";
32

43
export default {
54
key: "dixa-add-message",
65
name: "Add Message to Conversation",
7-
description: "Adds a message to an existing conversation. [See the documentation]().",
8-
version: "0.0.{{ts}}",
6+
description: "Adds a message to an existing conversation. [See the documentation](https://docs.dixa.io/openapi/dixa-api/v1/tag/Conversations/#tag/Conversations/operation/postConversationsConversationidMessages).",
7+
version: "0.0.1",
98
type: "action",
109
props: {
1110
dixa,
12-
conversationId: {
11+
endUserId: {
1312
propDefinition: [
1413
dixa,
15-
"conversationId",
14+
"endUserId",
1615
],
1716
},
18-
attachments: {
17+
conversationId: {
1918
propDefinition: [
2019
dixa,
21-
"attachments",
20+
"conversationId",
21+
({ endUserId }) => ({
22+
endUserId,
23+
}),
2224
],
23-
optional: true,
2425
},
2526
content: {
26-
propDefinition: [
27-
dixa,
28-
"content",
29-
],
30-
optional: true,
27+
type: "string",
28+
label: "Content",
29+
description: "Content of the message",
3130
},
32-
externalId: {
31+
direction: {
3332
propDefinition: [
3433
dixa,
35-
"externalId",
34+
"direction",
3635
],
37-
optional: true,
36+
reloadProps: true,
3837
},
39-
integrationEmail: {
38+
agentId: {
4039
propDefinition: [
4140
dixa,
42-
"integrationEmail",
41+
"agentId",
4342
],
44-
optional: true,
4543
},
4644
},
45+
async additionalProps(props) {
46+
props.agentId.hidden = !this.direction === "Outbound";
47+
return {};
48+
},
4749
async run({ $ }) {
4850
const response = await this.dixa.addMessage({
51+
$,
4952
conversationId: this.conversationId,
50-
attachments: this.attachments,
51-
content: this.content,
52-
externalId: this.externalId,
53-
integrationEmail: this.integrationEmail,
53+
data: {
54+
content: {
55+
agentId: this.direction === "Outbound"
56+
? this.agentId
57+
: undefined,
58+
value: this.content,
59+
_type: "Text",
60+
},
61+
_type: this.direction,
62+
},
5463
});
5564
$.export("$summary", `Added message to conversation ${this.conversationId}`);
5665
return response;
Lines changed: 70 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,102 @@
11
import dixa from "../../dixa.app.mjs";
2-
import { axios } from "@pipedream/platform";
32

43
export default {
54
key: "dixa-create-conversation",
65
name: "Create Conversation",
7-
description: "Creates a new email or contact form-based conversation. [See the documentation](https://docs.dixa.io/openapi).",
8-
version: "0.0.{{ts}}",
6+
description: "Creates a new email or contact form-based conversation. [See the documentation](https://docs.dixa.io/openapi/dixa-api/v1/tag/Conversations/#tag/Conversations/operation/postConversations).",
7+
version: "0.0.1",
98
type: "action",
109
props: {
11-
dixa: {
12-
type: "app",
13-
app: "dixa",
10+
dixa,
11+
requesterId: {
12+
propDefinition: [
13+
dixa,
14+
"endUserId",
15+
],
16+
label: "Requester Id",
1417
},
15-
subject: {
18+
direction: {
1619
propDefinition: [
17-
"dixa",
18-
"subject",
20+
dixa,
21+
"direction",
22+
],
23+
reloadProps: true,
24+
},
25+
channel: {
26+
type: "string",
27+
label: "Channel",
28+
description: "For outbound, only Email is supported. Inbound also supports ContactForm.",
29+
options: [
30+
"Email",
31+
"ContactForm",
1932
],
2033
},
2134
emailIntegrationId: {
2235
propDefinition: [
23-
"dixa",
36+
dixa,
2437
"emailIntegrationId",
2538
],
2639
},
27-
messageType: {
40+
subject: {
2841
propDefinition: [
29-
"dixa",
30-
"messageType",
42+
dixa,
43+
"subject",
3144
],
3245
},
46+
message: {
47+
type: "string",
48+
label: "Message",
49+
description: "The content message.",
50+
},
3351
language: {
3452
propDefinition: [
35-
"dixa",
53+
dixa,
3654
"language",
3755
],
3856
optional: true,
3957
},
58+
agentId: {
59+
propDefinition: [
60+
dixa,
61+
"agentId",
62+
],
63+
optional: true,
64+
},
65+
},
66+
async additionalProps(props) {
67+
props.agentId.hidden = !this.direction === "Outbound";
68+
props.channel.options = this.direction === "Outbound"
69+
? [
70+
"Email",
71+
]
72+
: [
73+
"ContactForm",
74+
"Email",
75+
];
76+
return {};
4077
},
4178
async run({ $ }) {
4279
const response = await this.dixa.createConversation({
43-
subject: this.subject,
44-
emailIntegrationId: this.emailIntegrationId,
45-
messageType: this.messageType,
46-
language: this.language,
80+
$,
81+
data: {
82+
subject: this.subject,
83+
emailIntegrationId: this.emailIntegrationId,
84+
language: this.language,
85+
requesterId: this.requesterId,
86+
message: {
87+
agentId: this.direction === "Outbound"
88+
? this.agentId
89+
: undefined,
90+
content: {
91+
_type: "Text",
92+
value: this.message,
93+
},
94+
_type: this.direction,
95+
},
96+
_type: this.channel,
97+
},
4798
});
48-
$.export("$summary", `Created conversation with subject: ${response.subject} and ID: ${response.id}`);
99+
$.export("$summary", `Created conversation with Id: ${response.data.id}`);
49100
return response;
50101
},
51102
};

components/dixa/actions/set-custom-contact-attributes/set-custom-contact-attributes.mjs

Lines changed: 76 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,96 @@
11
import dixa from "../../dixa.app.mjs";
2-
import { axios } from "@pipedream/platform";
32

43
export default {
54
key: "dixa-set-custom-contact-attributes",
65
name: "Set Custom Contact Attributes",
76
description: "Updates custom attributes for a specified user. [See the documentation]()",
8-
version: "0.0.{{ts}}",
7+
version: "0.0.1",
98
type: "action",
109
props: {
1110
dixa,
1211
userId: {
1312
propDefinition: [
1413
dixa,
15-
"userId",
14+
"endUserId",
1615
],
16+
reloadProps: true,
1717
},
18-
attributes: {
19-
propDefinition: [
20-
dixa,
21-
"attributes",
22-
],
23-
optional: true,
18+
},
19+
async additionalProps() {
20+
const props = {};
21+
const { data } = await this.dixa.listCustomAttributes();
22+
23+
for (const item of data) {
24+
if (item.isDeactivated || item.isArchived || item.entityType != "Contact") continue;
25+
26+
props[item.id] = {
27+
type: "string",
28+
label: item.label,
29+
description: item.description,
30+
optional: !item.isRequired,
31+
default: item.inputDefinition.placeholder,
32+
};
33+
34+
if (item.inputDefinition._type === "Select") {
35+
props[item.id].options = this.prepareOptions(item.inputDefinition.options);
36+
}
37+
}
38+
return props;
39+
},
40+
methods: {
41+
prepareOptions(options, parentVal = "", parentLabel = "") {
42+
const newOptions = [];
43+
44+
for (const opt of options) {
45+
const newLabel = parentLabel
46+
? `${parentLabel} - ${opt.label}`
47+
: opt.label;
48+
49+
const newVal = parentVal
50+
? `${parentVal}/${opt.value}`
51+
: opt.value;
52+
53+
if (opt.nestedOptions.length) {
54+
newOptions.push(...this.prepareOptions(opt.nestedOptions, newVal, newLabel));
55+
} else {
56+
newOptions.push({
57+
label: newLabel,
58+
value: newVal,
59+
});
60+
}
61+
}
62+
return newOptions;
63+
},
64+
async prepareData(data) {
65+
const response = {};
66+
const { data: customAttributes } = await this.dixa.listCustomAttributes();
67+
Object.entries(data).map(([
68+
key,
69+
val,
70+
]) => {
71+
const customAttribute = customAttributes.find((attr) => attr.id === key);
72+
73+
response[key] = customAttribute.inputDefinition._type != "Text"
74+
? val.split("/")
75+
: val;
76+
});
77+
return response;
2478
},
2579
},
2680
async run({ $ }) {
27-
const response = await this.dixa.updateCustomAttributes({
28-
userId: this.userId,
29-
attributes: this.attributes,
81+
const {
82+
dixa,
83+
// eslint-disable-next-line no-unused-vars
84+
prepareOptions,
85+
prepareData,
86+
userId,
87+
...data
88+
} = this;
89+
90+
const response = await dixa.updateCustomAttributes({
91+
$,
92+
userId,
93+
data: await prepareData(data),
3094
});
3195
$.export("$summary", `Updated custom attributes for user ${this.userId}`);
3296
return response;

components/dixa/actions/tag-conversation/tag-conversation.mjs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
import dixa from "../../dixa.app.mjs";
2-
import { axios } from "@pipedream/platform";
32

43
export default {
54
key: "dixa-tag-conversation",
65
name: "Add Tag to Conversation",
7-
description: "Adds a tag to a conversation. [See the documentation]()",
8-
version: "0.0.{{ts}}",
6+
description: "Adds a tag to a conversation. [See the documentation](https://docs.dixa.io/openapi/dixa-api/v1/tag/Tags/#tag/Tags/operation/putConversationsConversationidTagsTagid)",
7+
version: "0.0.1",
98
type: "action",
109
props: {
11-
dixa: {
12-
type: "app",
13-
app: "dixa",
10+
dixa,
11+
endUserId: {
12+
propDefinition: [
13+
dixa,
14+
"endUserId",
15+
],
1416
},
1517
conversationId: {
1618
propDefinition: [
1719
dixa,
1820
"conversationId",
21+
({ endUserId }) => ({
22+
endUserId,
23+
}),
1924
],
2025
},
2126
tagId: {
@@ -27,6 +32,7 @@ export default {
2732
},
2833
async run({ $ }) {
2934
const response = await this.dixa.addTag({
35+
$,
3036
conversationId: this.conversationId,
3137
tagId: this.tagId,
3238
});

components/dixa/common/utils.mjs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) return undefined;
3+
4+
if (Array.isArray(obj)) {
5+
return obj.map((item) => {
6+
if (typeof item === "string") {
7+
try {
8+
return JSON.parse(item);
9+
} catch (e) {
10+
return item;
11+
}
12+
}
13+
return item;
14+
});
15+
}
16+
if (typeof obj === "string") {
17+
try {
18+
return JSON.parse(obj);
19+
} catch (e) {
20+
return obj;
21+
}
22+
}
23+
return obj;
24+
};

0 commit comments

Comments
 (0)