Files
chatwoot/app/javascript/shared/mixins/inboxMixin.js
Sojan Jose b7f2c151bf feat: Voice channel creation Flow (#11775)
This PR introduces a new channel type for voice conversations.

ref: #11481 

## Changes

- Add database migration for channel_voice table with phone_number and
provider_config
- Create Channel::Voice model with E.164 phone number validation and
Twilio config validation
- Add voice channel association to Account model
- Extend inbox helpers and types to support voice channels
- Add voice channel setup UI with Twilio configuration form
- Include voice channel in channel factory and list components
- Add API routes and store actions for voice channel creation
- Add comprehensive translations for voice channel management

---------

Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
Co-authored-by: iamsivin <iamsivin@gmail.com>
2025-06-25 14:21:03 -07:00

141 lines
3.9 KiB
JavaScript

import { INBOX_TYPES } from 'dashboard/helper/inbox';
export const INBOX_FEATURES = {
REPLY_TO: 'replyTo',
REPLY_TO_OUTGOING: 'replyToOutgoing',
VOICE_CALL: 'voiceCall',
};
// This is a single source of truth for inbox features
// This is used to check if a feature is available for a particular inbox or not
export const INBOX_FEATURE_MAP = {
[INBOX_FEATURES.REPLY_TO]: [
INBOX_TYPES.FB,
INBOX_TYPES.WEB,
INBOX_TYPES.TWITTER,
INBOX_TYPES.WHATSAPP,
INBOX_TYPES.TELEGRAM,
INBOX_TYPES.API,
INBOX_TYPES.VOICE,
],
[INBOX_FEATURES.REPLY_TO_OUTGOING]: [
INBOX_TYPES.WEB,
INBOX_TYPES.TWITTER,
INBOX_TYPES.WHATSAPP,
INBOX_TYPES.TELEGRAM,
INBOX_TYPES.API,
INBOX_TYPES.VOICE,
],
[INBOX_FEATURES.VOICE_CALL]: [INBOX_TYPES.VOICE],
};
export default {
computed: {
channelType() {
return this.inbox?.channel_type || '';
},
whatsAppAPIProvider() {
return this.inbox?.provider || '';
},
isAMicrosoftInbox() {
return this.isAnEmailChannel && this.inbox?.provider === 'microsoft';
},
isAGoogleInbox() {
return this.isAnEmailChannel && this.inbox?.provider === 'google';
},
isAPIInbox() {
return this.channelType === INBOX_TYPES.API;
},
isATwitterInbox() {
return this.channelType === INBOX_TYPES.TWITTER;
},
isAFacebookInbox() {
return this.channelType === INBOX_TYPES.FB;
},
isAWebWidgetInbox() {
return this.channelType === INBOX_TYPES.WEB;
},
isATwilioChannel() {
return this.channelType === INBOX_TYPES.TWILIO;
},
isAVoiceChannel() {
return this.channelType === INBOX_TYPES.VOICE;
},
isALineChannel() {
return this.channelType === INBOX_TYPES.LINE;
},
isAnEmailChannel() {
return this.channelType === INBOX_TYPES.EMAIL;
},
isATelegramChannel() {
return this.channelType === INBOX_TYPES.TELEGRAM;
},
isATwilioSMSChannel() {
const { medium: medium = '' } = this.inbox;
return this.isATwilioChannel && medium === 'sms';
},
isASmsInbox() {
return this.channelType === INBOX_TYPES.SMS || this.isATwilioSMSChannel;
},
isATwilioWhatsAppChannel() {
const { medium: medium = '' } = this.inbox;
return this.isATwilioChannel && medium === 'whatsapp';
},
isAWhatsAppCloudChannel() {
return (
this.channelType === INBOX_TYPES.WHATSAPP &&
this.whatsAppAPIProvider === 'whatsapp_cloud'
);
},
is360DialogWhatsAppChannel() {
return (
this.channelType === INBOX_TYPES.WHATSAPP &&
this.whatsAppAPIProvider === 'default'
);
},
chatAdditionalAttributes() {
const { additional_attributes: additionalAttributes } = this.chat || {};
return additionalAttributes || {};
},
isTwitterInboxTweet() {
return this.chatAdditionalAttributes.type === 'tweet';
},
twilioBadge() {
return `${this.isATwilioSMSChannel ? 'sms' : 'whatsapp'}`;
},
twitterBadge() {
return `${this.isTwitterInboxTweet ? 'twitter-tweet' : 'twitter-dm'}`;
},
facebookBadge() {
return this.chatAdditionalAttributes.type || 'facebook';
},
inboxBadge() {
let badgeKey = '';
if (this.isATwitterInbox) {
badgeKey = this.twitterBadge;
} else if (this.isAFacebookInbox) {
badgeKey = this.facebookBadge;
} else if (this.isATwilioChannel) {
badgeKey = this.twilioBadge;
} else if (this.isAWhatsAppChannel) {
badgeKey = 'whatsapp';
}
return badgeKey || this.channelType;
},
isAWhatsAppChannel() {
return (
this.channelType === INBOX_TYPES.WHATSAPP ||
this.isATwilioWhatsAppChannel
);
},
isAnInstagramChannel() {
return this.channelType === INBOX_TYPES.INSTAGRAM;
},
},
methods: {
inboxHasFeature(feature) {
return INBOX_FEATURE_MAP[feature]?.includes(this.channelType) ?? false;
},
},
};