Logging an SMS message or conversation
The developer framework is currently in BETA
This framework is in beta. Please submit a Github issue if you encounter any problems or have a question.
The Unified CRM extension allows users to log in their CRM all forms of communication with a customer, which includes SMS or text messages. This interface describes how to log an SMS conversation within the target CRM.
Endpoint
- HTTP method: POST
- HTTP endpoint:
<server base URL>/messageLog
Request parameters
Name | Description |
---|---|
jwtToken |
An encrypted string that includes the current user's ID and the associated CRM. |
Response
Name | Description |
---|---|
TODO |
TODO |
Sample code
async function addMessageLog({ user, contactInfo, authHeader, message, additionalSubmission, recordingLink, timezoneOffset, contactNumber }) {
// ---------------------------------------
// ---TODO.7: Implement message logging---
// ---------------------------------------
// const postBody = {
// data: {
// subject: `[SMS] ${message.direction} SMS - ${message.from.name ?? ''}(${message.from.phoneNumber}) to ${message.to[0].name ?? ''}(${message.to[0].phoneNumber})`,
// body: `${message.direction} SMS - ${message.direction == 'Inbound' ? `from ${message.from.name ?? ''}(${message.from.phoneNumber})` : `to ${message.to[0].name ?? ''}(${message.to[0].phoneNumber})`} \n${!!message.subject ? `[Message] ${message.subject}` : ''} ${!!recordingLink ? `\n[Recording link] ${recordingLink}` : ''}\n\n--- Created via RingCentral CRM Extension`,
// type: 'Message'
// }
// }
// const addLogRes = await axios.post(
// `https://api.crm.com/activity`,
// postBody,
// {
// headers: { 'Authorization': authHeader }
// });
console.log(`adding message log... \n\n${JSON.stringify(callLog, null, 2)}`);
mockMessageLog = {
id: 'testMessageLogId'
}
const addLogRes = {
data: {
id: mockMessageLog.id
}
}
//---------------------------------------------------------------------------------
//---CHECK.7: Open db.sqlite and CRM website to check if message logs are saved ---
//---------------------------------------------------------------------------------
return addLogRes.data.id;
}
async function addMessageLog({ user, contactInfo, authHeader, message, additionalSubmission, recordingLink, timezoneOffset, contactNumber }) {
const dealId = additionalSubmission ? additionalSubmission.deals : '';
const orgId = contactInfo.organization ? contactInfo.organization.id : '';
const timeUtc = moment(message.creationTime).utcOffset(0).format('HH:mm')
const dateUtc = moment(message.creationTime).utcOffset(0).format('YYYY-MM-DD');
const activityTypesResponse = await axios.get(`https://${user.hostname}/v1/activityTypes`, { headers: { 'Authorization': authHeader } });
const hasSMSType = activityTypesResponse.data.data.some(t => t.name === 'SMS' && t.active_flag);
const postBody = {
user_id: user.id,
subject: `${message.direction} SMS - ${message.from.name ?? ''}(${message.from.phoneNumber}) to ${contactInfo.name}(${message.to[0].phoneNumber})`,
person_id: contactInfo.id,
org_id: orgId,
deal_id: dealId,
note: `<p>[Time] ${moment(message.creationTime).utcOffset(timezoneOffset).format('YYYY-MM-DD hh:mm:ss A')}</p>${!!message.subject ? `<p>[Message] ${message.subject}</p>` : ''} ${!!recordingLink ? `\n<p>[Recording link] ${recordingLink}</p>` : ''}<p><span style="font-size:9px">[Created via] <em><a href="https://www.pipedrive.com/en/marketplace/app/ring-central-crm-extension/5d4736e322561f57">RingCentral CRM Extension</a></span></em></p>`,
done: true,
due_date: dateUtc,
due_time: timeUtc,
type: hasSMSType ? 'SMS' : 'Call'
}
const addLogRes = await axios.post(
`https://${user.hostname}/v1/activities`,
postBody,
{
headers: { 'Authorization': authHeader }
});
return addLogRes.data.data.id;
}