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
67 changes: 67 additions & 0 deletions components/dixa/actions/add-message/add-message.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import dixa from "../../dixa.app.mjs";

export default {
key: "dixa-add-message",
name: "Add Message to Conversation",
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).",
version: "0.0.1",
type: "action",
props: {
dixa,
endUserId: {
propDefinition: [
dixa,
"endUserId",
],
},
conversationId: {
propDefinition: [
dixa,
"conversationId",
({ endUserId }) => ({
endUserId,
}),
],
},
content: {
type: "string",
label: "Content",
description: "Content of the message",
},
direction: {
propDefinition: [
dixa,
"direction",
],
reloadProps: true,
},
agentId: {
propDefinition: [
dixa,
"agentId",
],
},
},
async additionalProps(props) {
props.agentId.hidden = this.direction !== "Outbound";
return {};
},
async run({ $ }) {
const response = await this.dixa.addMessage({
$,
conversationId: this.conversationId,
data: {
agentId: this.direction === "Outbound"
? this.agentId
: undefined,
content: {
value: this.content,
_type: "Text",
},
_type: this.direction,
},
});
$.export("$summary", `Added message to conversation ${this.conversationId}`);
return response;
},
};
102 changes: 102 additions & 0 deletions components/dixa/actions/create-conversation/create-conversation.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import dixa from "../../dixa.app.mjs";

export default {
key: "dixa-create-conversation",
name: "Create Conversation",
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).",
version: "0.0.1",
type: "action",
props: {
dixa,
requesterId: {
propDefinition: [
dixa,
"endUserId",
],
label: "Requester Id",
},
direction: {
propDefinition: [
dixa,
"direction",
],
reloadProps: true,
},
channel: {
type: "string",
label: "Channel",
description: "For outbound, only Email is supported. Inbound also supports ContactForm.",
options: [
"Email",
"ContactForm",
],
},
emailIntegrationId: {
propDefinition: [
dixa,
"emailIntegrationId",
],
},
subject: {
propDefinition: [
dixa,
"subject",
],
},
message: {
type: "string",
label: "Message",
description: "The content message.",
},
language: {
propDefinition: [
dixa,
"language",
],
optional: true,
},
agentId: {
propDefinition: [
dixa,
"agentId",
],
optional: true,
},
},
async additionalProps(props) {
props.agentId.hidden = !(this.direction === "Outbound");
props.channel.options = this.direction === "Outbound"
? [
"Email",
]
: [
"ContactForm",
"Email",
];
return {};
},
async run({ $ }) {
const response = await this.dixa.createConversation({
$,
data: {
subject: this.subject,
emailIntegrationId: this.emailIntegrationId,
language: this.language,
requesterId: this.requesterId,
message: {
agentId: this.direction === "Outbound"
? this.agentId
: undefined,
content: {
_type: "Text",
value: this.message,
},
_type: this.direction,
},
_type: this.channel,
},
});
$.export("$summary", `Created conversation with Id: ${response.data.id}`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import dixa from "../../dixa.app.mjs";

export default {
key: "dixa-set-custom-contact-attributes",
name: "Set Custom Contact Attributes",
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)",
version: "0.0.1",
type: "action",
props: {
dixa,
userId: {
propDefinition: [
dixa,
"endUserId",
],
reloadProps: true,
},
},
async additionalProps() {
const props = {};
const { data } = await this.dixa.listCustomAttributes();

for (const item of data) {
if (item.isDeactivated || item.isArchived || item.entityType != "Contact") continue;

props[item.id] = {
type: "string",
label: item.label,
description: item.description,
optional: !item.isRequired,
default: item.inputDefinition.placeholder,
};

if (item.inputDefinition._type === "Select") {
props[item.id].options = this.prepareOptions(item.inputDefinition.options);
}
}
return props;
},
methods: {
prepareOptions(options, parentVal = "", parentLabel = "") {
const newOptions = [];

for (const opt of options) {
const newLabel = parentLabel
? `${parentLabel} - ${opt.label}`
: opt.label;

const newVal = parentVal
? `${parentVal}/${opt.value}`
: opt.value;

if (opt.nestedOptions.length) {
newOptions.push(...this.prepareOptions(opt.nestedOptions, newVal, newLabel));
} else {
newOptions.push({
label: newLabel,
value: newVal,
});
}
}
return newOptions;
},
async prepareData(data) {
const response = {};
const { data: customAttributes } = await this.dixa.listCustomAttributes();
Object.entries(data).map(([
key,
val,
]) => {
const customAttribute = customAttributes.find((attr) => attr.id === key);

response[key] = customAttribute.inputDefinition._type != "Text"
? val.split("/")
: val;
});
return response;
},
},
async run({ $ }) {
const {
dixa,
// eslint-disable-next-line no-unused-vars
prepareOptions,
prepareData,
userId,
...data
} = this;

const response = await dixa.updateCustomAttributes({
$,
userId,
data: await prepareData(data),
});
$.export("$summary", `Updated custom attributes for user ${this.userId}`);
return response;
},
};
42 changes: 42 additions & 0 deletions components/dixa/actions/tag-conversation/tag-conversation.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import dixa from "../../dixa.app.mjs";

export default {
key: "dixa-tag-conversation",
name: "Add Tag to Conversation",
description: "Adds a tag to a conversation. [See the documentation](https://docs.dixa.io/openapi/dixa-api/v1/tag/Tags/#tag/Tags/operation/putConversationsConversationidTagsTagid)",
version: "0.0.1",
type: "action",
props: {
dixa,
endUserId: {
propDefinition: [
dixa,
"endUserId",
],
},
conversationId: {
propDefinition: [
dixa,
"conversationId",
({ endUserId }) => ({
endUserId,
}),
],
},
tagId: {
propDefinition: [
dixa,
"tagId",
],
},
},
async run({ $ }) {
const response = await this.dixa.addTag({
$,
conversationId: this.conversationId,
tagId: this.tagId,
});
$.export("$summary", `Added tag ${this.tagId} to conversation ${this.conversationId}`);
return response;
},
};
Loading
Loading