diff --git a/crm/fcrm/doctype/twilio_settings/twilio_settings.json b/crm/fcrm/doctype/twilio_settings/twilio_settings.json index ed3aa43f1..8aef97490 100644 --- a/crm/fcrm/doctype/twilio_settings/twilio_settings.json +++ b/crm/fcrm/doctype/twilio_settings/twilio_settings.json @@ -7,6 +7,7 @@ "editable_grid": 1, "engine": "InnoDB", "field_order": [ + "section_break_malx", "account_sid", "api_key", "api_secret", @@ -14,8 +15,9 @@ "auth_token", "twiml_sid", "section_break_ssqj", - "record_calls", - "column_break_avmt" + "enabled", + "column_break_avmt", + "record_calls" ], "fields": [ { @@ -23,7 +25,7 @@ "fieldtype": "Data", "in_list_view": 1, "label": "Account SID", - "reqd": 1 + "mandatory_depends_on": "eval: doc.enabled" }, { "fieldname": "api_key", @@ -46,7 +48,7 @@ "fieldtype": "Password", "in_list_view": 1, "label": "Auth Token", - "reqd": 1 + "mandatory_depends_on": "eval: doc.enabled" }, { "fieldname": "twiml_sid", @@ -67,12 +69,22 @@ { "fieldname": "column_break_avmt", "fieldtype": "Column Break" + }, + { + "fieldname": "section_break_malx", + "fieldtype": "Section Break" + }, + { + "default": "0", + "fieldname": "enabled", + "fieldtype": "Check", + "label": "Enabled" } ], "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2023-09-20 16:42:17.025651", + "modified": "2023-11-03 15:13:09.155818", "modified_by": "Administrator", "module": "FCRM", "name": "Twilio Settings", diff --git a/crm/twilio/api.py b/crm/twilio/api.py index 536b62aea..4297e5a7f 100644 --- a/crm/twilio/api.py +++ b/crm/twilio/api.py @@ -5,6 +5,10 @@ from frappe import _ from .twilio_handler import Twilio, IncomingCall, TwilioCallDetails +@frappe.whitelist() +def is_enabled(): + return frappe.db.get_single_value("Twilio Settings", "enabled") + @frappe.whitelist() def generate_access_token(): """Returns access token that is required to authenticate Twilio Client SDK. diff --git a/crm/twilio/twilio_handler.py b/crm/twilio/twilio_handler.py index 61e527dd7..71a64461c 100644 --- a/crm/twilio/twilio_handler.py +++ b/crm/twilio/twilio_handler.py @@ -27,8 +27,8 @@ def connect(self): """Make a twilio connection. """ settings = frappe.get_doc("Twilio Settings") - # if not (settings and settings.enabled): - # return + if not (settings and settings.enabled): + return return Twilio(settings=settings) def get_phone_numbers(self): @@ -115,6 +115,8 @@ def generate_twilio_client_response(self, client, ring_tone='at'): @classmethod def get_twilio_client(self): twilio_settings = frappe.get_doc("Twilio Settings") + if not twilio_settings.enabled: + frappe.throw(_("Please enable twilio settings before making a call.")) auth_token = get_decrypted_password("Twilio Settings", "Twilio Settings", 'auth_token') client = TwilioClient(twilio_settings.account_sid, auth_token) diff --git a/frappe-ui b/frappe-ui index 38eb500cb..e0859c616 160000 --- a/frappe-ui +++ b/frappe-ui @@ -1 +1 @@ -Subproject commit 38eb500cb47d6cfc7124817e9c2acdcd560045f1 +Subproject commit e0859c6165a5d54a999f94e7c1cf9647ecd2bf72 diff --git a/frontend/package.json b/frontend/package.json index 67d6c91d9..b70de79c0 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -9,21 +9,23 @@ "serve": "vite preview" }, "dependencies": { - "@tiptap/vue-3": "^2.0.4", "@twilio/voice-sdk": "^2.7.1", - "@vitejs/plugin-vue": "^4.2.3", "@vueuse/core": "^10.3.0", "@vueuse/integrations": "^10.3.0", - "autoprefixer": "^10.4.14", "feather-icons": "^4.28.0", - "frappe-ui": "^0.1.12", + "frappe-ui": "^0.1.14", "pinia": "^2.0.33", - "postcss": "^8.4.5", "socket.io-client": "^4.7.2", "sortablejs": "^1.15.0", "tailwindcss": "^3.3.3", "vite": "^4.4.9", "vue": "^3.3.4", "vue-router": "^4.2.2" + }, + "devDependencies": { + "@vitejs/plugin-vue": "^4.2.3", + "autoprefixer": "^10.4.14", + "postcss": "^8.4.5", + "vite": "^4.4.9" } } diff --git a/frontend/src/components/CallUI.vue b/frontend/src/components/CallUI.vue index 92f4ae879..55cf9596a 100644 --- a/frontend/src/components/CallUI.vue +++ b/frontend/src/components/CallUI.vue @@ -2,17 +2,17 @@
-
- +
+
-
+
@@ -22,11 +22,11 @@
{{ contact.mobile_no }}
-
+
{{ counterUp?.updatedTime }}
-
+
{{ callStatus == 'ringing' ? 'Ringing...' @@ -43,13 +43,13 @@ />
@@ -87,7 +87,7 @@ @click="acceptIncomingCall" >
@@ -107,16 +107,16 @@
-
+
{{ contact.full_name }}
@@ -124,10 +124,10 @@
{{ counterUp?.updatedTime }}
-
@@ -152,21 +152,21 @@
@@ -197,6 +197,7 @@ const contact = ref({ mobile_no: '', }) +let enabled = ref(false) let showCallPopup = ref(false) let showSmallCallWindow = ref(false) let onCall = ref(false) @@ -244,6 +245,10 @@ let { style } = useDraggable(callPopup, { preventDefault: true, }) +async function is_twilio_enabled() { + return await call('crm.twilio.api.is_enabled') +} + async function startupClient() { log.value = 'Requesting Access Token...' @@ -469,7 +474,10 @@ function toggleCallWindow() { } } -onMounted(() => startupClient()) +onMounted(async () => { + enabled.value = await is_twilio_enabled() + enabled.value && startupClient() +}) watch( () => log.value, @@ -481,6 +489,7 @@ watch( const app = getCurrentInstance() app.appContext.config.globalProperties.makeCall = makeOutgoingCall +app.appContext.config.globalProperties.is_twilio_enabled = enabled.value