Merge branch 'develop' into feat/shopify-app-store-install-flow
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script setup>
|
||||
import { ref, computed, onMounted, watch } from 'vue';
|
||||
import { reactive, ref, computed, onMounted, watch } from 'vue';
|
||||
import { useStore, useMapGetter } from 'dashboard/composables/store';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useWindowSize } from '@vueuse/core';
|
||||
@@ -59,6 +59,23 @@ const isFetchingInboxes = ref(false);
|
||||
const isSearching = ref(false);
|
||||
const showComposeNewConversation = ref(false);
|
||||
|
||||
const formState = reactive({
|
||||
message: '',
|
||||
subject: '',
|
||||
ccEmails: '',
|
||||
bccEmails: '',
|
||||
attachedFiles: [],
|
||||
});
|
||||
|
||||
const clearFormState = () => {
|
||||
Object.assign(formState, {
|
||||
subject: '',
|
||||
ccEmails: '',
|
||||
bccEmails: '',
|
||||
attachedFiles: [],
|
||||
});
|
||||
};
|
||||
|
||||
const contactById = useMapGetter('contacts/getContactById');
|
||||
const contactsUiFlags = useMapGetter('contacts/getUIFlags');
|
||||
const currentUser = useMapGetter('getCurrentUser');
|
||||
@@ -140,12 +157,14 @@ const handleSelectedContact = async ({ value, action, ...rest }) => {
|
||||
|
||||
const handleTargetInbox = inbox => {
|
||||
targetInbox.value = inbox;
|
||||
if (!inbox) clearFormState();
|
||||
resetContacts();
|
||||
};
|
||||
|
||||
const clearSelectedContact = () => {
|
||||
selectedContact.value = null;
|
||||
targetInbox.value = null;
|
||||
clearFormState();
|
||||
};
|
||||
|
||||
const closeCompose = () => {
|
||||
@@ -160,6 +179,12 @@ const closeCompose = () => {
|
||||
emit('close');
|
||||
};
|
||||
|
||||
const discardCompose = () => {
|
||||
clearFormState();
|
||||
formState.message = '';
|
||||
closeCompose();
|
||||
};
|
||||
|
||||
const createConversation = async ({ payload, isFromWhatsApp }) => {
|
||||
try {
|
||||
const data = await store.dispatch('contactConversations/create', {
|
||||
@@ -171,7 +196,7 @@ const createConversation = async ({ payload, isFromWhatsApp }) => {
|
||||
to: `/app/accounts/${data.account_id}/conversations/${data.id}`,
|
||||
message: t('COMPOSE_NEW_CONVERSATION.FORM.GO_TO_CONVERSATION'),
|
||||
};
|
||||
closeCompose();
|
||||
discardCompose();
|
||||
useAlert(t('COMPOSE_NEW_CONVERSATION.FORM.SUCCESS_MESSAGE'), action);
|
||||
return true; // Return success
|
||||
} catch (error) {
|
||||
@@ -193,7 +218,11 @@ watch(
|
||||
(currentContact, previousContact) => {
|
||||
if (currentContact && props.contactId) {
|
||||
// Reset on contact change
|
||||
if (currentContact?.id !== previousContact?.id) clearSelectedContact();
|
||||
if (currentContact?.id !== previousContact?.id) {
|
||||
clearSelectedContact();
|
||||
clearFormState();
|
||||
formState.message = '';
|
||||
}
|
||||
|
||||
// First process the contactable inboxes to get the right structure
|
||||
const processedInboxes = processContactableInboxes(
|
||||
@@ -265,6 +294,7 @@ useKeyboardEvents(keyboardEvents);
|
||||
@click.self="onModalBackdropClick"
|
||||
>
|
||||
<ComposeNewConversationForm
|
||||
:form-state="formState"
|
||||
:class="[{ 'mt-2': !viewInModal }, composePopoverClass]"
|
||||
:contacts="contacts"
|
||||
:contact-id="contactId"
|
||||
@@ -285,7 +315,7 @@ useKeyboardEvents(keyboardEvents);
|
||||
@update-target-inbox="handleTargetInbox"
|
||||
@clear-selected-contact="clearSelectedContact"
|
||||
@create-conversation="createConversation"
|
||||
@discard="closeCompose"
|
||||
@discard="discardCompose"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+4
-3
@@ -1,5 +1,5 @@
|
||||
<script setup>
|
||||
import { reactive, ref, computed } from 'vue';
|
||||
import { ref, computed } from 'vue';
|
||||
import { useVuelidate } from '@vuelidate/core';
|
||||
import { required, requiredIf } from '@vuelidate/validators';
|
||||
import { INBOX_TYPES } from 'dashboard/helper/inbox';
|
||||
@@ -37,6 +37,7 @@ const props = defineProps({
|
||||
contactsUiFlags: { type: Object, default: null },
|
||||
messageSignature: { type: String, default: '' },
|
||||
sendWithSignature: { type: Boolean, default: false },
|
||||
formState: { type: Object, required: true },
|
||||
});
|
||||
|
||||
const emit = defineEmits([
|
||||
@@ -57,13 +58,13 @@ const showBccEmailsDropdown = ref(false);
|
||||
|
||||
const isCreating = computed(() => props.contactConversationsUiFlags.isCreating);
|
||||
|
||||
const state = reactive({
|
||||
const state = props.formState || {
|
||||
message: '',
|
||||
subject: '',
|
||||
ccEmails: '',
|
||||
bccEmails: '',
|
||||
attachedFiles: [],
|
||||
});
|
||||
};
|
||||
|
||||
const inboxTypes = computed(() => ({
|
||||
isEmail: props.targetInbox?.channelType === INBOX_TYPES.EMAIL,
|
||||
|
||||
@@ -145,6 +145,7 @@ const {
|
||||
isConversationSelected,
|
||||
onAssignAgent,
|
||||
onAssignLabels,
|
||||
onRemoveLabels,
|
||||
onAssignTeamsForBulk,
|
||||
onUpdateConversations,
|
||||
} = useBulkActions();
|
||||
@@ -859,6 +860,7 @@ provide('deSelectConversation', deSelectConversation);
|
||||
provide('assignAgent', onAssignAgent);
|
||||
provide('assignTeam', onAssignTeam);
|
||||
provide('assignLabels', onAssignLabels);
|
||||
provide('removeLabels', onRemoveLabels);
|
||||
provide('updateConversationStatus', handleResolveConversation);
|
||||
provide('toggleContextMenu', onContextMenuToggle);
|
||||
provide('markAsUnread', markAsUnread);
|
||||
|
||||
@@ -10,6 +10,7 @@ export default {
|
||||
'assignAgent',
|
||||
'assignTeam',
|
||||
'assignLabels',
|
||||
'removeLabels',
|
||||
'updateConversationStatus',
|
||||
'toggleContextMenu',
|
||||
'markAsUnread',
|
||||
@@ -63,6 +64,7 @@ export default {
|
||||
@assign-agent="assignAgent"
|
||||
@assign-team="assignTeam"
|
||||
@assign-label="assignLabels"
|
||||
@remove-label="removeLabels"
|
||||
@update-conversation-status="updateConversationStatus"
|
||||
@context-menu-toggle="toggleContextMenu"
|
||||
@mark-as-unread="markAsUnread"
|
||||
|
||||
@@ -28,7 +28,10 @@ import { useAlert } from 'dashboard/composables';
|
||||
import { vOnClickOutside } from '@vueuse/components';
|
||||
|
||||
import { BUS_EVENTS } from 'shared/constants/busEvents';
|
||||
import { CONVERSATION_EVENTS } from 'dashboard/helper/AnalyticsHelper/events';
|
||||
import {
|
||||
CONVERSATION_EVENTS,
|
||||
CAPTAIN_EVENTS,
|
||||
} from 'dashboard/helper/AnalyticsHelper/events';
|
||||
import { MESSAGE_EDITOR_IMAGE_RESIZES } from 'dashboard/constants/editor';
|
||||
|
||||
import {
|
||||
@@ -86,6 +89,7 @@ const props = defineProps({
|
||||
// are triggered except when this flag is true
|
||||
allowSignature: { type: Boolean, default: false },
|
||||
channelType: { type: String, default: '' },
|
||||
conversationId: { type: Number, default: null },
|
||||
medium: { type: String, default: '' },
|
||||
showImageResizeToolbar: { type: Boolean, default: false }, // A kill switch to show or hide the image toolbar
|
||||
focusOnMount: { type: Boolean, default: true },
|
||||
@@ -396,7 +400,14 @@ function openFileBrowser() {
|
||||
}
|
||||
|
||||
function handleCopilotClick() {
|
||||
showSelectionMenu.value = !showSelectionMenu.value;
|
||||
const isOpening = !showSelectionMenu.value;
|
||||
if (isOpening) {
|
||||
useTrack(CAPTAIN_EVENTS.EDITOR_AI_MENU_OPENED, {
|
||||
conversationId: props.conversationId,
|
||||
entryPoint: 'inline',
|
||||
});
|
||||
}
|
||||
showSelectionMenu.value = isOpening;
|
||||
}
|
||||
|
||||
function handleClickOutside(event) {
|
||||
@@ -819,7 +830,13 @@ useEmitter(BUS_EVENTS.INSERT_INTO_RICH_EDITOR, insertContentIntoEditor);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="editorRoot" class="relative w-full">
|
||||
<div
|
||||
ref="editorRoot"
|
||||
class="relative w-full"
|
||||
:class="{
|
||||
'opacity-50 cursor-not-allowed pointer-events-none': disabled,
|
||||
}"
|
||||
>
|
||||
<TagAgents
|
||||
v-if="showUserMentions && isPrivate"
|
||||
:search-key="mentionSearchKey"
|
||||
|
||||
@@ -122,6 +122,10 @@ export default {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
isEditorDisabled: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
emits: [
|
||||
'replaceText',
|
||||
@@ -130,7 +134,7 @@ export default {
|
||||
'selectContentTemplate',
|
||||
'toggleQuotedReply',
|
||||
],
|
||||
setup() {
|
||||
setup(props) {
|
||||
const { setSignatureFlagForInbox, fetchSignatureFlagFromUISettings } =
|
||||
useUISettings();
|
||||
|
||||
@@ -139,6 +143,9 @@ export default {
|
||||
const keyboardEvents = {
|
||||
'$mod+Alt+KeyA': {
|
||||
action: () => {
|
||||
// Skip if editor is disabled (e.g., WhatsApp 24-hour window expired)
|
||||
if (props.isEditorDisabled) return;
|
||||
|
||||
// TODO: This is really hacky, we need to replace the file picker component with
|
||||
// a custom one, where the logic and the component markup is isolated.
|
||||
// Once we have the custom component, we can remove the hacky logic below.
|
||||
@@ -146,7 +153,7 @@ export default {
|
||||
const uploadTriggerButton = document.querySelector(
|
||||
'#conversationAttachment'
|
||||
);
|
||||
uploadTriggerButton.click();
|
||||
if (uploadTriggerButton) uploadTriggerButton.click();
|
||||
},
|
||||
allowOnFocusedInput: true,
|
||||
},
|
||||
@@ -177,9 +184,11 @@ export default {
|
||||
};
|
||||
},
|
||||
showAttachButton() {
|
||||
if (this.isEditorDisabled) return false;
|
||||
return this.showFileUpload || this.isNote;
|
||||
},
|
||||
showAudioRecorderButton() {
|
||||
if (this.isEditorDisabled) return false;
|
||||
if (this.isALineChannel) {
|
||||
return false;
|
||||
}
|
||||
@@ -197,6 +206,7 @@ export default {
|
||||
);
|
||||
},
|
||||
showAudioPlayStopButton() {
|
||||
if (this.isEditorDisabled) return false;
|
||||
return this.showAudioRecorder && this.isRecordingAudio;
|
||||
},
|
||||
isInstagramDM() {
|
||||
@@ -236,6 +246,7 @@ export default {
|
||||
}
|
||||
},
|
||||
showMessageSignatureButton() {
|
||||
if (this.isEditorDisabled) return false;
|
||||
return !this.isOnPrivateNote;
|
||||
},
|
||||
sendWithSignature() {
|
||||
@@ -280,6 +291,7 @@ export default {
|
||||
<div class="flex justify-between p-3" :class="wrapClass">
|
||||
<div class="left-wrap">
|
||||
<NextButton
|
||||
v-if="!isEditorDisabled"
|
||||
v-tooltip.top-end="$t('CONVERSATION.REPLYBOX.TIP_EMOJI_ICON')"
|
||||
icon="i-ph-smiley-sticker"
|
||||
slate
|
||||
@@ -288,6 +300,7 @@ export default {
|
||||
@click="toggleEmojiPicker"
|
||||
/>
|
||||
<FileUpload
|
||||
v-if="showAttachButton"
|
||||
ref="uploadRef"
|
||||
v-tooltip.top-end="$t('CONVERSATION.REPLYBOX.TIP_ATTACH_ICON')"
|
||||
input-id="conversationAttachment"
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
import { ref } from 'vue';
|
||||
import { useKeyboardEvents } from 'dashboard/composables/useKeyboardEvents';
|
||||
import { useCaptain } from 'dashboard/composables/useCaptain';
|
||||
import { useTrack } from 'dashboard/composables';
|
||||
import { vOnClickOutside } from '@vueuse/components';
|
||||
import { REPLY_EDITOR_MODES, CHAR_LENGTH_WARNING } from './constants';
|
||||
import { CAPTAIN_EVENTS } from 'dashboard/helper/AnalyticsHelper/events';
|
||||
import NextButton from 'dashboard/components-next/button/Button.vue';
|
||||
import EditorModeToggle from './EditorModeToggle.vue';
|
||||
import CopilotMenuBar from './CopilotMenuBar.vue';
|
||||
@@ -31,6 +33,14 @@ export default {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
isEditorDisabled: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
conversationId: {
|
||||
type: Number,
|
||||
default: null,
|
||||
},
|
||||
isMessageLengthReachingThreshold: {
|
||||
type: Boolean,
|
||||
default: () => false,
|
||||
@@ -69,7 +79,14 @@ export default {
|
||||
};
|
||||
|
||||
const toggleCopilotMenu = () => {
|
||||
showCopilotMenu.value = !showCopilotMenu.value;
|
||||
const isOpening = !showCopilotMenu.value;
|
||||
if (isOpening) {
|
||||
useTrack(CAPTAIN_EVENTS.EDITOR_AI_MENU_OPENED, {
|
||||
conversationId: props.conversationId,
|
||||
entryPoint: 'top_panel',
|
||||
});
|
||||
}
|
||||
showCopilotMenu.value = isOpening;
|
||||
};
|
||||
|
||||
const handleClickOutside = () => {
|
||||
@@ -144,7 +161,7 @@ export default {
|
||||
<div class="relative">
|
||||
<NextButton
|
||||
ghost
|
||||
:disabled="disabled"
|
||||
:disabled="disabled || isEditorDisabled"
|
||||
:class="{
|
||||
'text-n-violet-9 hover:enabled:!bg-n-violet-3': !showCopilotMenu,
|
||||
'text-n-violet-9 bg-n-violet-3': showCopilotMenu,
|
||||
|
||||
@@ -34,6 +34,7 @@ const emit = defineEmits([
|
||||
'contextMenuToggle',
|
||||
'assignAgent',
|
||||
'assignLabel',
|
||||
'removeLabel',
|
||||
'assignTeam',
|
||||
'markAsUnread',
|
||||
'markAsRead',
|
||||
@@ -203,7 +204,10 @@ const onAssignAgent = agent => {
|
||||
|
||||
const onAssignLabel = label => {
|
||||
emit('assignLabel', [label.title], [props.chat.id]);
|
||||
closeContextMenu();
|
||||
};
|
||||
|
||||
const onRemoveLabel = label => {
|
||||
emit('removeLabel', [label.title], [props.chat.id]);
|
||||
};
|
||||
|
||||
const onAssignTeam = team => {
|
||||
@@ -379,11 +383,13 @@ const deleteConversation = () => {
|
||||
:priority="chat.priority"
|
||||
:chat-id="chat.id"
|
||||
:has-unread-messages="hasUnread"
|
||||
:conversation-labels="chat.labels"
|
||||
:conversation-url="conversationPath"
|
||||
:allowed-options="allowedContextMenuOptions"
|
||||
@update-conversation="onUpdateConversation"
|
||||
@assign-agent="onAssignAgent"
|
||||
@assign-label="onAssignLabel"
|
||||
@remove-label="onRemoveLabel"
|
||||
@assign-team="onAssignTeam"
|
||||
@mark-as-unread="markAsUnread"
|
||||
@mark-as-read="markAsRead"
|
||||
|
||||
@@ -41,7 +41,10 @@ import {
|
||||
truncatePreviewText,
|
||||
appendQuotedTextToMessage,
|
||||
} from 'dashboard/helper/quotedEmailHelper';
|
||||
import { CONVERSATION_EVENTS } from '../../../helper/AnalyticsHelper/events';
|
||||
import {
|
||||
CONVERSATION_EVENTS,
|
||||
CAPTAIN_EVENTS,
|
||||
} from '../../../helper/AnalyticsHelper/events';
|
||||
import fileUploadMixin from 'dashboard/mixins/fileUploadMixin';
|
||||
import {
|
||||
appendSignature,
|
||||
@@ -136,6 +139,7 @@ export default {
|
||||
newConversationModalActive: false,
|
||||
showArticleSearchPopover: false,
|
||||
hasRecordedAudio: false,
|
||||
copilotAcceptedMessages: {},
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@@ -195,6 +199,11 @@ export default {
|
||||
return this.$store.getters['inboxes/getInbox'](this.inboxId);
|
||||
},
|
||||
messagePlaceHolder() {
|
||||
if (this.isEditorDisabled) {
|
||||
return this.isAWhatsAppChannel
|
||||
? this.$t('CONVERSATION.FOOTER.MESSAGING_RESTRICTED_WHATSAPP')
|
||||
: this.$t('CONVERSATION.FOOTER.MESSAGING_RESTRICTED');
|
||||
}
|
||||
return this.isPrivate
|
||||
? this.$t('CONVERSATION.FOOTER.PRIVATE_MSG_INPUT')
|
||||
: this.$t('CONVERSATION.FOOTER.MSG_INPUT');
|
||||
@@ -206,6 +215,7 @@ export default {
|
||||
return this.maxLength - this.message.length;
|
||||
},
|
||||
isReplyButtonDisabled() {
|
||||
if (this.isEditorDisabled) return true;
|
||||
if (this.isATwitterInbox) return true;
|
||||
if (this.hasAttachments || this.hasRecordedAudio) return false;
|
||||
|
||||
@@ -414,6 +424,13 @@ export default {
|
||||
isDefaultEditorMode() {
|
||||
return !this.showAudioRecorderEditor && !this.copilot.isActive.value;
|
||||
},
|
||||
isEditorDisabled() {
|
||||
return (
|
||||
this.isAWhatsAppChannel &&
|
||||
!this.isOnPrivateNote &&
|
||||
!this.currentChat.can_reply
|
||||
);
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
currentChat(conversation, oldConversation) {
|
||||
@@ -508,6 +525,24 @@ export default {
|
||||
emitter.off(CMD_AI_ASSIST, this.executeCopilotAction);
|
||||
},
|
||||
methods: {
|
||||
getDraftKey(
|
||||
conversationId = this.conversationIdByRoute,
|
||||
replyType = this.replyType
|
||||
) {
|
||||
return `draft-${conversationId}-${replyType}`;
|
||||
},
|
||||
getCopilotAcceptedMessage(replyType = this.replyType) {
|
||||
const key = this.getDraftKey(this.conversationIdByRoute, replyType);
|
||||
return this.copilotAcceptedMessages[key] || '';
|
||||
},
|
||||
setCopilotAcceptedMessage(message, replyType = this.replyType) {
|
||||
const key = this.getDraftKey(this.conversationIdByRoute, replyType);
|
||||
this.copilotAcceptedMessages[key] = trimContent(message || '');
|
||||
},
|
||||
clearCopilotAcceptedMessage(replyType = this.replyType) {
|
||||
const key = this.getDraftKey(this.conversationIdByRoute, replyType);
|
||||
delete this.copilotAcceptedMessages[key];
|
||||
},
|
||||
handleInsert(article) {
|
||||
const { url, title } = article;
|
||||
// Removing empty lines from the title
|
||||
@@ -559,7 +594,7 @@ export default {
|
||||
},
|
||||
saveDraft(conversationId, replyType) {
|
||||
if (this.message || this.message === '') {
|
||||
const key = `draft-${conversationId}-${replyType}`;
|
||||
const key = this.getDraftKey(conversationId, replyType);
|
||||
const draftToSave = trimContent(this.message || '');
|
||||
|
||||
this.$store.dispatch('draftMessages/set', {
|
||||
@@ -574,7 +609,7 @@ export default {
|
||||
},
|
||||
getFromDraft() {
|
||||
if (this.conversationIdByRoute) {
|
||||
const key = `draft-${this.conversationIdByRoute}-${this.replyType}`;
|
||||
const key = this.getDraftKey();
|
||||
const messageFromStore =
|
||||
this.$store.getters['draftMessages/get'](key) || '';
|
||||
|
||||
@@ -597,7 +632,7 @@ export default {
|
||||
},
|
||||
removeFromDraft() {
|
||||
if (this.conversationIdByRoute) {
|
||||
const key = `draft-${this.conversationIdByRoute}-${this.replyType}`;
|
||||
const key = this.getDraftKey();
|
||||
this.$store.dispatch('draftMessages/delete', { key });
|
||||
}
|
||||
},
|
||||
@@ -655,6 +690,9 @@ export default {
|
||||
// Don't handle paste if compose new conversation modal is open
|
||||
if (this.newConversationModalActive) return;
|
||||
|
||||
// Don't handle paste if editor is disabled
|
||||
if (this.isEditorDisabled) return;
|
||||
|
||||
// Filter valid files (non-zero size)
|
||||
Array.from(e.clipboardData.files)
|
||||
.filter(file => file.size > 0)
|
||||
@@ -708,6 +746,7 @@ export default {
|
||||
return;
|
||||
}
|
||||
if (!this.showMentions) {
|
||||
const copilotAcceptedMessage = this.getCopilotAcceptedMessage();
|
||||
const isOnWhatsApp =
|
||||
this.isATwilioWhatsAppChannel ||
|
||||
this.isAWhatsAppCloudChannel ||
|
||||
@@ -717,10 +756,17 @@ export default {
|
||||
// This can create duplicate messages in Chatwoot. To prevent this issue, we'll handle text and attachments as separate messages.
|
||||
const isOnInstagram = this.isAnInstagramChannel;
|
||||
if ((isOnWhatsApp || isOnInstagram) && !this.isPrivate) {
|
||||
this.sendMessageAsMultipleMessages(this.message);
|
||||
this.sendMessageAsMultipleMessages(
|
||||
this.message,
|
||||
copilotAcceptedMessage
|
||||
);
|
||||
} else {
|
||||
const messagePayload = this.getMessagePayload(this.message);
|
||||
this.sendMessage(messagePayload);
|
||||
this.sendMessage(
|
||||
messagePayload,
|
||||
this.message,
|
||||
copilotAcceptedMessage
|
||||
);
|
||||
}
|
||||
|
||||
if (!this.isPrivate) {
|
||||
@@ -732,13 +778,53 @@ export default {
|
||||
this.$emit('update:popOutReplyBox', false);
|
||||
}
|
||||
},
|
||||
sendMessageAsMultipleMessages(message) {
|
||||
sendMessageAsMultipleMessages(message, copilotAcceptedMessage = '') {
|
||||
const messages = this.getMultipleMessagesPayload(message);
|
||||
messages.forEach(messagePayload => {
|
||||
this.sendMessage(messagePayload);
|
||||
this.sendMessage(
|
||||
messagePayload,
|
||||
messagePayload.message || '',
|
||||
copilotAcceptedMessage
|
||||
);
|
||||
});
|
||||
},
|
||||
sendMessageAnalyticsData(isPrivate) {
|
||||
sendMessageAnalyticsData(
|
||||
isPrivate,
|
||||
{ editorMessage = '', copilotAcceptedMessage = '' } = {}
|
||||
) {
|
||||
const normalizeForComparison = message => {
|
||||
let normalizedMessage = message || '';
|
||||
|
||||
if (this.sendWithSignature && this.messageSignature && !isPrivate) {
|
||||
const effectiveChannelType = getEffectiveChannelType(
|
||||
this.channelType,
|
||||
this.inbox?.medium || ''
|
||||
);
|
||||
normalizedMessage = removeSignature(
|
||||
normalizedMessage,
|
||||
this.messageSignature,
|
||||
effectiveChannelType
|
||||
);
|
||||
}
|
||||
|
||||
return trimContent(normalizedMessage);
|
||||
};
|
||||
|
||||
const normalizedAcceptedMessage = normalizeForComparison(
|
||||
copilotAcceptedMessage
|
||||
);
|
||||
const normalizedEditorMessage = normalizeForComparison(editorMessage);
|
||||
|
||||
if (normalizedAcceptedMessage && normalizedEditorMessage) {
|
||||
useTrack(CAPTAIN_EVENTS.AI_ASSISTED_MESSAGE_SENT, {
|
||||
conversationId: this.conversationIdByRoute,
|
||||
channelType: this.channelType,
|
||||
editedBeforeSend:
|
||||
normalizedAcceptedMessage !== normalizedEditorMessage,
|
||||
isPrivate,
|
||||
});
|
||||
}
|
||||
|
||||
// Analytics data for message signature is enabled or not in channels
|
||||
return isPrivate
|
||||
? useTrack(CONVERSATION_EVENTS.SENT_PRIVATE_NOTE)
|
||||
@@ -772,7 +858,11 @@ export default {
|
||||
this.confirmOnSendReply();
|
||||
}
|
||||
},
|
||||
async sendMessage(messagePayload) {
|
||||
async sendMessage(
|
||||
messagePayload,
|
||||
editorMessage = '',
|
||||
copilotAcceptedMessage = ''
|
||||
) {
|
||||
try {
|
||||
await this.$store.dispatch(
|
||||
'createPendingMessageAndSend',
|
||||
@@ -781,7 +871,10 @@ export default {
|
||||
emitter.emit(BUS_EVENTS.SCROLL_TO_MESSAGE);
|
||||
emitter.emit(BUS_EVENTS.MESSAGE_SENT);
|
||||
this.removeFromDraft();
|
||||
this.sendMessageAnalyticsData(messagePayload.private);
|
||||
this.sendMessageAnalyticsData(messagePayload.private, {
|
||||
editorMessage,
|
||||
copilotAcceptedMessage,
|
||||
});
|
||||
} catch (error) {
|
||||
const errorMessage =
|
||||
error?.response?.data?.error || this.$t('CONVERSATION.MESSAGE_ERROR');
|
||||
@@ -855,6 +948,7 @@ export default {
|
||||
},
|
||||
clearMessage() {
|
||||
this.message = '';
|
||||
this.clearCopilotAcceptedMessage();
|
||||
if (this.sendWithSignature && !this.isPrivate) {
|
||||
// if signature is enabled, append it to the message
|
||||
const effectiveChannelType = getEffectiveChannelType(
|
||||
@@ -1119,7 +1213,9 @@ export default {
|
||||
this.$emit('update:popOutReplyBox', !this.popOutReplyBox);
|
||||
},
|
||||
onSubmitCopilotReply() {
|
||||
this.message = this.copilot.accept();
|
||||
const acceptedMessage = this.copilot.accept();
|
||||
this.message = acceptedMessage;
|
||||
this.setCopilotAcceptedMessage(acceptedMessage);
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1130,11 +1226,13 @@ export default {
|
||||
<div ref="replyEditor" class="reply-box" :class="replyBoxClass">
|
||||
<ReplyTopPanel
|
||||
:mode="replyType"
|
||||
:conversation-id="conversationId"
|
||||
:is-reply-restricted="isReplyRestricted"
|
||||
:disabled="
|
||||
(copilot.isActive.value && copilot.isButtonDisabled.value) ||
|
||||
showAudioRecorderEditor
|
||||
"
|
||||
:is-editor-disabled="isEditorDisabled"
|
||||
:is-message-length-reaching-threshold="isMessageLengthReachingThreshold"
|
||||
:characters-remaining="charactersRemaining"
|
||||
:popout-reply-box="popOutReplyBox"
|
||||
@@ -1204,12 +1302,14 @@ export default {
|
||||
<WootMessageEditor
|
||||
v-else-if="!showAudioRecorderEditor"
|
||||
v-model="message"
|
||||
:conversation-id="conversationId"
|
||||
:editor-id="editorStateId"
|
||||
class="input popover-prosemirror-menu"
|
||||
:is-private="isOnPrivateNote"
|
||||
:placeholder="messagePlaceHolder"
|
||||
:update-selection-with="updateEditorSelectionWith"
|
||||
:min-height="4"
|
||||
:disabled="isEditorDisabled"
|
||||
enable-variables
|
||||
:variables="messageVariables"
|
||||
:signature="messageSignature"
|
||||
@@ -1285,6 +1385,7 @@ export default {
|
||||
:is-recording-audio="isRecordingAudio"
|
||||
:is-send-disabled="isReplyButtonDisabled"
|
||||
:is-note="isPrivate"
|
||||
:is-editor-disabled="isEditorDisabled"
|
||||
:on-file-upload="onFileUpload"
|
||||
:on-send="onSendReply"
|
||||
:conversation-type="conversationType"
|
||||
|
||||
@@ -53,6 +53,10 @@ export default {
|
||||
type: String,
|
||||
default: null,
|
||||
},
|
||||
conversationLabels: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
conversationUrl: {
|
||||
type: String,
|
||||
default: '',
|
||||
@@ -70,6 +74,7 @@ export default {
|
||||
'assignAgent',
|
||||
'assignTeam',
|
||||
'assignLabel',
|
||||
'removeLabel',
|
||||
'deleteConversation',
|
||||
'close',
|
||||
],
|
||||
@@ -334,8 +339,16 @@ export default {
|
||||
v-for="label in labels"
|
||||
:key="label.id"
|
||||
:option="generateMenuLabelConfig(label, 'label')"
|
||||
variant="label"
|
||||
@click.stop="$emit('assignLabel', label)"
|
||||
:variant="
|
||||
conversationLabels.includes(label.title)
|
||||
? 'label-assigned'
|
||||
: 'label'
|
||||
"
|
||||
@click.stop="
|
||||
conversationLabels.includes(label.title)
|
||||
? $emit('removeLabel', label)
|
||||
: $emit('assignLabel', label)
|
||||
"
|
||||
/>
|
||||
</MenuItemWithSubmenu>
|
||||
<MenuItemWithSubmenu
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script setup>
|
||||
import Avatar from 'dashboard/components-next/avatar/Avatar.vue';
|
||||
import Icon from 'dashboard/components-next/icon/Icon.vue';
|
||||
|
||||
defineProps({
|
||||
option: {
|
||||
@@ -22,7 +23,9 @@ defineProps({
|
||||
class="flex-shrink-0"
|
||||
/>
|
||||
<span
|
||||
v-if="variant === 'label' && option.color"
|
||||
v-if="
|
||||
(variant === 'label' || variant === 'label-assigned') && option.color
|
||||
"
|
||||
class="label-pill flex-shrink-0"
|
||||
:style="{ backgroundColor: option.color }"
|
||||
/>
|
||||
@@ -37,6 +40,11 @@ defineProps({
|
||||
<p class="menu-label truncate min-w-0 flex-1">
|
||||
{{ option.label }}
|
||||
</p>
|
||||
<Icon
|
||||
v-if="variant === 'label-assigned'"
|
||||
icon="i-lucide-check"
|
||||
class="flex-shrink-0 size-3.5 mr-1"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
export const CAPTAIN_ERROR_TYPES = Object.freeze({
|
||||
ABORTED: 'aborted',
|
||||
API_ERROR: 'api_error',
|
||||
HTTP_PREFIX: 'http_',
|
||||
ABORT_ERROR: 'AbortError',
|
||||
CANCELED_ERROR: 'CanceledError',
|
||||
});
|
||||
|
||||
export const CAPTAIN_GENERATION_FAILURE_REASONS = Object.freeze({
|
||||
EMPTY_RESPONSE: 'empty_response',
|
||||
EXCEPTION: 'exception',
|
||||
});
|
||||
@@ -102,6 +102,28 @@ export function useBulkActions() {
|
||||
}
|
||||
}
|
||||
|
||||
// Only used in context menu
|
||||
async function onRemoveLabels(labelsToRemove, conversationId = null) {
|
||||
try {
|
||||
await store.dispatch('bulkActions/process', {
|
||||
type: 'Conversation',
|
||||
ids: conversationId || selectedConversations.value,
|
||||
labels: {
|
||||
remove: labelsToRemove,
|
||||
},
|
||||
});
|
||||
|
||||
useAlert(
|
||||
t('CONVERSATION.CARD_CONTEXT_MENU.API.LABEL_REMOVAL.SUCCESFUL', {
|
||||
labelName: labelsToRemove[0],
|
||||
conversationId,
|
||||
})
|
||||
);
|
||||
} catch (err) {
|
||||
useAlert(t('CONVERSATION.CARD_CONTEXT_MENU.API.LABEL_REMOVAL.FAILED'));
|
||||
}
|
||||
}
|
||||
|
||||
async function onAssignTeamsForBulk(team) {
|
||||
try {
|
||||
await store.dispatch('bulkActions/process', {
|
||||
@@ -189,6 +211,7 @@ export function useBulkActions() {
|
||||
isConversationSelected,
|
||||
onAssignAgent,
|
||||
onAssignLabels,
|
||||
onRemoveLabels,
|
||||
onAssignTeamsForBulk,
|
||||
onUpdateConversations,
|
||||
};
|
||||
|
||||
@@ -11,6 +11,7 @@ import { useAlert } from 'dashboard/composables';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { FEATURE_FLAGS } from 'dashboard/featureFlags';
|
||||
import TasksAPI from 'dashboard/api/captain/tasks';
|
||||
import { CAPTAIN_ERROR_TYPES } from 'dashboard/composables/captain/constants';
|
||||
|
||||
export function useCaptain() {
|
||||
const store = useStore();
|
||||
@@ -69,7 +70,10 @@ export function useCaptain() {
|
||||
* @param {Error} error - The error object from the API call.
|
||||
*/
|
||||
const handleAPIError = error => {
|
||||
if (error.name === 'AbortError' || error.name === 'CanceledError') {
|
||||
if (
|
||||
error.name === CAPTAIN_ERROR_TYPES.ABORT_ERROR ||
|
||||
error.name === CAPTAIN_ERROR_TYPES.CANCELED_ERROR
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const errorMessage =
|
||||
@@ -78,6 +82,24 @@ export function useCaptain() {
|
||||
useAlert(errorMessage);
|
||||
};
|
||||
|
||||
/**
|
||||
* Classifies API error types for downstream analytics.
|
||||
* @param {Error} error
|
||||
* @returns {string}
|
||||
*/
|
||||
const getErrorType = error => {
|
||||
if (
|
||||
error.name === CAPTAIN_ERROR_TYPES.ABORT_ERROR ||
|
||||
error.name === CAPTAIN_ERROR_TYPES.CANCELED_ERROR
|
||||
) {
|
||||
return CAPTAIN_ERROR_TYPES.ABORTED;
|
||||
}
|
||||
if (error.response?.status) {
|
||||
return `${CAPTAIN_ERROR_TYPES.HTTP_PREFIX}${error.response.status}`;
|
||||
}
|
||||
return CAPTAIN_ERROR_TYPES.API_ERROR;
|
||||
};
|
||||
|
||||
// === Task Methods ===
|
||||
/**
|
||||
* Rewrites content with a specific operation.
|
||||
@@ -103,7 +125,7 @@ export function useCaptain() {
|
||||
return { message: generatedMessage, followUpContext };
|
||||
} catch (error) {
|
||||
handleAPIError(error);
|
||||
return { message: '' };
|
||||
return { message: '', errorType: getErrorType(error) };
|
||||
}
|
||||
};
|
||||
|
||||
@@ -125,7 +147,7 @@ export function useCaptain() {
|
||||
return { message: generatedMessage, followUpContext };
|
||||
} catch (error) {
|
||||
handleAPIError(error);
|
||||
return { message: '' };
|
||||
return { message: '', errorType: getErrorType(error) };
|
||||
}
|
||||
};
|
||||
|
||||
@@ -147,7 +169,7 @@ export function useCaptain() {
|
||||
return { message: generatedMessage, followUpContext };
|
||||
} catch (error) {
|
||||
handleAPIError(error);
|
||||
return { message: '' };
|
||||
return { message: '', errorType: getErrorType(error) };
|
||||
}
|
||||
};
|
||||
|
||||
@@ -171,7 +193,11 @@ export function useCaptain() {
|
||||
return { message: generatedMessage, followUpContext: updatedContext };
|
||||
} catch (error) {
|
||||
handleAPIError(error);
|
||||
return { message: '', followUpContext };
|
||||
return {
|
||||
message: '',
|
||||
followUpContext,
|
||||
errorType: getErrorType(error),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -3,6 +3,10 @@ import { useCaptain } from 'dashboard/composables/useCaptain';
|
||||
import { useUISettings } from 'dashboard/composables/useUISettings';
|
||||
import { useTrack } from 'dashboard/composables';
|
||||
import { CAPTAIN_EVENTS } from 'dashboard/helper/AnalyticsHelper/events';
|
||||
import {
|
||||
CAPTAIN_ERROR_TYPES,
|
||||
CAPTAIN_GENERATION_FAILURE_REASONS,
|
||||
} from 'dashboard/composables/captain/constants';
|
||||
|
||||
// Actions that map to REWRITE events (with operation attribute)
|
||||
const REWRITE_ACTIONS = [
|
||||
@@ -52,6 +56,20 @@ function buildPayload(action, conversationId, followUpCount = undefined) {
|
||||
return payload;
|
||||
}
|
||||
|
||||
function trackGenerationFailure({
|
||||
action,
|
||||
conversationId,
|
||||
followUpCount = undefined,
|
||||
stage,
|
||||
reason,
|
||||
}) {
|
||||
useTrack(CAPTAIN_EVENTS.GENERATION_FAILED, {
|
||||
...buildPayload(action, conversationId, followUpCount),
|
||||
stage,
|
||||
reason,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Composable for managing Copilot reply generation state and actions.
|
||||
* Extracts copilot-related logic from ReplyBox for cleaner code organization.
|
||||
@@ -146,7 +164,8 @@ export function useCopilotReply() {
|
||||
|
||||
// Reset without tracking dismiss (starting new action)
|
||||
reset(false);
|
||||
abortController.value = new AbortController();
|
||||
const requestController = new AbortController();
|
||||
abortController.value = requestController;
|
||||
isGenerating.value = true;
|
||||
isContentReady.value = false;
|
||||
currentAction.value = action;
|
||||
@@ -154,28 +173,66 @@ export function useCopilotReply() {
|
||||
trackedConversationId.value = conversationId.value;
|
||||
|
||||
try {
|
||||
const { message: content, followUpContext: newContext } =
|
||||
await processEvent(action, data, {
|
||||
signal: abortController.value.signal,
|
||||
});
|
||||
const {
|
||||
message: content,
|
||||
followUpContext: newContext,
|
||||
errorType,
|
||||
} = await processEvent(action, data, {
|
||||
signal: requestController.signal,
|
||||
});
|
||||
|
||||
if (!abortController.value?.signal.aborted) {
|
||||
generatedContent.value = content;
|
||||
followUpContext.value = newContext;
|
||||
if (content) {
|
||||
showEditor.value = true;
|
||||
// Track "Used" event on successful generation
|
||||
const eventKey = `${getEventPrefix(action)}_USED`;
|
||||
useTrack(
|
||||
CAPTAIN_EVENTS[eventKey],
|
||||
buildPayload(action, trackedConversationId.value)
|
||||
);
|
||||
if (requestController.signal.aborted) return;
|
||||
if (errorType === CAPTAIN_ERROR_TYPES.ABORTED) {
|
||||
if (abortController.value === requestController) {
|
||||
isGenerating.value = false;
|
||||
}
|
||||
isGenerating.value = false;
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
if (!abortController.value?.signal.aborted) {
|
||||
isGenerating.value = false;
|
||||
|
||||
generatedContent.value = content;
|
||||
followUpContext.value = newContext;
|
||||
if (content) {
|
||||
showEditor.value = true;
|
||||
// Track "Used" event on successful generation
|
||||
const eventKey = `${getEventPrefix(action)}_USED`;
|
||||
useTrack(
|
||||
CAPTAIN_EVENTS[eventKey],
|
||||
buildPayload(action, trackedConversationId.value)
|
||||
);
|
||||
} else if (errorType && errorType !== CAPTAIN_ERROR_TYPES.ABORTED) {
|
||||
trackGenerationFailure({
|
||||
action,
|
||||
conversationId: trackedConversationId.value,
|
||||
stage: 'initial',
|
||||
reason: errorType,
|
||||
});
|
||||
} else {
|
||||
trackGenerationFailure({
|
||||
action,
|
||||
conversationId: trackedConversationId.value,
|
||||
stage: 'initial',
|
||||
reason: CAPTAIN_GENERATION_FAILURE_REASONS.EMPTY_RESPONSE,
|
||||
});
|
||||
}
|
||||
isGenerating.value = false;
|
||||
} catch (error) {
|
||||
if (
|
||||
requestController.signal.aborted ||
|
||||
error?.name === CAPTAIN_ERROR_TYPES.ABORT_ERROR ||
|
||||
error?.name === CAPTAIN_ERROR_TYPES.CANCELED_ERROR
|
||||
) {
|
||||
return;
|
||||
}
|
||||
trackGenerationFailure({
|
||||
action,
|
||||
conversationId: trackedConversationId.value,
|
||||
stage: 'initial',
|
||||
reason: error?.name || CAPTAIN_GENERATION_FAILURE_REASONS.EXCEPTION,
|
||||
});
|
||||
isGenerating.value = false;
|
||||
} finally {
|
||||
if (abortController.value === requestController) {
|
||||
abortController.value = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -187,7 +244,8 @@ export function useCopilotReply() {
|
||||
async function sendFollowUp(message) {
|
||||
if (!followUpContext.value || !message.trim()) return;
|
||||
|
||||
abortController.value = new AbortController();
|
||||
const requestController = new AbortController();
|
||||
abortController.value = requestController;
|
||||
isGenerating.value = true;
|
||||
isContentReady.value = false;
|
||||
|
||||
@@ -198,24 +256,65 @@ export function useCopilotReply() {
|
||||
followUpCount.value += 1;
|
||||
|
||||
try {
|
||||
const { message: content, followUpContext: updatedContext } =
|
||||
await followUp({
|
||||
followUpContext: followUpContext.value,
|
||||
message,
|
||||
signal: abortController.value.signal,
|
||||
});
|
||||
const {
|
||||
message: content,
|
||||
followUpContext: updatedContext,
|
||||
errorType,
|
||||
} = await followUp({
|
||||
followUpContext: followUpContext.value,
|
||||
message,
|
||||
signal: requestController.signal,
|
||||
});
|
||||
|
||||
if (!abortController.value?.signal.aborted) {
|
||||
if (content) {
|
||||
generatedContent.value = content;
|
||||
followUpContext.value = updatedContext;
|
||||
showEditor.value = true;
|
||||
if (requestController.signal.aborted) return;
|
||||
if (errorType === CAPTAIN_ERROR_TYPES.ABORTED) {
|
||||
if (abortController.value === requestController) {
|
||||
isGenerating.value = false;
|
||||
}
|
||||
isGenerating.value = false;
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
if (!abortController.value?.signal.aborted) {
|
||||
isGenerating.value = false;
|
||||
|
||||
if (content) {
|
||||
generatedContent.value = content;
|
||||
followUpContext.value = updatedContext;
|
||||
showEditor.value = true;
|
||||
} else if (errorType && errorType !== CAPTAIN_ERROR_TYPES.ABORTED) {
|
||||
trackGenerationFailure({
|
||||
action: currentAction.value,
|
||||
conversationId: trackedConversationId.value,
|
||||
followUpCount: followUpCount.value,
|
||||
stage: 'follow_up',
|
||||
reason: errorType,
|
||||
});
|
||||
} else {
|
||||
trackGenerationFailure({
|
||||
action: currentAction.value,
|
||||
conversationId: trackedConversationId.value,
|
||||
followUpCount: followUpCount.value,
|
||||
stage: 'follow_up',
|
||||
reason: CAPTAIN_GENERATION_FAILURE_REASONS.EMPTY_RESPONSE,
|
||||
});
|
||||
}
|
||||
isGenerating.value = false;
|
||||
} catch (error) {
|
||||
if (
|
||||
requestController.signal.aborted ||
|
||||
error?.name === CAPTAIN_ERROR_TYPES.ABORT_ERROR ||
|
||||
error?.name === CAPTAIN_ERROR_TYPES.CANCELED_ERROR
|
||||
) {
|
||||
return;
|
||||
}
|
||||
trackGenerationFailure({
|
||||
action: currentAction.value,
|
||||
conversationId: trackedConversationId.value,
|
||||
followUpCount: followUpCount.value,
|
||||
stage: 'follow_up',
|
||||
reason: error?.name || CAPTAIN_GENERATION_FAILURE_REASONS.EXCEPTION,
|
||||
});
|
||||
isGenerating.value = false;
|
||||
} finally {
|
||||
if (abortController.value === requestController) {
|
||||
abortController.value = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,6 +85,11 @@ export const PORTALS_EVENTS = Object.freeze({
|
||||
});
|
||||
|
||||
export const CAPTAIN_EVENTS = Object.freeze({
|
||||
// Editor funnel events
|
||||
EDITOR_AI_MENU_OPENED: 'Captain: Editor AI menu opened',
|
||||
GENERATION_FAILED: 'Captain: Generation failed',
|
||||
AI_ASSISTED_MESSAGE_SENT: 'Captain: AI-assisted message sent',
|
||||
|
||||
// Rewrite events (with operation attribute in payload)
|
||||
REWRITE_USED: 'Captain: Rewrite used',
|
||||
REWRITE_APPLIED: 'Captain: Rewrite applied',
|
||||
|
||||
@@ -174,6 +174,10 @@
|
||||
"SUCCESFUL": "Assigned label #{labelName} to conversation id {conversationId}",
|
||||
"FAILED": "Couldn't assign label. Please try again."
|
||||
},
|
||||
"LABEL_REMOVAL": {
|
||||
"SUCCESFUL": "Removed label #{labelName} from conversation id {conversationId}",
|
||||
"FAILED": "Couldn't remove label. Please try again."
|
||||
},
|
||||
"TEAM_ASSIGNMENT": {
|
||||
"SUCCESFUL": "Assigned team \"{team}\" to conversation id {conversationId}",
|
||||
"FAILED": "Couldn't assign team. Please try again."
|
||||
@@ -186,6 +190,8 @@
|
||||
"DISABLE_SIGN_TOOLTIP": "Disable signature",
|
||||
"MSG_INPUT": "Shift + enter for new line. Start with '/' to select a Canned Response.",
|
||||
"PRIVATE_MSG_INPUT": "Shift + enter for new line. This will be visible only to Agents",
|
||||
"MESSAGING_RESTRICTED": "You cannot reply to this conversation",
|
||||
"MESSAGING_RESTRICTED_WHATSAPP": "You can only reply using a template message due to 24-hour message window restriction",
|
||||
"MESSAGE_SIGNATURE_NOT_CONFIGURED": "Message signature is not configured, please configure it in profile settings.",
|
||||
"COPILOT_MSG_INPUT": "Give copilot additional prompts, or ask anything else... Press enter to send follow-up",
|
||||
"CLICK_HERE": "Click here to update",
|
||||
|
||||
Reference in New Issue
Block a user