* feat: Adds model for scheduling messages * feat: Implement scheduled message handling and processing jobs * feat: Add ScheduledMessagesController and associated specs for managing scheduled messages * refactor: Simplify scheduled message job specs and improve metadata handling * feat: Add ScheduledMessagePolicy for managing access to scheduled messages * feat: Add routes for managing scheduled messages * feat: Add scheduled message event handling and broadcasting * feat: Add JSON views for scheduled messages creation, destruction, updating, and indexing * feat: Update scheduled message status and dispatch update event after message creation * feat: Ensure scheduled message updates trigger dispatch event * feat: Add mutation types for managing scheduled messages * feat: Add additionalAttributes prop to Message component and provider * feat: Implement scheduled message handling in ActionCable and Vuex store * feat: Add unit tests for scheduled messages actions and mutations * feat: implement scheduled messages functionality - Added support for scheduling messages in the conversation dashboard. - Introduced new components: ScheduledMessageModal and ScheduledMessages for managing scheduled messages. - Enhanced ReplyBottomPanel to include scheduling options. - Updated Base.vue to handle scheduled message styling. - Integrated Vuex store module for managing scheduled messages state. - Added necessary translations for scheduled messages in English and Portuguese. * feat: add pagination to scheduled messages index and update tests accordingly * chore: update scheduled messages specs for future time validation and response status * chore: enhance scheduled messages API with pagination and add skeleton loader component * feat: add create_scheduled_message action to automation rule attributes * feat: implement create_scheduled_message action and enhance attachment handling * feat: add scheduled message functionality with UI components and localization * test: enhance scheduledMessages mutations tests with meta handling and structure * chore: update label to display file name upon successful upload in AutomationFileInput component * feat: add initialAttachment prop to ScheduledMessageModal and update ReplyBox to pass attachment * chore: prepend_mod_with to ScheduledMessagesController for better module handling * fix: attachment visibility in ScheduledMessageItem component * chore: enhance ScheduledMessage model with validations and reduce controller load * refactor: simplify ScheduledMessagesAPI methods by removing unnecessary instance variable * chore: update event emission for scheduled message creation in ReplyBox and ScheduledMessageModal * refactor: update status configuration to use label keys * chore: update date formatting in ScheduledMessageItem component * refactor: collapse logic to checkOverflow and update related functionality * chore: add author indication for current user in scheduled messages * chore: enhance scheduled message metadata with author information and localization * fix: send message shortcut * chore: handle errors in scheduled message submission * chore: update scheduled message modal to use combined date and time input * chore: refactor scheduled messages handling to remove pagination and update related tests * fix: ensure scheduled messages update status and dispatch on failure * fix: update scheduled message due date logic and simplify sending checks * refactor: rename build_message method for send_message * fix: update scheduled message creation time and improve test reliability * chore: ignore unnecessary check * chore: add scheduled message metadata handling in message builder, add scheduled message factorie and update specs * refactor: use scheduled message factorie creation in specs * chore: streamline error handling in scheduled message job and remove dispatch logic * fix: change scheduled_messages association to destroy dependent records * refactor: remove unused attributes from scheduled message payload builder * chore: update scheduled message retrieval to use conversation association * chore: correct cron format for scheduled messages job * chore: remove migration for author_type in scheduled_messages * feat: enhance scheduled messages management with delete confirmation and error handling * chore: set cron poll interval to 10 seconds for improved scheduling precision * feat: include additional_attributes in message JSON response * feat: enhance scheduled message validation and localization support * chore: update scheduled message display * Merge branch 'main' into Cayo-Oliveira/CU-86aenh268/Mensagens-agendadas * feat: add scheduled message indicators and validation for message length * fix: remove unnecessary condition from line-clamp class binding * feat: update scheduled messages localization and enhance content validation * feat: update scheduled messages order, enhance scheduledAt computation, and add message association * fix: reorder condition for Facebook channel message length computation * fix: change detection for attachments in scheduled messages * fix: remove unnecessary colon from close-on-backdrop-click prop in ScheduledMessageModal * chore: add error handling for scheduled message deletion and update localization for delete failure * fix: enforce minimum delay of 1 minute for scheduled messages and update validation * fix: remove unused private property and improve locale formatting for scheduled messages * fix: adjust positioning of DropdownBody in ReplyBottomPanel and clean up schema foreign keys * docs: add scheduled messages management APIs and payload definitions --------- Co-authored-by: gabrieljablonski <contact@gabrieljablonski.com>
490 lines
13 KiB
Vue
490 lines
13 KiB
Vue
<script>
|
|
import { ref } from 'vue';
|
|
import { useUISettings } from 'dashboard/composables/useUISettings';
|
|
import { useKeyboardEvents } from 'dashboard/composables/useKeyboardEvents';
|
|
import FileUpload from 'vue-upload-component';
|
|
import * as ActiveStorage from 'activestorage';
|
|
import inboxMixin from 'shared/mixins/inboxMixin';
|
|
import { FEATURE_FLAGS } from 'dashboard/featureFlags';
|
|
import { getAllowedFileTypesByChannel } from '@chatwoot/utils';
|
|
import { ALLOWED_FILE_TYPES } from 'shared/constants/messages';
|
|
import VideoCallButton from '../VideoCallButton.vue';
|
|
import AIAssistanceButton from '../AIAssistanceButton.vue';
|
|
import { INBOX_TYPES } from 'dashboard/helper/inbox';
|
|
import { mapGetters } from 'vuex';
|
|
import NextButton from 'dashboard/components-next/button/Button.vue';
|
|
import DropdownContainer from 'next/dropdown-menu/base/DropdownContainer.vue';
|
|
import DropdownBody from 'next/dropdown-menu/base/DropdownBody.vue';
|
|
import DropdownSection from 'next/dropdown-menu/base/DropdownSection.vue';
|
|
import DropdownItem from 'next/dropdown-menu/base/DropdownItem.vue';
|
|
|
|
export default {
|
|
name: 'ReplyBottomPanel',
|
|
components: {
|
|
NextButton,
|
|
FileUpload,
|
|
VideoCallButton,
|
|
AIAssistanceButton,
|
|
DropdownContainer,
|
|
DropdownBody,
|
|
DropdownSection,
|
|
DropdownItem,
|
|
},
|
|
mixins: [inboxMixin],
|
|
props: {
|
|
isNote: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
onSend: {
|
|
type: Function,
|
|
default: () => {},
|
|
},
|
|
sendButtonText: {
|
|
type: String,
|
|
default: '',
|
|
},
|
|
recordingAudioDurationText: {
|
|
type: String,
|
|
default: '00:00',
|
|
},
|
|
// inbox prop is used in /mixins/inboxMixin,
|
|
// remove this props when refactoring to composable if not needed
|
|
// eslint-disable-next-line vue/no-unused-properties
|
|
inbox: {
|
|
type: Object,
|
|
default: () => ({}),
|
|
},
|
|
showFileUpload: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
showAudioRecorder: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
onFileUpload: {
|
|
type: Function,
|
|
default: () => {},
|
|
},
|
|
toggleEmojiPicker: {
|
|
type: Function,
|
|
default: () => {},
|
|
},
|
|
toggleAudioRecorder: {
|
|
type: Function,
|
|
default: () => {},
|
|
},
|
|
toggleAudioRecorderPlayPause: {
|
|
type: Function,
|
|
default: () => {},
|
|
},
|
|
isRecordingAudio: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
recordingAudioState: {
|
|
type: String,
|
|
default: '',
|
|
},
|
|
isSendDisabled: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
isOnPrivateNote: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
enableMultipleFileUpload: {
|
|
type: Boolean,
|
|
default: true,
|
|
},
|
|
enableWhatsAppTemplates: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
enableContentTemplates: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
conversationId: {
|
|
type: Number,
|
|
required: true,
|
|
},
|
|
message: {
|
|
type: String,
|
|
default: '',
|
|
},
|
|
newConversationModalActive: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
portalSlug: {
|
|
type: String,
|
|
required: true,
|
|
},
|
|
conversationType: {
|
|
type: String,
|
|
default: '',
|
|
},
|
|
showQuotedReplyToggle: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
quotedReplyEnabled: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
showScheduleOptions: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
},
|
|
emits: [
|
|
'replaceText',
|
|
'toggleInsertArticle',
|
|
'selectWhatsappTemplate',
|
|
'selectContentTemplate',
|
|
'toggleQuotedReply',
|
|
'scheduleMessage',
|
|
],
|
|
setup() {
|
|
const { setSignatureFlagForInbox, fetchSignatureFlagFromUISettings } =
|
|
useUISettings();
|
|
|
|
const uploadRef = ref(false);
|
|
|
|
const keyboardEvents = {
|
|
'$mod+Alt+KeyA': {
|
|
action: () => {
|
|
// 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.
|
|
|
|
const uploadTriggerButton = document.querySelector(
|
|
'#conversationAttachment'
|
|
);
|
|
uploadTriggerButton.click();
|
|
},
|
|
allowOnFocusedInput: true,
|
|
},
|
|
};
|
|
|
|
useKeyboardEvents(keyboardEvents);
|
|
|
|
return {
|
|
setSignatureFlagForInbox,
|
|
fetchSignatureFlagFromUISettings,
|
|
uploadRef,
|
|
};
|
|
},
|
|
data() {
|
|
return {
|
|
ALLOWED_FILE_TYPES,
|
|
};
|
|
},
|
|
computed: {
|
|
...mapGetters({
|
|
accountId: 'getCurrentAccountId',
|
|
isFeatureEnabledonAccount: 'accounts/isFeatureEnabledonAccount',
|
|
uiFlags: 'integrations/getUIFlags',
|
|
}),
|
|
wrapClass() {
|
|
return {
|
|
'is-note-mode': this.isNote,
|
|
};
|
|
},
|
|
showAttachButton() {
|
|
return this.showFileUpload || this.isNote;
|
|
},
|
|
showAudioRecorderButton() {
|
|
if (this.isALineChannel) {
|
|
return false;
|
|
}
|
|
// Disable audio recorder for safari browser as recording is not supported
|
|
// const isSafari = /^((?!chrome|android|crios|fxios).)*safari/i.test(
|
|
// navigator.userAgent
|
|
// );
|
|
|
|
return (
|
|
this.isFeatureEnabledonAccount(
|
|
this.accountId,
|
|
FEATURE_FLAGS.VOICE_RECORDER
|
|
) && this.showAudioRecorder
|
|
// !isSafari
|
|
);
|
|
},
|
|
showAudioPlayStopButton() {
|
|
return this.showAudioRecorder && this.isRecordingAudio;
|
|
},
|
|
isInstagramDM() {
|
|
return this.conversationType === 'instagram_direct_message';
|
|
},
|
|
allowedFileTypes() {
|
|
// Use default file types for private notes
|
|
if (this.isOnPrivateNote) {
|
|
return this.ALLOWED_FILE_TYPES;
|
|
}
|
|
|
|
let channelType = this.channelType || this.inbox?.channel_type;
|
|
|
|
if (this.isAnInstagramChannel || this.isInstagramDM) {
|
|
channelType = INBOX_TYPES.INSTAGRAM;
|
|
}
|
|
|
|
return getAllowedFileTypesByChannel({
|
|
channelType,
|
|
medium: this.inbox?.medium,
|
|
});
|
|
},
|
|
enableDragAndDrop() {
|
|
return !this.newConversationModalActive;
|
|
},
|
|
audioRecorderPlayStopIcon() {
|
|
switch (this.recordingAudioState) {
|
|
// playing paused recording stopped inactive destroyed
|
|
case 'playing':
|
|
return 'i-ph-pause';
|
|
case 'paused':
|
|
return 'i-ph-play';
|
|
case 'stopped':
|
|
return 'i-ph-play';
|
|
default:
|
|
return 'i-ph-stop';
|
|
}
|
|
},
|
|
showMessageSignatureButton() {
|
|
return !this.isOnPrivateNote;
|
|
},
|
|
sendWithSignature() {
|
|
// channelType is sourced from inboxMixin
|
|
return this.fetchSignatureFlagFromUISettings(this.channelType);
|
|
},
|
|
signatureToggleTooltip() {
|
|
return this.sendWithSignature
|
|
? this.$t('CONVERSATION.FOOTER.DISABLE_SIGN_TOOLTIP')
|
|
: this.$t('CONVERSATION.FOOTER.ENABLE_SIGN_TOOLTIP');
|
|
},
|
|
enableInsertArticleInReply() {
|
|
return this.portalSlug;
|
|
},
|
|
isFetchingAppIntegrations() {
|
|
return this.uiFlags.isFetching;
|
|
},
|
|
quotedReplyToggleTooltip() {
|
|
return this.quotedReplyEnabled
|
|
? this.$t('CONVERSATION.REPLYBOX.QUOTED_REPLY.DISABLE_TOOLTIP')
|
|
: this.$t('CONVERSATION.REPLYBOX.QUOTED_REPLY.ENABLE_TOOLTIP');
|
|
},
|
|
},
|
|
mounted() {
|
|
ActiveStorage.start();
|
|
},
|
|
methods: {
|
|
toggleMessageSignature() {
|
|
this.setSignatureFlagForInbox(this.channelType, !this.sendWithSignature);
|
|
},
|
|
replaceText(text) {
|
|
this.$emit('replaceText', text);
|
|
},
|
|
toggleInsertArticle() {
|
|
this.$emit('toggleInsertArticle');
|
|
},
|
|
openScheduleModal() {
|
|
this.$emit('scheduleMessage');
|
|
},
|
|
},
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<div class="flex justify-between p-3" :class="wrapClass">
|
|
<div class="left-wrap">
|
|
<NextButton
|
|
v-tooltip.top-end="$t('CONVERSATION.REPLYBOX.TIP_EMOJI_ICON')"
|
|
icon="i-ph-smiley-sticker"
|
|
slate
|
|
faded
|
|
sm
|
|
@click="toggleEmojiPicker"
|
|
/>
|
|
<FileUpload
|
|
ref="uploadRef"
|
|
v-tooltip.top-end="$t('CONVERSATION.REPLYBOX.TIP_ATTACH_ICON')"
|
|
input-id="conversationAttachment"
|
|
:size="4096 * 4096"
|
|
:accept="allowedFileTypes"
|
|
:multiple="enableMultipleFileUpload"
|
|
:drop="enableDragAndDrop"
|
|
:drop-directory="false"
|
|
:data="{
|
|
direct_upload_url: '/rails/active_storage/direct_uploads',
|
|
direct_upload: true,
|
|
}"
|
|
@input-file="onFileUpload"
|
|
>
|
|
<NextButton
|
|
v-if="showAttachButton"
|
|
v-tooltip.top-end="$t('CONVERSATION.REPLYBOX.TIP_ATTACH_ICON')"
|
|
icon="i-ph-paperclip"
|
|
slate
|
|
faded
|
|
sm
|
|
/>
|
|
</FileUpload>
|
|
<NextButton
|
|
v-if="showAudioRecorderButton"
|
|
v-tooltip.top-end="$t('CONVERSATION.REPLYBOX.TIP_AUDIORECORDER_ICON')"
|
|
:icon="!isRecordingAudio ? 'i-ph-microphone' : 'i-ph-microphone-slash'"
|
|
slate
|
|
faded
|
|
sm
|
|
@click="toggleAudioRecorder"
|
|
/>
|
|
<NextButton
|
|
v-if="showAudioPlayStopButton"
|
|
:icon="audioRecorderPlayStopIcon"
|
|
slate
|
|
faded
|
|
sm
|
|
:label="recordingAudioDurationText"
|
|
@click="toggleAudioRecorderPlayPause"
|
|
/>
|
|
<NextButton
|
|
v-if="showMessageSignatureButton"
|
|
v-tooltip.top-end="signatureToggleTooltip"
|
|
icon="i-ph-signature"
|
|
:color="sendWithSignature ? 'blue' : 'slate'"
|
|
faded
|
|
sm
|
|
@click="toggleMessageSignature"
|
|
/>
|
|
<NextButton
|
|
v-if="showQuotedReplyToggle"
|
|
v-tooltip.top-end="quotedReplyToggleTooltip"
|
|
icon="i-ph-quotes"
|
|
:variant="quotedReplyEnabled ? 'solid' : 'faded'"
|
|
color="slate"
|
|
sm
|
|
:aria-pressed="quotedReplyEnabled"
|
|
@click="$emit('toggleQuotedReply')"
|
|
/>
|
|
<NextButton
|
|
v-if="enableWhatsAppTemplates"
|
|
v-tooltip.top-end="$t('CONVERSATION.FOOTER.WHATSAPP_TEMPLATES')"
|
|
icon="i-ph-whatsapp-logo"
|
|
slate
|
|
faded
|
|
sm
|
|
@click="$emit('selectWhatsappTemplate')"
|
|
/>
|
|
<NextButton
|
|
v-if="enableContentTemplates"
|
|
v-tooltip.top-end="'Content Templates'"
|
|
icon="i-ph-whatsapp-logo"
|
|
slate
|
|
faded
|
|
sm
|
|
@click="$emit('selectContentTemplate')"
|
|
/>
|
|
<VideoCallButton
|
|
v-if="(isAWebWidgetInbox || isAPIInbox) && !isOnPrivateNote"
|
|
:conversation-id="conversationId"
|
|
/>
|
|
<AIAssistanceButton
|
|
v-if="!isFetchingAppIntegrations"
|
|
:conversation-id="conversationId"
|
|
:is-private-note="isOnPrivateNote"
|
|
:message="message"
|
|
@replace-text="replaceText"
|
|
/>
|
|
<transition name="modal-fade">
|
|
<div
|
|
v-show="uploadRef && uploadRef.dropActive"
|
|
class="flex fixed top-0 right-0 bottom-0 left-0 z-20 flex-col gap-2 justify-center items-center w-full h-full text-n-slate-12 bg-modal-backdrop-light dark:bg-modal-backdrop-dark"
|
|
>
|
|
<fluent-icon icon="cloud-backup" size="40" />
|
|
<h4 class="text-2xl break-words text-n-slate-12">
|
|
{{ $t('CONVERSATION.REPLYBOX.DRAG_DROP') }}
|
|
</h4>
|
|
</div>
|
|
</transition>
|
|
<NextButton
|
|
v-if="enableInsertArticleInReply"
|
|
v-tooltip.top-end="$t('HELP_CENTER.ARTICLE_SEARCH.OPEN_ARTICLE_SEARCH')"
|
|
icon="i-ph-article-ny-times"
|
|
slate
|
|
faded
|
|
sm
|
|
@click="toggleInsertArticle"
|
|
/>
|
|
</div>
|
|
<div class="right-wrap">
|
|
<div v-if="showScheduleOptions && !isNote" class="flex">
|
|
<NextButton
|
|
:label="sendButtonText"
|
|
type="submit"
|
|
sm
|
|
blue
|
|
:disabled="isSendDisabled"
|
|
class="flex-shrink-0 !rounded-r-none"
|
|
@click="onSend"
|
|
/>
|
|
<DropdownContainer>
|
|
<template #trigger="{ toggle, isOpen }">
|
|
<NextButton
|
|
type="button"
|
|
sm
|
|
blue
|
|
icon="i-lucide-chevron-down"
|
|
:disabled="isSendDisabled"
|
|
class="flex-shrink-0 !rounded-l-none !border-l border-l-white/20 !px-1.5"
|
|
:class="{ 'bg-n-blue-11': isOpen }"
|
|
@click="toggle"
|
|
/>
|
|
</template>
|
|
<DropdownBody class="bottom-11 -right-8 min-w-48 z-50" strong>
|
|
<DropdownSection>
|
|
<DropdownItem
|
|
icon="i-lucide-clock"
|
|
:label="$t('CONVERSATION.REPLYBOX.SCHEDULE_SEND')"
|
|
:click="openScheduleModal"
|
|
/>
|
|
</DropdownSection>
|
|
</DropdownBody>
|
|
</DropdownContainer>
|
|
</div>
|
|
<NextButton
|
|
v-else
|
|
:label="sendButtonText"
|
|
type="submit"
|
|
sm
|
|
:color="isNote ? 'amber' : 'blue'"
|
|
:disabled="isSendDisabled"
|
|
class="flex-shrink-0"
|
|
@click="onSend"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<style lang="scss" scoped>
|
|
.left-wrap {
|
|
@apply items-center flex gap-2;
|
|
}
|
|
|
|
.right-wrap {
|
|
@apply flex;
|
|
}
|
|
|
|
::v-deep .file-uploads {
|
|
label {
|
|
@apply cursor-pointer;
|
|
}
|
|
|
|
&:hover button {
|
|
@apply enabled:bg-n-slate-9/20;
|
|
}
|
|
}
|
|
</style>
|