Merge pull request #89 from shariquerik/moved-twilio-inside-integrations

fix: moved twilio inside integrations folder and other small fixes
This commit is contained in:
Shariq Ansari 2024-03-28 17:35:01 +05:30 committed by GitHub
commit eb04c38346
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 44 additions and 35 deletions

View File

@ -62,7 +62,7 @@ class TwilioSettings(Document):
frappe.throw(_("Twilio API credential creation error.")) frappe.throw(_("Twilio API credential creation error."))
def get_twilio_voice_url(self): def get_twilio_voice_url(self):
url_path = "/api/method/crm.twilio.api.voice" url_path = "/api/method/crm.integrations.twilio.api.voice"
return get_public_url(url_path) return get_public_url(url_path)
def get_application(self, twilio, friendly_name=None): def get_application(self, twilio, friendly_name=None):

View File

@ -69,11 +69,11 @@ class Twilio:
return identity.replace('(at)', '@') return identity.replace('(at)', '@')
def get_recording_status_callback_url(self): def get_recording_status_callback_url(self):
url_path = "/api/method/crm.twilio.api.update_recording_info" url_path = "/api/method/crm.integrations.twilio.api.update_recording_info"
return get_public_url(url_path) return get_public_url(url_path)
def get_update_call_status_callback_url(self): def get_update_call_status_callback_url(self):
url_path = "/api/method/crm.twilio.api.update_call_status_info" url_path = "/api/method/crm.integrations.twilio.api.update_call_status_info"
return get_public_url(url_path) return get_public_url(url_path)
def generate_twilio_dial_response(self, from_number: str, to_number: str): def generate_twilio_dial_response(self, from_number: str, to_number: str):
@ -141,7 +141,7 @@ class IncomingCall:
""" """
twilio = Twilio.connect() twilio = Twilio.connect()
owners = get_twilio_number_owners(self.to_number) owners = get_twilio_number_owners(self.to_number)
attender = get_the_call_attender(owners) attender = get_the_call_attender(owners, self.from_number)
if not attender: if not attender:
resp = VoiceResponse() resp = VoiceResponse()
@ -190,11 +190,20 @@ def get_active_loggedin_users(users):
""", {'users': users}) """, {'users': users})
return [row[0] for row in set(rows)] return [row[0] for row in set(rows)]
def get_the_call_attender(owners): def get_the_call_attender(owners, caller=None):
"""Get attender details from list of owners """Get attender details from list of owners
""" """
if not owners: return if not owners: return
current_loggedin_users = get_active_loggedin_users(list(owners.keys())) current_loggedin_users = get_active_loggedin_users(list(owners.keys()))
if len(current_loggedin_users) > 1 and caller:
deal_owner = frappe.db.get_value('CRM Deal', {'mobile_no': caller}, 'deal_owner')
if not deal_owner:
deal_owner = frappe.db.get_value('CRM Lead', {'mobile_no': caller}, 'lead_owner')
for user in current_loggedin_users:
if user == deal_owner:
current_loggedin_users = [user]
for name, details in owners.items(): for name, details in owners.items():
if ((details['call_receiving_device'] == 'Phone' and details['mobile_no']) or if ((details['call_receiving_device'] == 'Phone' and details['mobile_no']) or
(details['call_receiving_device'] == 'Computer' and name in current_loggedin_users)): (details['call_receiving_device'] == 'Computer' and name in current_loggedin_users)):
@ -244,7 +253,7 @@ class TwilioCallDetails:
caller = Twilio.emailid_from_identity(identity) if identity else '' caller = Twilio.emailid_from_identity(identity) if identity else ''
else: else:
owners = get_twilio_number_owners(to_number) owners = get_twilio_number_owners(to_number)
attender = get_the_call_attender(owners) attender = get_the_call_attender(owners, from_number)
receiver = attender['name'] if attender else '' receiver = attender['name'] if attender else ''
return { return {

View File

@ -9,7 +9,7 @@
"serve": "vite preview" "serve": "vite preview"
}, },
"dependencies": { "dependencies": {
"@twilio/voice-sdk": "^2.7.1", "@twilio/voice-sdk": "^2.10.2",
"@vueuse/core": "^10.3.0", "@vueuse/core": "^10.3.0",
"@vueuse/integrations": "^10.3.0", "@vueuse/integrations": "^10.3.0",
"feather-icons": "^4.28.0", "feather-icons": "^4.28.0",

View File

@ -2,7 +2,7 @@
<div v-show="showCallPopup"> <div v-show="showCallPopup">
<div <div
ref="callPopup" ref="callPopup"
class="fixed z-12 flex w-60 cursor-move select-none flex-col rounded-lg bg-gray-900 p-4 text-gray-300 shadow-2xl" class="fixed z-20 flex w-60 cursor-move select-none flex-col rounded-lg bg-gray-900 p-4 text-gray-300 shadow-2xl"
:style="style" :style="style"
> >
<div class="flex flex-row-reverse items-center gap-1"> <div class="flex flex-row-reverse items-center gap-1">
@ -205,7 +205,7 @@ const { setMakeCall, setTwilioEnabled, $dialog } = globalStore()
let device = '' let device = ''
let log = ref('Connecting...') let log = ref('Connecting...')
let _call = ref(null) let _call = null
const contact = ref({ const contact = ref({
full_name: '', full_name: '',
mobile_no: '', mobile_no: '',
@ -228,8 +228,8 @@ const note = ref({
async function updateNote(_note, insert_mode = false) { async function updateNote(_note, insert_mode = false) {
note.value = _note note.value = _note
if (insert_mode && _note.name) { if (insert_mode && _note.name) {
await call('crm.twilio.api.add_note_to_call_log', { await call('crm.integrations.twilio.api.add_note_to_call_log', {
call_sid: _call.value.parameters.CallSid, call_sid: _call.parameters.CallSid,
note: _note.name, note: _note.name,
}) })
} }
@ -243,14 +243,14 @@ let { style } = useDraggable(callPopup, {
}) })
async function is_twilio_enabled() { async function is_twilio_enabled() {
return await call('crm.twilio.api.is_enabled') return await call('crm.integrations.twilio.api.is_enabled')
} }
async function startupClient() { async function startupClient() {
log.value = 'Requesting Access Token...' log.value = 'Requesting Access Token...'
try { try {
const data = await call('crm.twilio.api.generate_access_token') const data = await call('crm.integrations.twilio.api.generate_access_token')
log.value = 'Got a token.' log.value = 'Got a token.'
intitializeDevice(data.token) intitializeDevice(data.token)
} catch (err) { } catch (err) {
@ -286,17 +286,17 @@ function addDeviceListeners() {
device.on('incoming', handleIncomingCall) device.on('incoming', handleIncomingCall)
device.on('tokenWillExpire', async () => { device.on('tokenWillExpire', async () => {
const data = await call('crm.twilio.api.generate_access_token') const data = await call('crm.integrations.twilio.api.generate_access_token')
device.updateToken(data.token) device.updateToken(data.token)
}) })
} }
function toggleMute() { function toggleMute() {
if (_call.value.isMuted()) { if (_call.isMuted()) {
_call.value.mute(false) _call.mute(false)
muted.value = false muted.value = false
} else { } else {
_call.value.mute() _call.mute()
muted.value = true muted.value = true
} }
} }
@ -318,9 +318,9 @@ function handleIncomingCall(call) {
} }
showCallPopup.value = true showCallPopup.value = true
_call.value = call _call = call
_call.value.on('accept', (conn) => { _call.on('accept', (conn) => {
console.log('conn', conn) console.log('conn', conn)
}) })
@ -333,12 +333,12 @@ function handleIncomingCall(call) {
async function acceptIncomingCall() { async function acceptIncomingCall() {
log.value = 'Accepted incoming call.' log.value = 'Accepted incoming call.'
onCall.value = true onCall.value = true
await _call.value.accept() await _call.accept()
counterUp.value.start() counterUp.value.start()
} }
function rejectIncomingCall() { function rejectIncomingCall() {
_call.value.reject() _call.reject()
log.value = 'Rejected incoming call' log.value = 'Rejected incoming call'
showCallPopup.value = false showCallPopup.value = false
if (showSmallCallWindow.value == undefined) { if (showSmallCallWindow.value == undefined) {
@ -351,7 +351,7 @@ function rejectIncomingCall() {
} }
function hangUpCall() { function hangUpCall() {
_call.value.disconnect() _call.disconnect()
log.value = 'Hanging up incoming call' log.value = 'Hanging up incoming call'
onCall.value = false onCall.value = false
callStatus.value = '' callStatus.value = ''
@ -371,7 +371,7 @@ function handleDisconnectedIncomingCall() {
} else { } else {
showSmallCallWindow.value = false showSmallCallWindow.value = false
} }
_call.value = null _call = null
muted.value = false muted.value = false
onCall.value = false onCall.value = false
counterUp.value.stop() counterUp.value.stop()
@ -396,14 +396,14 @@ async function makeOutgoingCall(number) {
log.value = `Attempting to call ${number} ...` log.value = `Attempting to call ${number} ...`
try { try {
_call.value = await device.connect({ _call = await device.connect({
params: { To: number }, params: { To: number },
}) })
showCallPopup.value = true showCallPopup.value = true
callStatus.value = 'initiating' callStatus.value = 'initiating'
_call.value.on('messageReceived', (message) => { _call.on('messageReceived', (message) => {
let info = message.content let info = message.content
callStatus.value = info.CallStatus callStatus.value = info.CallStatus
@ -417,19 +417,19 @@ async function makeOutgoingCall(number) {
} }
}) })
_call.value.on('accept', () => { _call.on('accept', () => {
log.value = `Initiated call!` log.value = `Initiated call!`
showCallPopup.value = true showCallPopup.value = true
calling.value = true calling.value = true
onCall.value = false onCall.value = false
}) })
_call.value.on('disconnect', (conn) => { _call.on('disconnect', (conn) => {
log.value = `Call ended from makeOutgoing call disconnect.` log.value = `Call ended from makeOutgoing call disconnect.`
calling.value = false calling.value = false
onCall.value = false onCall.value = false
showCallPopup.value = false showCallPopup.value = false
showSmallCallWindow = false showSmallCallWindow = false
_call.value = null _call = null
callStatus.value = '' callStatus.value = ''
muted.value = false muted.value = false
counterUp.value.stop() counterUp.value.stop()
@ -438,13 +438,13 @@ async function makeOutgoingCall(number) {
content: '', content: '',
} }
}) })
_call.value.on('cancel', () => { _call.on('cancel', () => {
log.value = `Call ended from makeOutgoing call cancel.` log.value = `Call ended from makeOutgoing call cancel.`
calling.value = false calling.value = false
onCall.value = false onCall.value = false
showCallPopup.value = false showCallPopup.value = false
showSmallCallWindow = false showSmallCallWindow = false
_call.value = null _call = null
callStatus.value = '' callStatus.value = ''
muted.value = false muted.value = false
note.value = { note.value = {
@ -462,7 +462,7 @@ async function makeOutgoingCall(number) {
} }
function cancelCall() { function cancelCall() {
_call.value.disconnect() _call.disconnect()
showCallPopup.value = false showCallPopup.value = false
if (showSmallCallWindow.value == undefined) { if (showSmallCallWindow.value == undefined) {
showSmallCallWindow = false showSmallCallWindow = false

View File

@ -999,10 +999,10 @@
resolved "https://registry.yarnpkg.com/@twilio/voice-errors/-/voice-errors-1.4.0.tgz#0ab954085a32a00442814e56c95936908871ff6e" resolved "https://registry.yarnpkg.com/@twilio/voice-errors/-/voice-errors-1.4.0.tgz#0ab954085a32a00442814e56c95936908871ff6e"
integrity sha512-7BCg9MPz+KQ0JJ6Rl5W3Zw3E+i3Tt77VZw3/2i3Z+IPZITmCOQLu1nKx/0Nlj505Xtfr7eY9Mcern5PfIoBW0w== integrity sha512-7BCg9MPz+KQ0JJ6Rl5W3Zw3E+i3Tt77VZw3/2i3Z+IPZITmCOQLu1nKx/0Nlj505Xtfr7eY9Mcern5PfIoBW0w==
"@twilio/voice-sdk@^2.7.1": "@twilio/voice-sdk@^2.10.2":
version "2.9.0" version "2.10.2"
resolved "https://registry.yarnpkg.com/@twilio/voice-sdk/-/voice-sdk-2.9.0.tgz#57b5097bfc43089e63eeeec1b9be545b607c9a8d" resolved "https://registry.yarnpkg.com/@twilio/voice-sdk/-/voice-sdk-2.10.2.tgz#99c668f1af9ea135c026c43a2f293678bd68afc3"
integrity sha512-e7Z3o9VMJ3M5fVf4kPBFrS5D6PqDEX82Sp9RhTBLl/+l2oPAHDcJumNM4pmMCvqdIpgIYg9miq+TiQ65uGko2Q== integrity sha512-+isGRUI5nkjD0fxl6UeO1hfUYx0SnynFePSmw186QxCHiWqToxnA6hg9SGiC9I4RDJKBDmnKlxA/4egupPQ7wg==
dependencies: dependencies:
"@twilio/voice-errors" "1.4.0" "@twilio/voice-errors" "1.4.0"
"@types/md5" "2.3.2" "@types/md5" "2.3.2"