chore: Audit message characters across all channels (#11343)

- Audited message characters across all channels.
- Replaced `isAInstagramChannel` with `isAnInstagramChannel`
This commit is contained in:
Muhsin Keloth
2025-04-21 14:46:51 +05:30
committed by GitHub
parent 1531772365
commit 0a394e16ca
8 changed files with 42 additions and 18 deletions

View File

@@ -19,7 +19,7 @@ const {
isAWebWidgetInbox, isAWebWidgetInbox,
isAWhatsAppChannel, isAWhatsAppChannel,
isAnEmailChannel, isAnEmailChannel,
isAInstagramChannel, isAnInstagramChannel,
} = useInbox(); } = useInbox();
const { const {
@@ -60,7 +60,7 @@ const isSent = computed(() => {
isAFacebookInbox.value || isAFacebookInbox.value ||
isASmsInbox.value || isASmsInbox.value ||
isATelegramChannel.value || isATelegramChannel.value ||
isAInstagramChannel.value isAnInstagramChannel.value
) { ) {
return sourceId.value && status.value === MESSAGE_STATUS.SENT; return sourceId.value && status.value === MESSAGE_STATUS.SENT;
} }
@@ -100,7 +100,7 @@ const isRead = computed(() => {
isAWhatsAppChannel.value || isAWhatsAppChannel.value ||
isATwilioChannel.value || isATwilioChannel.value ||
isAFacebookInbox.value || isAFacebookInbox.value ||
isAInstagramChannel.value isAnInstagramChannel.value
) { ) {
return sourceId.value && status.value === MESSAGE_STATUS.READ; return sourceId.value && status.value === MESSAGE_STATUS.READ;
} }

View File

@@ -202,7 +202,7 @@ export default {
if (this.isALineChannel) { if (this.isALineChannel) {
return ALLOWED_FILE_TYPES_FOR_LINE; return ALLOWED_FILE_TYPES_FOR_LINE;
} }
if (this.isAInstagramChannel || this.isInstagramDM) { if (this.isAnInstagramChannel || this.isInstagramDM) {
return ALLOWED_FILE_TYPES_FOR_INSTAGRAM; return ALLOWED_FILE_TYPES_FOR_INSTAGRAM;
} }

View File

@@ -249,7 +249,7 @@ export default {
return this.$t('CONVERSATION.CANNOT_REPLY'); return this.$t('CONVERSATION.CANNOT_REPLY');
}, },
replyWindowLink() { replyWindowLink() {
if (this.isAFacebookInbox || this.isAInstagramChannel) { if (this.isAFacebookInbox || this.isAnInstagramChannel) {
return REPLY_POLICY.FACEBOOK; return REPLY_POLICY.FACEBOOK;
} }
if (this.isAWhatsAppCloudChannel) { if (this.isAWhatsAppCloudChannel) {
@@ -264,7 +264,7 @@ export default {
if ( if (
this.isAWhatsAppChannel || this.isAWhatsAppChannel ||
this.isAFacebookInbox || this.isAFacebookInbox ||
this.isAInstagramChannel this.isAnInstagramChannel
) { ) {
return this.$t('CONVERSATION.24_HOURS_WINDOW'); return this.$t('CONVERSATION.24_HOURS_WINDOW');
} }

View File

@@ -241,15 +241,27 @@ export default {
if (this.isAFacebookInbox) { if (this.isAFacebookInbox) {
return MESSAGE_MAX_LENGTH.FACEBOOK; return MESSAGE_MAX_LENGTH.FACEBOOK;
} }
if (this.isAWhatsAppChannel) { if (this.isAnInstagramChannel) {
return MESSAGE_MAX_LENGTH.INSTAGRAM;
}
if (this.isATwilioWhatsAppChannel) {
return MESSAGE_MAX_LENGTH.TWILIO_WHATSAPP; return MESSAGE_MAX_LENGTH.TWILIO_WHATSAPP;
} }
if (this.isAWhatsAppCloudChannel) {
return MESSAGE_MAX_LENGTH.WHATSAPP_CLOUD;
}
if (this.isASmsInbox) { if (this.isASmsInbox) {
return MESSAGE_MAX_LENGTH.TWILIO_SMS; return MESSAGE_MAX_LENGTH.TWILIO_SMS;
} }
if (this.isAnEmailChannel) { if (this.isAnEmailChannel) {
return MESSAGE_MAX_LENGTH.EMAIL; return MESSAGE_MAX_LENGTH.EMAIL;
} }
if (this.isATwilioSMSChannel) {
return MESSAGE_MAX_LENGTH.TWILIO_SMS;
}
if (this.isAWhatsAppChannel) {
return MESSAGE_MAX_LENGTH.WHATSAPP_CLOUD;
}
return MESSAGE_MAX_LENGTH.GENERAL; return MESSAGE_MAX_LENGTH.GENERAL;
}, },
showFileUpload() { showFileUpload() {
@@ -262,7 +274,7 @@ export default {
this.isASmsInbox || this.isASmsInbox ||
this.isATelegramChannel || this.isATelegramChannel ||
this.isALineChannel || this.isALineChannel ||
this.isAInstagramChannel this.isAnInstagramChannel
); );
}, },
replyButtonLabel() { replyButtonLabel() {
@@ -693,7 +705,7 @@ export default {
// When users send messages containing both text and attachments on Instagram, Instagram treats them as separate messages. // When users send messages containing both text and attachments on Instagram, Instagram treats them as separate messages.
// Although Chatwoot combines these into a single message, Instagram sends separate echo events for each component. // Although Chatwoot combines these into a single message, Instagram sends separate echo events for each component.
// This can create duplicate messages in Chatwoot. To prevent this issue, we'll handle text and attachments as separate messages. // This can create duplicate messages in Chatwoot. To prevent this issue, we'll handle text and attachments as separate messages.
const isOnInstagram = this.isAInstagramChannel; const isOnInstagram = this.isAnInstagramChannel;
if ((isOnWhatsApp || isOnInstagram) && !this.isPrivate) { if ((isOnWhatsApp || isOnInstagram) && !this.isPrivate) {
this.sendMessageAsMultipleMessages(this.message); this.sendMessageAsMultipleMessages(this.message);
} else { } else {
@@ -947,7 +959,7 @@ export default {
const multipleMessagePayload = []; const multipleMessagePayload = [];
if (this.attachedFiles && this.attachedFiles.length) { if (this.attachedFiles && this.attachedFiles.length) {
let caption = this.isAInstagramChannel ? '' : message; let caption = this.isAnInstagramChannel ? '' : message;
this.attachedFiles.forEach(attachment => { this.attachedFiles.forEach(attachment => {
const attachedFile = this.globalConfig.directUploadsEnabled const attachedFile = this.globalConfig.directUploadsEnabled
? attachment.blobSignedId ? attachment.blobSignedId
@@ -963,7 +975,7 @@ export default {
attachmentPayload = this.setReplyToInPayload(attachmentPayload); attachmentPayload = this.setReplyToInPayload(attachmentPayload);
multipleMessagePayload.push(attachmentPayload); multipleMessagePayload.push(attachmentPayload);
// For WhatsApp, only the first attachment gets a caption // For WhatsApp, only the first attachment gets a caption
if (!this.isAInstagramChannel) caption = ''; if (!this.isAnInstagramChannel) caption = '';
}); });
} }
@@ -972,8 +984,8 @@ export default {
// For Instagram, we need a separate text message // For Instagram, we need a separate text message
// For WhatsApp, we only need a text message if there are no attachments // For WhatsApp, we only need a text message if there are no attachments
if ( if (
(this.isAInstagramChannel && this.message) || (this.isAnInstagramChannel && this.message) ||
(!this.isAInstagramChannel && hasNoAttachments) (!this.isAnInstagramChannel && hasNoAttachments)
) { ) {
let messagePayload = { let messagePayload = {
conversationId: this.currentChat.id, conversationId: this.currentChat.id,

View File

@@ -121,7 +121,7 @@ export const useInbox = () => {
); );
}); });
const isAInstagramChannel = computed(() => { const isAnInstagramChannel = computed(() => {
return channelType.value === INBOX_TYPES.INSTAGRAM; return channelType.value === INBOX_TYPES.INSTAGRAM;
}); });
@@ -141,6 +141,6 @@ export const useInbox = () => {
isAWhatsAppCloudChannel, isAWhatsAppCloudChannel,
is360DialogWhatsAppChannel, is360DialogWhatsAppChannel,
isAnEmailChannel, isAnEmailChannel,
isAInstagramChannel, isAnInstagramChannel,
}; };
}; };

View File

@@ -204,7 +204,7 @@ export default {
return false; return false;
}, },
instagramUnauthorized() { instagramUnauthorized() {
return this.isAInstagramChannel && this.inbox.reauthorization_required; return this.isAnInstagramChannel && this.inbox.reauthorization_required;
}, },
// Check if a instagram inbox exists with the same instagram_id // Check if a instagram inbox exists with the same instagram_id
hasDuplicateInstagramInbox() { hasDuplicateInstagramInbox() {

View File

@@ -4,8 +4,20 @@ export const isASubmittedFormMessage = (message = {}) =>
export const MESSAGE_MAX_LENGTH = { export const MESSAGE_MAX_LENGTH = {
GENERAL: 10000, GENERAL: 10000,
FACEBOOK: 1000, // https://developers.facebook.com/docs/messenger-platform/reference/send-api#request
FACEBOOK: 2000,
// https://developers.facebook.com/docs/instagram-platform/instagram-api-with-instagram-login/messaging-api#send-a-text-message
INSTAGRAM: 1000,
// https://www.twilio.com/docs/glossary/what-sms-character-limit
TWILIO_SMS: 320, TWILIO_SMS: 320,
// https://help.twilio.com/articles/360033806753-Maximum-Message-Length-with-Twilio-Programmable-Messaging
TWILIO_WHATSAPP: 1600, TWILIO_WHATSAPP: 1600,
// https://developers.facebook.com/docs/whatsapp/cloud-api/reference/messages#text-object
WHATSAPP_CLOUD: 4096,
// https://support.bandwidth.com/hc/en-us/articles/360010235373-What-are-Bandwidth-s-SMS-character-limits-and-concatenation-practices
BANDWIDTH_SMS: 160,
// https://core.telegram.org/bots/api#sendmessage
TELEGRAM: 4096,
LINE: 2000,
EMAIL: 25000, EMAIL: 25000,
}; };

View File

@@ -121,7 +121,7 @@ export default {
this.isATwilioWhatsAppChannel this.isATwilioWhatsAppChannel
); );
}, },
isAInstagramChannel() { isAnInstagramChannel() {
return this.channelType === INBOX_TYPES.INSTAGRAM; return this.channelType === INBOX_TYPES.INSTAGRAM;
}, },
}, },