Skip to content

Commit 320ace7

Browse files
New Components - dixa (#15261)
* dixa init * [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 * pnpm update * some adjusts * Update components/dixa/actions/add-message/add-message.mjs Co-authored-by: Guilherme Falcão <48412907+GTFalcao@users.noreply.github.com> * some adjusts * fix add-message data --------- Co-authored-by: Guilherme Falcão <48412907+GTFalcao@users.noreply.github.com>
1 parent ac79b00 commit 320ace7

File tree

18 files changed

+959
-7
lines changed

18 files changed

+959
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import dixa from "../../dixa.app.mjs";
2+
3+
export default {
4+
key: "dixa-add-message",
5+
name: "Add Message to Conversation",
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",
8+
type: "action",
9+
props: {
10+
dixa,
11+
endUserId: {
12+
propDefinition: [
13+
dixa,
14+
"endUserId",
15+
],
16+
},
17+
conversationId: {
18+
propDefinition: [
19+
dixa,
20+
"conversationId",
21+
({ endUserId }) => ({
22+
endUserId,
23+
}),
24+
],
25+
},
26+
content: {
27+
type: "string",
28+
label: "Content",
29+
description: "Content of the message",
30+
},
31+
direction: {
32+
propDefinition: [
33+
dixa,
34+
"direction",
35+
],
36+
reloadProps: true,
37+
},
38+
agentId: {
39+
propDefinition: [
40+
dixa,
41+
"agentId",
42+
],
43+
},
44+
},
45+
async additionalProps(props) {
46+
props.agentId.hidden = this.direction !== "Outbound";
47+
return {};
48+
},
49+
async run({ $ }) {
50+
const response = await this.dixa.addMessage({
51+
$,
52+
conversationId: this.conversationId,
53+
data: {
54+
agentId: this.direction === "Outbound"
55+
? this.agentId
56+
: undefined,
57+
content: {
58+
value: this.content,
59+
_type: "Text",
60+
},
61+
_type: this.direction,
62+
},
63+
});
64+
$.export("$summary", `Added message to conversation ${this.conversationId}`);
65+
return response;
66+
},
67+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import dixa from "../../dixa.app.mjs";
2+
3+
export default {
4+
key: "dixa-create-conversation",
5+
name: "Create Conversation",
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",
8+
type: "action",
9+
props: {
10+
dixa,
11+
requesterId: {
12+
propDefinition: [
13+
dixa,
14+
"endUserId",
15+
],
16+
label: "Requester Id",
17+
},
18+
direction: {
19+
propDefinition: [
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",
32+
],
33+
},
34+
emailIntegrationId: {
35+
propDefinition: [
36+
dixa,
37+
"emailIntegrationId",
38+
],
39+
},
40+
subject: {
41+
propDefinition: [
42+
dixa,
43+
"subject",
44+
],
45+
},
46+
message: {
47+
type: "string",
48+
label: "Message",
49+
description: "The content message.",
50+
},
51+
language: {
52+
propDefinition: [
53+
dixa,
54+
"language",
55+
],
56+
optional: true,
57+
},
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 {};
77+
},
78+
async run({ $ }) {
79+
const response = await this.dixa.createConversation({
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+
},
98+
});
99+
$.export("$summary", `Created conversation with Id: ${response.data.id}`);
100+
return response;
101+
},
102+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import dixa from "../../dixa.app.mjs";
2+
3+
export default {
4+
key: "dixa-set-custom-contact-attributes",
5+
name: "Set Custom Contact Attributes",
6+
description: "Updates custom attributes for a specified user. [See the documentation](https://docs.dixa.io/openapi/dixa-api/v1/tag/Custom-Attributes/#tag/Custom-Attributes/operation/patchEndusersUseridCustom-attributes)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
dixa,
11+
userId: {
12+
propDefinition: [
13+
dixa,
14+
"endUserId",
15+
],
16+
reloadProps: true,
17+
},
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;
78+
},
79+
},
80+
async run({ $ }) {
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),
94+
});
95+
$.export("$summary", `Updated custom attributes for user ${this.userId}`);
96+
return response;
97+
},
98+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import dixa from "../../dixa.app.mjs";
2+
3+
export default {
4+
key: "dixa-tag-conversation",
5+
name: "Add Tag to Conversation",
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",
8+
type: "action",
9+
props: {
10+
dixa,
11+
endUserId: {
12+
propDefinition: [
13+
dixa,
14+
"endUserId",
15+
],
16+
},
17+
conversationId: {
18+
propDefinition: [
19+
dixa,
20+
"conversationId",
21+
({ endUserId }) => ({
22+
endUserId,
23+
}),
24+
],
25+
},
26+
tagId: {
27+
propDefinition: [
28+
dixa,
29+
"tagId",
30+
],
31+
},
32+
},
33+
async run({ $ }) {
34+
const response = await this.dixa.addTag({
35+
$,
36+
conversationId: this.conversationId,
37+
tagId: this.tagId,
38+
});
39+
$.export("$summary", `Added tag ${this.tagId} to conversation ${this.conversationId}`);
40+
return response;
41+
},
42+
};

0 commit comments

Comments
 (0)