Skip to content

createMessageLog

Creates a CRM activity for SMS, MMS, voicemail, fax, or shared SMS content.

Signature

async function createMessageLog({
  user,
  contactInfo,
  correspondents,
  assigneeName,
  ownerName,
  sharedSMSLogContent,
  authHeader,
  message,
  additionalSubmission,
  recordingLink,
  faxDocLink,
  faxDownloadLink,
  imageLink,
  imageDownloadLink,
  imageContentType,
  videoLink,
  proxyConfig
}) {
  return {
    logId: 'crm-message-log-id',
    returnMessage: {
      message: 'Message logged.',
      messageType: 'success',
      ttl: 1000
    }
  };
}

The runtime calls this with different fields depending on message type.

Input

Field Description
user Connected CRM user.
contactInfo Selected contact. Shape: { id, phoneNumber, type, name }.
correspondents Extra matched contacts for group SMS.
assigneeName, ownerName Shared SMS assignment/owner context when available.
sharedSMSLogContent { subject, body } generated by core for shared SMS conversations. When this is present, message is not used.
authHeader Prepared CRM auth header.
message RingCentral message object for SMS, MMS, voicemail, or fax.
additionalSubmission Values from manifest page.messageLog.additionalFields[].
recordingLink Voicemail recording link.
faxDocLink, faxDownloadLink Fax document view/download links.
imageLink, imageDownloadLink, imageContentType MMS image links and content type.
videoLink MMS video link.
proxyConfig Proxy configuration when applicable.

Return

Field Required Description
logId Yes CRM log/activity ID. Core stores it for later message updates.
returnMessage Optional UI feedback.
extraDataTracking Optional Analytics/tracing data.

Grouping Behavior

Normal SMS/MMS/fax/voicemail logs are grouped by conversation/day. The first unlogged message calls createMessageLog; later messages in the same group call updateMessageLog.

Shared SMS uses conversationLogId. Core composes sharedSMSLogContent and either creates a new log or updates the existing one.

Reference

const axios = require('axios');

// message : same as in https://developers.ringcentral.com/api-reference/Message-Store/readMessage
async function createMessageLog({ user, contactInfo, authHeader, message, additionalSubmission, recordingLink, faxDocLink }) {
    const messageType = recordingLink ? 'Voicemail' : (faxDocLink ? 'Fax' : 'SMS');
    console.log(`adding message log... \n\n${JSON.stringify(message, null, 2)}`);
    const newMessageLog = {
        id:  `CRM message log id ${Date.now()}`
    }

    // Using mock JSON as CRM response
    const fs = require('fs');
    const path = require('path');
    const mockMessageLogsPath = path.join(__dirname, '..', 'mockMessageLogs.json');
    const mockMessageLogs = require(mockMessageLogsPath);
    mockMessageLogs.push(newMessageLog);
    fs.writeFileSync(mockMessageLogsPath, JSON.stringify(mockMessageLogs, null, 2));
    //-------------------------------------------------------------------------------------------------------------
    //--- CHECK: For single message logging, open db.sqlite and JSON file to check if message logs are saved ------
    //-------------------------------------------------------------------------------------------------------------

    //--------------------------------------
    //--- TODO: Add CRM API call here ------
    //--- TODO: Delete above mock JSON -----
    //--------------------------------------
    // 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 App Connect`,
    //         type: 'Message'
    //     }
    // }
    // const addLogRes = await axios.post(
    //     `https://api.crm.com/activity`,
    //     postBody,
    //     {
    //         headers: { 'Authorization': authHeader }
    //     });
    return {
        logId: newMessageLog.id,
        returnMessage: {
            message: 'Message logged',
            messageType: 'success',
            ttl: 1000
        }
    };
}

module.exports = createMessageLog;