Skip to content

Working with call log records

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.

One of the most used features across all of RingCentral's CRM integrations is the function of logging a phone call and recording a disposition associated with that phone call in the target CRM. To facilitate various user flows that relate to the logging of calls, developers need to implement three different interfaces in their server implementation.

  • Load a call log associated with a phone call
  • Create a call log record
  • Update a call log record

Below you will find more information about each of these interfaces.

Logging new phone calls

Endpoint

  • HTTP method: POST
  • HTTP endpoint: <server base URL>/callLog

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 addCallLog({ user, contactInfo, authHeader, callLog, note, additionalSubmission, timezoneOffset, contactNumber }) {
    // ------------------------------------
    // ---TODO.4: Implement call logging---
    // ------------------------------------

    // const postBody = {
    //     subject: callLog.customSubject ?? `[Call] ${callLog.direction} Call ${callLog.direction === 'Outbound' ? 'to' : 'from'} ${contactInfo.name} [${contactInfo.phone}]`,
    //     body: `\nContact Number: ${contactNumber}\nCall Result: ${callLog.result}\nNote: ${note}${callLog.recording ? `\n[Call recording link] ${callLog.recording.link}` : ''}\n\n--- Created via RingCentral CRM Extension`,
    //     type: 'PhoneCommunication',
    //     received_at: moment(callLog.startTime).toISOString()
    // }
    // const addLogRes = await axios.post(
    //     `https://api.crm.com/activity`,
    //     postBody,
    //     {
    //         headers: { 'Authorization': authHeader }
    //     });
    console.log(`adding call log... \n${JSON.stringify(callLog, null, 2)}`);
    console.log(`with note... \n${note}`);
    console.log(`with additional info... \n${JSON.stringify(additionalSubmission, null, 2)}`);
    mockCallLog = {
        id: 'testCallLogId',
        subject: callLog.customSubject,
        note,
        contactName: contactInfo.name
    }
    const addLogRes = {
        data: {
            id: mockCallLog.id
        }
    }
    //----------------------------------------------------------------------------
    //---CHECK.4: Open db.sqlite and CRM website to check if call log is saved ---
    //----------------------------------------------------------------------------
    return addLogRes.data.id;
}
async function getCallLog({ user, callLogId, authHeader }) {
    const getLogRes = await axios.get(
        `https://${user.hostname}/v1/activities/${callLogId}`,
        {
            headers: { 'Authorization': authHeader }
        });
    const logBody = getLogRes.data.data.note;
    const note = logBody.split('<p>[Note] ')[1].split('</p>')[0];
    const relatedContact = getLogRes.data.related_objects?.person;
    let contactName = 'Unknown';
    if (!!relatedContact) {
        const contactKeys = Object.keys(relatedContact);
        contactName = relatedContact[contactKeys[0]].name;
    }
    return {
        subject: getLogRes.data.data.subject,
        note,
        contactName
    }
}

Loading a log for a phone call

TODO

Endpoint

  • HTTP method: GET
  • HTTP endpoint: <server base URL>/callLog

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 createContact({ user, authHeader, phoneNumber, newContactName, newContactType }) {
    // ----------------------------------------
    // ---TODO.8: Implement contact creation---
    // ----------------------------------------

    const postBody = {
        name: newContactName,
        type: newContactType,
        phone_numbers: [
            {
                name: "Work",
                number: phoneNumber,
                default_number: true
            }
        ]
    }
    // const contactInfoRes = await axios.post(
    //     `https://api.crm.com/contacts`,
    //     postBody,
    //     {
    //         headers: { 'Authorization': authHeader }
    //     }
    // );
    mockContact = {
        id: 'testContactId',
        name: newContactName,
        type: newContactType,
        phone: phoneNumber,
        additionalInfo: {
            associatedDeal: [
                {
                    const: 'csA351',
                    title: 'Christmas special A351'
                },
                {
                    const: 'eA22',
                    title: 'Easter A22'
                },
                {
                    const: 'aC92',
                    title: 'Anniversary C92'
                }
            ]
        }
    }

    const contactInfoRes = {
        data: {
            id: mockContact.id,
            name: mockContact.name
        }
    }

    //--------------------------------------------------------------------------------
    //---CHECK.8: In extension, try create a new contact against an unknown number ---
    //--------------------------------------------------------------------------------
    return {
        id: contactInfoRes.id,
        name: contactInfoRes.name
    }
}
async function createContact({ user, authHeader, phoneNumber, newContactName }) {
    const postBody = {
        name: newContactName,
        phone: phoneNumber
    }
    const createContactRes = await axios.post(
        `https://${user.hostname}/v1/persons`,
        postBody,
        {
            headers: { 'Authorization': authHeader }
        });
    return {
        id: createContactRes.data.data.id,
        name: createContactRes.data.data.name
    }
}

Updating the log for a phone call

TODO

Endpoint

  • HTTP method: PATCH
  • HTTP endpoint: <server base URL>/callLog

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 updateCallLog({ user, existingCallLog, authHeader, recordingLink, subject, note }) {
    // ---------------------------------------
    // ---TODO.6: Implement call log update---
    // ---------------------------------------

    // const existingLogId = existingCallLog.thirdPartyLogId;
    // const getLogRes = await axios.get(
    //     `https://api.crm.com/activity/${existingLogId}`,
    //     {
    //         headers: { 'Authorization': authHeader }
    //     });
    // const originalNote = getLogRes.data.body;
    // let patchBody = {};

    // patchBody = {
    //     data: {
    //         subject: subject,
    //         body: note
    //     }
    // }
    // const patchLogRes = await axios.patch(
    //     `https://api.crm.com/activity/${existingLogId}`,
    //     patchBody,
    //     {
    //         headers: { 'Authorization': authHeader }
    //     });
    mockCallLog.subject = subject;
    mockCallLog.note = note;
    const patchLogRes = {
        data: {
            id: mockCallLog.id
        }
    }
    //-----------------------------------------------------------------------------------------
    //---CHECK.6: In extension, for a logged call, click edit to see if info can be updated ---
    //-----------------------------------------------------------------------------------------
    return patchLogRes.data.id;
}
async function updateCallLog({ user, existingCallLog, authHeader, recordingLink, subject, note }) {
    const existingPipedriveLogId = existingCallLog.thirdPartyLogId;
    const getLogRes = await axios.get(
        `https://${user.hostname}/v1/activities/${existingPipedriveLogId}`,
        {
            headers: { 'Authorization': authHeader }
        });
    let putBody = {};
    let logBody = getLogRes.data.data.note;
    // case: update recording
    if (!!recordingLink) {
        if (logBody.includes('<p><span>[Created via]')) {
            logBody = logBody.replace('<p><span>[Created via]', `<p>[Call recording link] <a target="_blank" href=${recordingLink}>open</a></p><p><span>[Created via]`);
        }
        else {
            logBody += `<p>[Call recording link] <a target="_blank" href=${recordingLink}>open</a></p>`;
        }
        putBody = {
            note: logBody
        }
    }
    // case: normal update
    else {
        const originalNote = logBody.split('</p><p>[Note] ')[1].split('</p>')[0];
        logBody = logBody.replace(`</p><p>[Note] ${originalNote}</p>`, `</p><p>[Note] ${note}</p>`);
        putBody = {
            note: logBody,
            subject: subject ?? existingCallLog.subject,
        }
    }
    const putLogRes = await axios.put(
        `https://${user.hostname}/v1/activities/${existingPipedriveLogId}`,
        putBody,
        {
            headers: { 'Authorization': authHeader }
        });
}