Code review stories

How SalesCandy brought leads into the system, routed them, and made their history available to customers.

Jump to the 46-commit timeline

Five decisions that shaped the lead workflow

SalesCandy’s routing work began before these commits. Read in order, these five changes trace how the team refined the path from an incoming enquiry to a record that other systems and managers could use.

May 2021 · Put phone enquiries into the lead form model

CandyNumber wrapped the caller’s phone number in a data object and added a version slot to the form payload. The slot was set to null. The useful change was the shared shape: a phone enquiry could carry form data in the same structure expected downstream.

September 2021 · Give ingestion updates an order

CandyBase configured FIFO topics with content-based deduplication for lead-source updates and manual bulk-ingestion results. That gave these streams a way to preserve order within a message group and suppress duplicate publishes with identical bodies within the deduplication window. For integrations handling repeated updates, both properties matter.

January 2022 · Keep looking for a salesperson

CarouselMatcher had an optimisation that could skip other enquiries in a project after one had no eligible salesperson. Once leads could target different teams, the earlier result no longer applied to every lead in the project. The patch kept leads with a team assignment out of that bulk skip, so the matcher could still try their teams.

October 2022 · Give deletions a place in the event stream

CandySync moved timestamp assignment before the early return that builds schema-v3 delete notifications for leads and lead logs. A subscriber could now receive eventAt even on that path. Its value came from the modification time, creation time, or processing time, in that order.

February 2023 · Show what a salesperson did and when a status changed

The lead exporter added separate fields for the first and last sales actions and the first and last status updates. An imported lead might already have a status before anyone contacts it. Keeping the two histories separate helps a manager interpret response-time reports without treating a status change as a customer interaction.

Further development findings

Updated Lead Ingestion Workflow Documentation

The process now specifies using a dedicated Lambda function to enqueue leads.

This clarifies the initial step for submitting new leads to the system.

Firsthand source notes

Reza Rosli recalls letting developers choose project names to encourage a sense of ownership. The team drew on names connected with selling and making candy and used names that hinted at what the services did. The CandyMuncher README gives a concrete example by naming the service for taking in incoming leads.

Implementation of DynamoDB deletion logic for connection state

The code now uses AWS SDK to delete an item from DynamoDB based on a connection ID.

This change establishes a dedicated mechanism for removing connection records from the database.

Firsthand source notes

Reza Rosli recalls that the v3 rewrite moved SalesCandy from a Node.js monolith that relied heavily on SQL stored procedures to managed and serverless services. The v3 architecture separated salesperson presence from lead intake and routing.

Updated Elasticsearch Client Usage in Ingestion Script

Replaced the 'request' module with the official '@elastic/elasticsearch' client.

This change modernizes the connection method for bulk data operations.

Firsthand source notes

Reza Rosli recalls that ELK was SalesCandy’s main source for looking up and analysing lead-related data. The team indexed lead-source information alongside lead records so it could use both in Kibana. Reza recalls CandyBase as the operational store and tentatively recalls Aurora. The archived LeadSource table definition in CandyBase at 522b9f9 defines a DynamoDB table, and the SugarRush library at 8603148 prepares new lead-source records for a configured DynamoDB table. The cited indexer diff shows lead-source records being written to Elasticsearch.

Added standalone HTML view for strategy simulation

The file now includes structure for selecting algorithms and input parameters.

This allows users to test different lead distribution strategies interactively.

Firsthand source notes

Reza Rosli recalls that salespeople asked why a teammate kept receiving the next leads while they were still waiting. The SalesCandy team used the simulator to understand customer feedback about how fair that experience felt. Reza recalls wanting customers to choose a strategy and tune its parameters, with the simulator and visualizations available in Manager Portal to explain the effects. The archived standalone HTML view supports strategy selection and lets readers vary availability, rejection chance and weight. It shows results by salesperson. Reza recalls that the simulator later became one of the projects owned by the data science team, which included Azraf (an intern), Jonathan, and Muhammad Anwaar. Azraf authored the cited browser-view revision.

Added first action time to lead export data

The code now extracts and includes the first action time in the generated CSV.

This addition provides a specific timestamp for when a lead first interacted with the system.

Firsthand source notes

Reza Rosli recalls collaborating with SalesCandy data scientist Muhammad Anwaar on data extraction, customer-facing exports and reports, and modelling. Reza recalls SageMaker and Jupyter notebook work. The cited Anwaar revision adds first-action time to lead exports. The archive retains June 2020 screenshots in a folder labelled SageMaker, and searches have yet to locate the notebooks.

VPC Configuration Added for Elastic Cloud Connectivity

The serverless configuration now specifies required VPC security groups and subnets.

This change directly connects the deployed function to the necessary private network segments.

Firsthand source notes

Reza Rosli recalls that SalesCandy used Elastic Cloud. The smart-alert-es commit describes a VPC configuration change to connect to Elastic Cloud.

Refactored Data Processing for Status Reporting

The code now parses status data into structured objects containing duration and status.

This change supports creating a flat, reconstructible format for status timeline data.

Firsthand source notes

Reza Rosli recalls that SalesCandy v2 handled the salesperson app-status report in MySQL on Amazon RDS and that the team had a lot of load to manage. He recalls that DynamoDB and compacting the daily status data helped keep the reporting load down. The team accepted less accuracy in the status timeline while continuing to work on how the visualization handled edge cases. Reza recalls that the team also needed a flat notation that could be reconstructed independently of the frontend. The archived v3 patch shows the interval encoder storing durations and status codes and computing minute totals from those runs.

Exporting Salesperson Action Report Data

The export function now uses the CSV service to write the processed data.

This change correctly handles the report's data export to a shared CSV format.

Firsthand source notes

Reza Rosli recalls that the team spent substantial time defining and fixing the Salesperson Action report and its export. The Manager Portal patch by Mohd Thaqif Bin Abdullah Hasim connects the report’s download to the shared CSV writer and maps its flattened rows to translated column labels. The separate report service history records changes to definitions such as first-action time and auto-assigned leads.

Integration of SonarQube Analysis into CI Pipeline

Added a dedicated job to run the sonar-scanner tool.

This change formally incorporated static code analysis into the build process.

Firsthand source notes

Reza Rosli recalls that SalesCandy used SonarQube Community. The project-cpx-report change records the SonarQube integration, and Reza's account identifies the edition.

Matcher.js: Implement single-candidate auto-assignment logic

The code now auto-assigns a lead if only one salesperson is found for the project or team.

This change ensures immediate lead assignment when only one salesperson is available.

Firsthand source notes

Reza Rosli recalls that waiting for the sole salesperson to become available would delay lead assignment without changing who could receive the lead. His CarouselMatcher commit adds direct assignment when the designated roster contains exactly one salesperson.

Repository histories

Commit timeline

Timeline view
  1. Add connStatus column to the logs, so that we can track new / expired/ lost connections

  2. link to datasource to vwLatestUserDeviceData

  3. Put into VPC to be able to connect to Elastic Cloud

  4. Allow form creation when a project group references a deleted project

  5. Re-engineer CDYAI. remove old API Gateway. since its not being used from outside.

  6. Get the reports based on the user's timezone, not tenant timezone

  7. Apply security audit findings

  8. Fix wrong range for 5mins duration. only created lead when hash file change hour

  9. Enhance connection logic to Redis to manage disconnections

  10. Export lead data by tenant and country

  11. Upgrade the Serverless runtime and update API configuration

  12. Fix conflicted status result in group by query when a user is in multiple teams

  13. add version to standardise the lead structure

  14. Migrate from deprecated Presence-sendMessage to use Presence-newMsg endpoint

  15. migration from sequelize to serverless

  16. remove unused queries for user device data and added getTenantDetails query in mobile schema

  17. Implement sonarqube

  18. Changes to support migration to CandyBase serverless

  19. fixed database configuration for ssl

  20. Use yargs for command line flags

  21. Add Campaign Tracker for leads

  22. Add target cluster for CandyFloss for tracking

  23. Add Leadsource FIFO and Manual FIFO

  24. separate industryid from update whatsapptemplate

  25. Add a defensive input sanitiser

  26. Change to arm64 lambda (graviton)

  27. Add case for reset mapping leadsource

  28. Keep routing when one lead has no matching salesperson

  29. Update libphonenumber-js and change to Lambda Graviton arch

  30. Implement a workflow to refresh a lead source item's data if we detect the associated project data is different from what is in the search index

  31. Apply a security fix

  32. Handle non-aphanumeric tenant names

  33. Ensure lead data provided phone numbe as string, because it will cause a type error when hashed

  34. Update elasticsearch client

  35. Implemented tenant-scoped auth and various utility functions for integrations management

  36. Fix an issue with reports generation due to lambda throttles causing sqs messages to be lost

  37. Add support for importing leads with preset status and submission date

  38. Security: obfuscate sensitive data sent to front-end

  39. Refactored functions for LeadActionTemplates. With workaround for a front-end bug where validation does not ignore deleted fields

  40. Optimisations: Remove message history logging and don't attempt to send messages when we get a disconnected status

  41. Workaround for Facebook API not returning permissions data for New Pages Experience pages

  42. Implement funnel stage mapping

  43. Fix an premature loop break bug when having multiple candystream subscribers

  44. Replace the browser token polling interval with a recursive timeout

  45. Solve conversations stuck in limbo if the rekated lead(s) were deleted in CandyMuncher

  46. Added new columns for first action, first status update, last action, last status update.

20200308-sample-leads 1
  1. Export lead data by tenant and country

CandyBase 1
  1. Add Leadsource FIFO and Manual FIFO

CandyMailbox 1
  1. Add Campaign Tracker for leads

CandyMuncher 1
  1. Fix an premature loop break bug when having multiple candystream subscribers

CandyNumber 1
  1. add version to standardise the lead structure

CandyPixel 1
  1. Allow form creation when a project group references a deleted project

Carousel 1
  1. Enhance connection logic to Redis to manage disconnections

CarouselMatcher 1
  1. Keep routing when one lead has no matching salesperson

Facebook 1
  1. Workaround for Facebook API not returning permissions data for New Pages Experience pages

Presence 1
  1. Optimisations: Remove message history logging and don't attempt to send messages when we get a disconnected status

PresenceLogger 1
  1. Add connStatus column to the logs, so that we can track new / expired/ lost connections

admin-portal 1
  1. separate industryid from update whatsapptemplate

app-status-reports 1
  1. Get the reports based on the user's timezone, not tenant timezone

auditlogger 1
  1. Add case for reset mapping leadsource

bouncer 1
  1. Fix wrong range for 5mins duration. only created lead when hash file change hour

candylake 1
  1. Add target cluster for CandyFloss for tracking

candymuncher-reindexer 1
  1. Use yargs for command line flags

candysync-webhook 1
  1. Security: obfuscate sensitive data sent to front-end

carousel-analytics 1
  1. Apply security audit findings

cdy.ai 1
  1. Re-engineer CDYAI. remove old API Gateway. since its not being used from outside.

clone-army 1
  1. Upgrade the Serverless runtime and update API configuration

crm-api 1
  1. Apply a security fix

customer-api 1
  1. Refactored functions for LeadActionTemplates. With workaround for a front-end bug where validation does not ignore deleted fields

customer-api-appsync 1
  1. remove unused queries for user device data and added getTenantDetails query in mobile schema

customer-api-bak_20220921 1
  1. migration from sequelize to serverless

dimsum-logger 1
  1. Update elasticsearch client

export-all 1
  1. Handle non-aphanumeric tenant names

fb-conversions-webhook 1
  1. Implement funnel stage mapping

lead-exporter 1
  1. Added new columns for first action, first status update, last action, last status update.

lead-performance-report 1
  1. Change to arm64 lambda (graviton)

manager-portal 1
  1. Replace the browser token polling interval with a recursive timeout

mhub-crm-adapter 1
  1. Implemented tenant-scoped auth and various utility functions for integrations management

phone-number-validator 1
  1. Update libphonenumber-js and change to Lambda Graviton arch

project-cpx-report 1
  1. Implement sonarqube

salesperson-action-report 1
  1. Fix conflicted status result in group by query when a user is in multiple teams

salesperson-ranking 1
  1. Changes to support migration to CandyBase serverless

sc-auth 1
  1. Add a defensive input sanitiser

sc-files 1
  1. fixed database configuration for ssl

sc-forms 1
  1. Add support for importing leads with preset status and submission date

sc-rollups 1
  1. Fix an issue with reports generation due to lambda throttles causing sqs messages to be lost

sc-twilio 1
  1. Solve conversations stuck in limbo if the rekated lead(s) were deleted in CandyMuncher

smart-alert-es 1
  1. Put into VPC to be able to connect to Elastic Cloud

sugarrush-es-indexer 1
  1. Implement a workflow to refresh a lead source item's data if we detect the associated project data is different from what is in the search index

sugarrush-main-library-layer 1
  1. Ensure lead data provided phone numbe as string, because it will cause a type error when hashed

user-analytics 1
  1. link to datasource to vwLatestUserDeviceData

usernotifications 1
  1. Migrate from deprecated Presence-sendMessage to use Presence-newMsg endpoint