Voice calling is now a capability on the existing TwilioSms rather than a separate Voice model. A single Twilio phone number handles both SMS and voice calls through one inbox. Fixes https://linear.app/chatwoot/issue/CW-6683/add-voice-calling-as-a-capability-on-twilio-sms-channel and https://linear.app/chatwoot/issue/PLA-120/add-the-support-for-sms **What changed** - Replaced Channel::Voice with voice_enabled flag on Channel::TwilioSms - Added voice_enabled, twiml_app_sid, api_key_secret columns to channel_twilio_sms table - Dropped channel_voice table (no production data) - All voice logic lives in Enterprise layer via prepend_mod_with('Channel::TwilioSms') - Added Voice settings tab on Twilio SMS inbox settings to enable/disable voice - Validates Twilio number voice capability before provisioning - Teardown service cleans up TwiML app and credentials when voice is disabled - Frontend voice detection uses isVoiceCallEnabled() / getVoiceCallProvider() helpers — extensible to future providers - Gated by channel_voice feature flag **How to test** 1. Enable feature flag: Account.find(<id>).enable_features('channel_voice') 2. Create voice inbox: Inboxes → Voice tile → enter Twilio credentials → verify incoming/outgoing calls and SMS work 3. Enable voice on existing SMS inbox: Inboxes → select Twilio SMS inbox → Voice tab → toggle on → provide API key credentials → verify calls work 4. Disable voice: Voice tab → toggle off → verify TwiML app is deleted, credentials cleared, SMS still works 5. Re-enable voice: Toggle on again → must provide api_key_secret again → new TwiML app provisioned --------- Co-authored-by: Muhsin <12408980+muhsin-k@users.noreply.github.com>
185 lines
4.5 KiB
JavaScript
185 lines
4.5 KiB
JavaScript
export const INBOX_TYPES = {
|
|
WEB: 'Channel::WebWidget',
|
|
FB: 'Channel::FacebookPage',
|
|
TWITTER: 'Channel::TwitterProfile',
|
|
TWILIO: 'Channel::TwilioSms',
|
|
WHATSAPP: 'Channel::Whatsapp',
|
|
API: 'Channel::Api',
|
|
EMAIL: 'Channel::Email',
|
|
TELEGRAM: 'Channel::Telegram',
|
|
LINE: 'Channel::Line',
|
|
SMS: 'Channel::Sms',
|
|
INSTAGRAM: 'Channel::Instagram',
|
|
TIKTOK: 'Channel::Tiktok',
|
|
};
|
|
|
|
// Add providers here as they gain voice capability (e.g., WhatsApp Cloud, Twilio WhatsApp)
|
|
export const VOICE_CALL_PROVIDERS = {
|
|
TWILIO: 'twilio',
|
|
};
|
|
|
|
export const getVoiceCallProvider = inbox => {
|
|
if (!inbox) return null;
|
|
|
|
// Callers pass either snake_case (raw API) or camelCase (after camelcaseKeys) shapes.
|
|
const channelType = inbox.channel_type || inbox.channelType;
|
|
const voiceEnabled = inbox.voice_enabled || inbox.voiceEnabled;
|
|
|
|
if (channelType === INBOX_TYPES.TWILIO && voiceEnabled) {
|
|
return VOICE_CALL_PROVIDERS.TWILIO;
|
|
}
|
|
|
|
return null;
|
|
};
|
|
|
|
export const isVoiceCallEnabled = inbox => getVoiceCallProvider(inbox) !== null;
|
|
|
|
export const TWILIO_CHANNEL_MEDIUM = {
|
|
WHATSAPP: 'whatsapp',
|
|
SMS: 'sms',
|
|
};
|
|
|
|
const INBOX_ICON_MAP_FILL = {
|
|
[INBOX_TYPES.WEB]: 'i-ri-global-fill',
|
|
[INBOX_TYPES.FB]: 'i-ri-messenger-fill',
|
|
[INBOX_TYPES.TWITTER]: 'i-ri-twitter-x-fill',
|
|
[INBOX_TYPES.WHATSAPP]: 'i-ri-whatsapp-fill',
|
|
[INBOX_TYPES.API]: 'i-ri-cloudy-fill',
|
|
[INBOX_TYPES.EMAIL]: 'i-ri-mail-fill',
|
|
[INBOX_TYPES.TELEGRAM]: 'i-ri-telegram-fill',
|
|
[INBOX_TYPES.LINE]: 'i-ri-line-fill',
|
|
[INBOX_TYPES.INSTAGRAM]: 'i-ri-instagram-fill',
|
|
[INBOX_TYPES.TIKTOK]: 'i-ri-tiktok-fill',
|
|
};
|
|
|
|
const DEFAULT_ICON_FILL = 'i-ri-chat-1-fill';
|
|
|
|
const INBOX_ICON_MAP_LINE = {
|
|
[INBOX_TYPES.WEB]: 'i-woot-website',
|
|
[INBOX_TYPES.FB]: 'i-woot-messenger',
|
|
[INBOX_TYPES.TWITTER]: 'i-woot-x',
|
|
[INBOX_TYPES.WHATSAPP]: 'i-woot-whatsapp',
|
|
[INBOX_TYPES.API]: 'i-woot-api',
|
|
[INBOX_TYPES.EMAIL]: 'i-woot-mail',
|
|
[INBOX_TYPES.TELEGRAM]: 'i-woot-telegram',
|
|
[INBOX_TYPES.LINE]: 'i-woot-line',
|
|
[INBOX_TYPES.INSTAGRAM]: 'i-woot-instagram',
|
|
[INBOX_TYPES.TIKTOK]: 'i-woot-tiktok',
|
|
};
|
|
|
|
const DEFAULT_ICON_LINE = 'i-ri-chat-1-line';
|
|
|
|
export const getInboxSource = (type, phoneNumber, inbox) => {
|
|
switch (type) {
|
|
case INBOX_TYPES.WEB:
|
|
return inbox.website_url || '';
|
|
|
|
case INBOX_TYPES.TWILIO:
|
|
case INBOX_TYPES.WHATSAPP:
|
|
return phoneNumber || '';
|
|
|
|
case INBOX_TYPES.EMAIL:
|
|
return inbox.email || '';
|
|
|
|
default:
|
|
return '';
|
|
}
|
|
};
|
|
export const getReadableInboxByType = (type, phoneNumber) => {
|
|
switch (type) {
|
|
case INBOX_TYPES.WEB:
|
|
return 'livechat';
|
|
|
|
case INBOX_TYPES.FB:
|
|
return 'facebook';
|
|
|
|
case INBOX_TYPES.TWITTER:
|
|
return 'twitter';
|
|
|
|
case INBOX_TYPES.TWILIO:
|
|
return phoneNumber?.startsWith('whatsapp') ? 'whatsapp' : 'sms';
|
|
|
|
case INBOX_TYPES.WHATSAPP:
|
|
return 'whatsapp';
|
|
|
|
case INBOX_TYPES.API:
|
|
return 'api';
|
|
|
|
case INBOX_TYPES.EMAIL:
|
|
return 'email';
|
|
|
|
case INBOX_TYPES.TELEGRAM:
|
|
return 'telegram';
|
|
|
|
case INBOX_TYPES.LINE:
|
|
return 'line';
|
|
|
|
default:
|
|
return 'chat';
|
|
}
|
|
};
|
|
|
|
export const getInboxClassByType = (type, phoneNumber) => {
|
|
switch (type) {
|
|
case INBOX_TYPES.WEB:
|
|
return 'globe-desktop';
|
|
|
|
case INBOX_TYPES.FB:
|
|
return 'brand-facebook';
|
|
|
|
case INBOX_TYPES.TWITTER:
|
|
return 'brand-twitter';
|
|
|
|
case INBOX_TYPES.TWILIO:
|
|
return phoneNumber?.startsWith('whatsapp')
|
|
? 'brand-whatsapp'
|
|
: 'brand-sms';
|
|
|
|
case INBOX_TYPES.WHATSAPP:
|
|
return 'brand-whatsapp';
|
|
|
|
case INBOX_TYPES.API:
|
|
return 'cloud';
|
|
|
|
case INBOX_TYPES.EMAIL:
|
|
return 'mail';
|
|
|
|
case INBOX_TYPES.TELEGRAM:
|
|
return 'brand-telegram';
|
|
|
|
case INBOX_TYPES.LINE:
|
|
return 'brand-line';
|
|
|
|
case INBOX_TYPES.INSTAGRAM:
|
|
return 'brand-instagram';
|
|
|
|
case INBOX_TYPES.TIKTOK:
|
|
return 'brand-tiktok';
|
|
|
|
default:
|
|
return 'chat';
|
|
}
|
|
};
|
|
|
|
export const getInboxIconByType = (type, medium, variant = 'fill') => {
|
|
const iconMap =
|
|
variant === 'fill' ? INBOX_ICON_MAP_FILL : INBOX_ICON_MAP_LINE;
|
|
const defaultIcon =
|
|
variant === 'fill' ? DEFAULT_ICON_FILL : DEFAULT_ICON_LINE;
|
|
|
|
// Special case for Twilio (whatsapp and sms)
|
|
if (type === INBOX_TYPES.TWILIO && medium === 'whatsapp') {
|
|
return iconMap[INBOX_TYPES.WHATSAPP];
|
|
}
|
|
|
|
return iconMap[type] ?? defaultIcon;
|
|
};
|
|
|
|
export const getInboxWarningIconClass = (type, reauthorizationRequired) => {
|
|
const allowedInboxTypes = [INBOX_TYPES.FB, INBOX_TYPES.EMAIL];
|
|
if (allowedInboxTypes.includes(type) && reauthorizationRequired) {
|
|
return 'warning';
|
|
}
|
|
return '';
|
|
};
|