updateMessageLog
This function is to add following messages on the same day to the same contact. Use case is explained here
Params
Input
:
- user
: user entity
- contactInfo
: has id
, phoneNumber
, type
, name
- existingMessageLog
: existing message log entity
- authHeader
: auth header for CRM API call
- message
: message text
Reference
//-------------------------------------------------------------------------------------
//---CHECK.5: In extension, for a logged call, click edit to see if info is fetched ---
//-------------------------------------------------------------------------------------
return {
callLogInfo: {
subject,
note
},
returnMessage: {
message: 'Call log fetched.',
messageType: 'success',
ttl: 3000
}
}
}
// - note: note submitted by user
// - subject: subject submitted by user
// - startTime: more accurate startTime will be patched to this update function shortly after the call ends
// - duration: more accurate duration will be patched to this update function shortly after the call ends
// - result: final result will be patched to this update function shortly after the call ends
// - 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, startTime, duration, result, aiNote, transcript }) {
// ---------------------------------------
// ---TODO.6: Implement call log update---
// ---------------------------------------
let body = mockCallLog.note;
if (!!note && (user.userSettings?.addCallLogNote?.value ?? true)) { logBody = upsertCallAgentNote({ body: logBody, note }); }
if (!!duration && (user.userSettings?.addCallLogDuration?.value ?? true)) { logBody = upsertCallDuration({ body: logBody, duration }); }
if (!!result && (user.userSettings?.addCallLogResult?.value ?? true)) { logBody = upsertCallResult({ body: logBody, result }); }
const hasSMSType = activityTypesResponse.data.data.some(t => t.name === 'SMS' && t.active_flag);
const messageType = !!recordingLink ? 'Voicemail' : (!!faxDocLink ? 'Fax' : 'SMS');
let subject = '';
let note = '';
switch (messageType) {
case 'SMS':
subject = `SMS conversation with ${contactInfo.name} - ${moment(message.creationTime).utcOffset(user.timezoneOffset).format('YY/MM/DD')}`;
note =
`<br><b>${subject}</b><br>` +
'<b>Conversation summary</b><br>' +
`${moment(message.creationTime).utcOffset(user.timezoneOffset).format('dddd, MMMM DD, YYYY')}<br>` +
'Participants<br>' +
`<ul><li><b>${userName}</b><br></li>` +
`<li><b>${contactInfo.name}</b></li></ul><br>` +
'Conversation(1 messages)<br>' +
'BEGIN<br>' +
'------------<br>' +
'<ul>' +
`<li>${message.direction === 'Inbound' ? `${contactInfo.name} (${contactInfo.phoneNumber})` : userName} ${moment(message.creationTime).utcOffset(user.timezoneOffset).format('hh:mm A')}<br>` +
`<b>${message.subject}</b></li>` +
'</ul>' +
'------------<br>' +
'END<br><br>' +
'--- Created via RingCentral App Connect';
break;
case 'Voicemail':
subject = `Voicemail left by ${contactInfo.name} - ${moment(message.creationTime).utcOffset(user.timezoneOffset).format('YY/MM/DD')}`;
note = `<br><b>${subject}</b><br>Voicemail recording link: ${recordingLink} <br><br>--- Created via RingCentral App Connect`;
break;
case 'Fax':
subject = `Fax document sent from ${contactInfo.name} - ${moment(message.creationTime).utcOffset(user.timezoneOffset).format('YY/MM/DD')}`;
note = `<br><b>${subject}</b><br>Fax document link: ${faxDocLink} <br><br>--- Created via RingCentral App Connect`;
break;