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
async function updateMessageLog({ user, contactInfo, existingMessageLog, message, authHeader }) {
// ---------------------------------------
// ---TODO.8: Implement message logging---
// ---------------------------------------
// const existingLogId = existingMessageLog.thirdPartyLogId;
// const getLogRes = await axios.get(
// `https://api.crm.com/activity/${existingLogId}`,
// {
// headers: { 'Authorization': authHeader }
// });
// const originalNote = getLogRes.data.body;
// const updateNote = orginalNote.replace();
// const patchBody = {
// data: {
// body: updateNote,
// }
// }
// const updateLogRes = await axios.patch(
// `https://api.crm.com/activity`,
// patchBody,
// {
// headers: { 'Authorization': authHeader }
// });
console.log(`update message log with... \n\n${JSON.stringify(message, null, 2)}`);
//---------------------------------------------------------------------------------------------------------------------------------------------
//---CHECK.8: For multiple messages or additional message during the day, open db.sqlite and CRM website to check if message logs are saved ---
//---------------------------------------------------------------------------------------------------------------------------------------------
}
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;
}
const postBody = {
owner_id: Number(user.id),
subject,
deal_id: dealId,
note,
done: true,
due_date: dateUtc,
due_time: timeUtc,
type: smsType ? smsType.key_string : 'call',
participants: [
{
person_id: Number(contactInfo.id),
primary: true
}
]
}
if (!dealId && leadId) {