* 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>
141 lines
7.6 KiB
JavaScript
141 lines
7.6 KiB
JavaScript
import { inject, provide, computed } from 'vue';
|
|
import { useMapGetter } from 'dashboard/composables/store';
|
|
import { useSnakeCase } from 'dashboard/composables/useTransformKeys';
|
|
import { ATTACHMENT_TYPES } from './constants';
|
|
|
|
const MessageControl = Symbol('MessageControl');
|
|
|
|
/**
|
|
* @typedef {Object} Attachment
|
|
* @property {number} id - Unique identifier for the attachment
|
|
* @property {number} messageId - ID of the associated message
|
|
* @property {'image'|'audio'|'video'|'file'|'location'|'fallback'|'share'|'story_mention'|'contact'|'ig_reel'} fileType - Type of the attachment (file or image)
|
|
* @property {number} accountId - ID of the associated account
|
|
* @property {string|null} extension - File extension
|
|
* @property {string} dataUrl - URL to access the full attachment data
|
|
* @property {string} thumbUrl - URL to access the thumbnail version
|
|
* @property {number} fileSize - Size of the file in bytes
|
|
* @property {number|null} width - Width of the image if applicable
|
|
* @property {number|null} height - Height of the image if applicable
|
|
*/
|
|
|
|
/**
|
|
* @typedef {Object} Sender
|
|
* @property {Object} additional_attributes - Additional attributes of the sender
|
|
* @property {Object} custom_attributes - Custom attributes of the sender
|
|
* @property {string} email - Email of the sender
|
|
* @property {number} id - ID of the sender
|
|
* @property {string|null} identifier - Identifier of the sender
|
|
* @property {string} name - Name of the sender
|
|
* @property {string|null} phone_number - Phone number of the sender
|
|
* @property {string} thumbnail - Thumbnail URL of the sender
|
|
* @property {string} type - Type of sender
|
|
*/
|
|
|
|
/**
|
|
* @typedef {Object} EmailContent
|
|
* @property {string[]|null} bcc - BCC recipients
|
|
* @property {string[]|null} cc - CC recipients
|
|
* @property {string} contentType - Content type of the email
|
|
* @property {string} date - Date the email was sent
|
|
* @property {string[]} from - From email address
|
|
* @property {Object} htmlContent - HTML content of the email
|
|
* @property {string} htmlContent.full - Full HTML content
|
|
* @property {string} htmlContent.reply - Reply HTML content
|
|
* @property {string} htmlContent.quoted - Quoted HTML content
|
|
* @property {string|null} inReplyTo - Message ID being replied to
|
|
* @property {string} messageId - Unique message identifier
|
|
* @property {boolean} multipart - Whether the email is multipart
|
|
* @property {number} numberOfAttachments - Number of attachments
|
|
* @property {string} subject - Email subject line
|
|
* @property {Object} textContent - Text content of the email
|
|
* @property {string} textContent.full - Full text content
|
|
* @property {string} textContent.reply - Reply text content
|
|
* @property {string} textContent.quoted - Quoted text content
|
|
* @property {string[]} to - To email addresses
|
|
*/
|
|
|
|
/**
|
|
* @typedef {Object} ContentAttributes
|
|
* @property {string} externalError - an error message to be shown if the message failed to send
|
|
* @property {Object} [data] - Optional data object containing roomName and messageId
|
|
* @property {string} data.roomName - Name of the room
|
|
* @property {string} data.messageId - ID of the message
|
|
* @property {'story_mention'} [imageType] - Flag to indicate this is a story mention
|
|
* @property {'dyte'} [type] - Flag to indicate this is a dyte call
|
|
* @property {EmailContent} [email] - Email content and metadata
|
|
* @property {string|null} [ccEmail] - CC email addresses
|
|
* @property {string|null} [bccEmail] - BCC email addresses
|
|
*/
|
|
|
|
/**
|
|
* @typedef {'sent'|'delivered'|'read'|'failed'|'progress'} MessageStatus
|
|
* @typedef {'text'|'input_text'|'input_textarea'|'input_email'|'input_select'|'cards'|'form'|'article'|'incoming_email'|'input_csat'|'integrations'|'sticker'} MessageContentType
|
|
* @typedef {0|1|2|3} MessageType
|
|
* @typedef {'contact'|'user'|'Contact'|'User'} SenderType
|
|
* @typedef {'user'|'agent'|'activity'|'private'|'bot'|'error'|'template'|'email'|'unsupported'} MessageVariant
|
|
* @typedef {'left'|'center'|'right'} MessageOrientation
|
|
|
|
* @typedef {Object} MessageContext
|
|
* @property {import('vue').Ref<string>} content - The message content
|
|
* @property {import('vue').Ref<number>} conversationId - The ID of the conversation to which the message belongs
|
|
* @property {import('vue').Ref<number>} createdAt - Timestamp when the message was created
|
|
* @property {import('vue').Ref<number>} currentUserId - The ID of the current user
|
|
* @property {import('vue').Ref<number>} id - The unique identifier for the message
|
|
* @property {import('vue').Ref<number>} inboxId - The ID of the inbox to which the message belongs
|
|
* @property {import('vue').Ref<boolean>} [groupWithNext=false] - Whether the message should be grouped with the next message
|
|
* @property {import('vue').Ref<boolean>} [isEmailInbox=false] - Whether the message is from an email inbox
|
|
* @property {import('vue').Ref<boolean>} [private=false] - Whether the message is private
|
|
* @property {import('vue').Ref<number|null>} [senderId=null] - The ID of the sender
|
|
* @property {import('vue').Ref<string|null>} [error=null] - Error message if the message failed to send
|
|
* @property {import('vue').Ref<Attachment[]>} [attachments=[]] - The attachments associated with the message
|
|
* @property {import('vue').Ref<ContentAttributes>} [contentAttributes={}] - Additional attributes of the message content
|
|
* @property {import('vue').Ref<MessageContentType>} contentType - Content type of the message
|
|
* @property {import('vue').Ref<MessageStatus>} status - The delivery status of the message
|
|
* @property {import('vue').Ref<MessageType>} messageType - The type of message (must be one of MESSAGE_TYPES)
|
|
* @property {import('vue').Ref<Object|null>} [inReplyTo=null] - The message to which this message is a reply
|
|
* @property {import('vue').Ref<SenderType>} [senderType=null] - The type of the sender
|
|
* @property {import('vue').Ref<Sender|null>} [sender=null] - The sender information
|
|
* @property {import('vue').Ref<Object>} [additionalAttributes={}] - Additional attributes of the message
|
|
* @property {import('vue').ComputedRef<MessageOrientation>} orientation - The visual variant of the message
|
|
* @property {import('vue').ComputedRef<MessageVariant>} variant - The visual variant of the message
|
|
* @property {import('vue').ComputedRef<boolean>} isBotOrAgentMessage - Does the message belong to the current user
|
|
* @property {import('vue').ComputedRef<boolean>} isPrivate - Proxy computed value for private
|
|
* @property {import('vue').ComputedRef<boolean>} shouldGroupWithNext - Should group with the next message or not, it is differnt from groupWithNext, this has a bypass for a failed message
|
|
*/
|
|
|
|
/**
|
|
* Retrieves the message context from the parent Message component.
|
|
* Must be used within a component that is a child of a Message component.
|
|
*
|
|
* @returns {MessageContext & { filteredCurrentChatAttachments: import('vue').ComputedRef<Attachment[]> }}
|
|
* Message context object containing message properties and computed values
|
|
* @throws {Error} If used outside of a Message component context
|
|
*/
|
|
export function useMessageContext() {
|
|
const context = inject(MessageControl, null);
|
|
if (context === null) {
|
|
throw new Error(`Component is missing a parent <Message /> component.`);
|
|
}
|
|
|
|
const currentChatAttachments = useMapGetter('getSelectedChatAttachments');
|
|
const filteredCurrentChatAttachments = computed(() => {
|
|
const attachments = currentChatAttachments.value.filter(attachment =>
|
|
[
|
|
ATTACHMENT_TYPES.IMAGE,
|
|
ATTACHMENT_TYPES.VIDEO,
|
|
ATTACHMENT_TYPES.IG_REEL,
|
|
ATTACHMENT_TYPES.AUDIO,
|
|
].includes(attachment.file_type)
|
|
);
|
|
|
|
return useSnakeCase(attachments);
|
|
});
|
|
|
|
return { ...context, filteredCurrentChatAttachments };
|
|
}
|
|
|
|
export function provideMessageContext(context) {
|
|
provide(MessageControl, context);
|
|
}
|