diff --git a/src/adapters/netsuite/index.js b/src/adapters/netsuite/index.js index 8554a623..081193d9 100644 --- a/src/adapters/netsuite/index.js +++ b/src/adapters/netsuite/index.js @@ -280,7 +280,7 @@ async function createCallLog({ user, contactInfo, authHeader, callLog, note, add } catch (error) { console.log({ message: "Error in getting timezone" }); } - const callEndTime = moment(callStartTime).add(callLog.duration, 'seconds'); + const callEndTime = (callLog.duration === 'pending') ? moment(callStartTime) : moment(callStartTime).add(callLog.duration, 'seconds'); const formatedStartTime = callStartTime.format('YYYY-MM-DD HH:mm:ss'); const formatedEndTime = callEndTime.format('YYYY-MM-DD HH:mm:ss'); let endTimeSlot = callEndTime.format('HH:mm'); @@ -308,7 +308,6 @@ async function createCallLog({ user, contactInfo, authHeader, callLog, note, add } else if (contactInfo.type === 'custjob') { postBody.company = { id: contactInfo.id }; } - const addLogRes = await axios.post( `https://${user.hostname.split(".")[0]}.suitetalk.api.netsuite.com/services/rest/record/v1/phonecall`, postBody, @@ -392,12 +391,50 @@ async function getCallLog({ user, callLogId, authHeader }) { } -async function updateCallLog({ user, existingCallLog, authHeader, recordingLink, subject, note }) { +async function updateCallLog({ user, existingCallLog, authHeader, recordingLink, subject, note, incomingData }) { try { const existingLogId = existingCallLog.thirdPartyLogId; const callLogResponse = await axios.get(`https://${user.hostname.split(".")[0]}.suitetalk.api.netsuite.com/services/rest/record/v1/phonecall/${existingLogId}`, { headers: { 'Authorization': authHeader } }); let messageBody = callLogResponse.data.message; let patchBody = { title: subject }; + if (incomingData?.startTime !== undefined && incomingData?.duration !== undefined) { + let callStartTime = moment(moment(incomingData.startTime).toISOString()); + let startTimeSLot = moment(incomingData.startTime).format('HH:mm'); + try { + const getTimeZoneUrl = `https://${user.hostname.split(".")[0]}.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=customscript_gettimezone&deploy=customdeploy_gettimezone`; + const timeZoneResponse = await axios.get(getTimeZoneUrl, { + headers: { 'Authorization': authHeader } + }); + const timeZone = timeZoneResponse?.data?.userTimezone; + callStartTime = moment(moment(incomingData.startTime).toISOString()).tz(timeZone); + startTimeSLot = callStartTime.format('HH:mm'); + + } catch (error) { + console.log({ message: "Error in getting timezone in updateCallLog" }); + } + const callEndTime = moment(callStartTime).add(incomingData.duration, 'seconds'); + const formatedStartTime = callStartTime.format('YYYY-MM-DD HH:mm:ss'); + const formatedEndTime = callEndTime.format('YYYY-MM-DD HH:mm:ss'); + let endTimeSlot = callEndTime.format('HH:mm'); + if (startTimeSLot === endTimeSlot) { + //If Start Time and End Time are same, then add 1 minute to End Time because endTime can not be less or equal to startTime + endTimeSlot = callEndTime.add(1, 'minutes').format('HH:mm'); + } + patchBody.startDate = callStartTime; + patchBody.startTime = startTimeSLot; + patchBody.endTime = endTimeSlot; + const contactNumberMatch = messageBody.match(/Contact Number: (\+?\d+)/); + let phoneNumber; + if (contactNumberMatch) { + phoneNumber = contactNumberMatch[1]; + } + let callRecordingLink; + const recordingLinkMatch = messageBody.match(/Call recording link: (\S+)/); + if (recordingLinkMatch) { + callRecordingLink = recordingLinkMatch[1]; + } + messageBody = `\nCall Start Time: ${formatedStartTime}\n Duration In Second: ${incomingData.duration}Sec.\n Call End Time : ${formatedEndTime}\nContact Number: ${phoneNumber}\nNote: ${note}${callRecordingLink ? `\nCall recording link ${callRecordingLink}` : ''}\n\n--- Created via RingCentral CRM Extension`; + } if (!!recordingLink) { const urlDecodedRecordingLink = decodeURIComponent(recordingLink); if (messageBody.includes('\n\n--- Created via RingCentral App Connect')) { diff --git a/src/adapters/pipedrive/index.js b/src/adapters/pipedrive/index.js index 3f499e18..0c1a7e0b 100644 --- a/src/adapters/pipedrive/index.js +++ b/src/adapters/pipedrive/index.js @@ -203,7 +203,7 @@ async function createCallLog({ user, contactInfo, authHeader, callLog, note, add }; } -async function updateCallLog({ user, existingCallLog, authHeader, recordingLink, subject, note }) { +async function updateCallLog({ user, existingCallLog, authHeader, recordingLink, subject, note, incomingData }) { const existingPipedriveLogId = existingCallLog.thirdPartyLogId; const getLogRes = await axios.get( `https://${user.hostname}/v1/activities/${existingPipedriveLogId}`, diff --git a/src/adapters/testCRM/index.js b/src/adapters/testCRM/index.js index 3a2f0e66..f1ef4780 100644 --- a/src/adapters/testCRM/index.js +++ b/src/adapters/testCRM/index.js @@ -151,11 +151,10 @@ async function findContact({ user, authHeader, phoneNumber, overridingFormat, is console.log(`phone number: ${phoneNumber}`) console.log(`is extesnion number? ${isExtension}`) const numberToQueryArray = []; - if(isExtension) - { + if (isExtension) { numberToQueryArray.push(phoneNumber); } - else{ + else { numberToQueryArray.push(phoneNumber.replace(' ', '+')); } // You can use parsePhoneNumber functions to further parse the phone number @@ -286,7 +285,7 @@ async function getCallLog({ user, callLogId, authHeader }) { // - note: note submitted by user // - subject: subject submitted by user // - recordingLink: recordingLink updated from RingCentral. It's separated from createCallLog because recordings are not generated right after a call. It needs to be updated into existing call log -async function updateCallLog({ user, existingCallLog, authHeader, recordingLink, subject, note }) { +async function updateCallLog({ user, existingCallLog, authHeader, recordingLink, subject, note, incomingData }) { // --------------------------------------- // ---TODO.6: Implement call log update--- // ---------------------------------------