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
name: contactInfoRes.name
},
returnMessage: {
message: `Contact created.`,
messageType: 'success',
ttl: 2000
}
}
}
exports.getAuthType = getAuthType;
exports.getUserInfo = getUserInfo;
exports.createCallLog = createCallLog;
exports.updateCallLog = updateCallLog;
exports.getCallLog = getCallLog;
exports.createMessageLog = createMessageLog;
exports.updateMessageLog = updateMessageLog;
exports.findContact = findContact;
exports.createContact = createContact;
exports.unAuthorize = unAuthorize;
}
});
const userName = userInfoResponse.data.data.name;
const getLogRes = await axios.get(
`https://${user.hostname}/api/v2/activities/${existingLogId}`,
{
headers: { 'Authorization': authHeader }
});
let logBody = getLogRes.data.data.note;
let patchBody = {};
const newMessageLog =
`<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>`;
// Add new message at the end (before the closing </ul> tag inside BEGIN/END block)
logBody = logBody.replace('</ul>------------<br>', `${newMessageLog}</ul>------------<br>`);
const regex = RegExp('<br>Conversation.(.*) messages.');
const matchResult = regex.exec(logBody);
logBody = logBody.replace(matchResult[0], `<br>Conversation(${parseInt(matchResult[1]) + 1} messages)`);
patchBody = {
note: logBody,
deal_id: dealId
}
if (!dealId && leadId) {
patchBody.lead_id = leadId;
}
const patchLogRes = await axios.patch(
`https://${user.hostname}/api/v2/activities/${existingLogId}`,
patchBody,
{
headers: { 'Authorization': authHeader }
});
extraDataTracking = {
ratelimitRemaining: patchLogRes.headers['x-ratelimit-remaining'],
ratelimitAmount: patchLogRes.headers['x-ratelimit-limit'],
ratelimitReset: patchLogRes.headers['x-ratelimit-reset']
};
return {
extraDataTracking
}
}
async function getCallLog({ user, callLogId, authHeader }) {
let extraDataTracking = {};
const getLogRes = await axios.get(
`https://${user.hostname}/api/v2/activities/${callLogId}`,
{