Skip to content

Commit

Permalink
NetSuite: Update startTime and endTime with updateCallLog
Browse files Browse the repository at this point in the history
  • Loading branch information
SushilMallRC committed Dec 24, 2024
1 parent 8a28902 commit 5d4c3b1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
43 changes: 40 additions & 3 deletions src/adapters/netsuite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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')) {
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/pipedrive/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down
7 changes: 3 additions & 4 deletions src/adapters/testCRM/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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---
// ---------------------------------------
Expand Down

0 comments on commit 5d4c3b1

Please sign in to comment.